Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using FileFS.Client.Exceptions;
using FileFS.Client.Transactions.Abstractions;
using FileFS.Client.Transactions;
using FileFS.DataAccess;
using FileFS.DataAccess.Constants;
using FileFS.DataAccess.Entities;
Expand All @@ -24,7 +24,6 @@ public class FileFsClientDirectoryTests
private readonly Mock<IEntryRepository> _entryRepositoryMock;
private readonly Mock<IFileRepository> _fileRepositoryMock;
private readonly Mock<IDirectoryRepository> _directoryRepositoryMock;
private readonly Mock<ITransactionWrapper> _transactionWrapperMock;
private readonly FileFsClient _client;

public FileFsClientDirectoryTests()
Expand All @@ -37,17 +36,13 @@ public FileFsClientDirectoryTests()
.Setup(r => r.Exists(PathConstants.RootDirectoryName))
.Returns(true);

_transactionWrapperMock = new Mock<ITransactionWrapper>();
_transactionWrapperMock.Setup(t => t.BeginTransaction());
_transactionWrapperMock.Setup(t => t.EndTransaction());

_client = new FileFsClient(
_fileRepositoryMock.Object,
_directoryRepositoryMock.Object,
_entryRepositoryMock.Object,
null,
null,
_transactionWrapperMock.Object,
new NullTransactionWrapper(),
new StorageOperationLocker());
}

Expand Down Expand Up @@ -578,4 +573,4 @@ public void IsDirectory_WhenDirectoryNotExists_ShouldReturnFalse(string name)
Assert.False(directoryExists);
}
}
}
}
11 changes: 3 additions & 8 deletions FileFS.Client.Tests/FileFsClientTests/FileFsClientFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Text;
using FileFS.Client.Abstractions;
using FileFS.Client.Exceptions;
using FileFS.Client.Transactions.Abstractions;
using FileFS.Client.Transactions;
using FileFS.DataAccess;
using FileFS.DataAccess.Allocation.Abstractions;
using FileFS.DataAccess.Constants;
Expand Down Expand Up @@ -30,7 +30,6 @@ public class FileFsClientFileTests
private readonly Mock<IStorageOptimizer> _storageOptimizerMock;
private readonly Mock<IEntryRepository> _entryRepositoryMock;
private readonly Mock<IDirectoryRepository> _directoryRepositoryMock;
private readonly Mock<ITransactionWrapper> _transactionWrapperMock;
private readonly FileFsClient _client;

public FileFsClientFileTests()
Expand All @@ -45,17 +44,13 @@ public FileFsClientFileTests()
.Setup(r => r.Exists(PathConstants.RootDirectoryName))
.Returns(true);

_transactionWrapperMock = new Mock<ITransactionWrapper>();
_transactionWrapperMock.Setup(t => t.BeginTransaction());
_transactionWrapperMock.Setup(t => t.EndTransaction());

_client = new FileFsClient(
_fileRepositoryMock.Object,
_directoryRepositoryMock.Object,
_entryRepositoryMock.Object,
_externalFileManagerMock.Object,
_storageOptimizerMock.Object,
_transactionWrapperMock.Object,
new NullTransactionWrapper(),
new StorageOperationLocker());
}

Expand Down Expand Up @@ -1117,4 +1112,4 @@ public void FileExists_WithInvalidFileName_ShouldThrowException(string fileName)
Assert.Throws<InvalidNameException>(Act);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Text;
using FileFS.Client.Exceptions;
using FileFS.Client.Transactions.Abstractions;
using FileFS.Client.Transactions;
using FileFS.DataAccess;
using FileFS.DataAccess.Constants;
using FileFS.DataAccess.Entities;
Expand All @@ -26,7 +26,6 @@ public class FileFsClientGenericTests
private readonly Mock<IEntryRepository> _entryRepositoryMock;
private readonly Mock<IFileRepository> _fileRepositoryMock;
private readonly Mock<IDirectoryRepository> _directoryRepositoryMock;
private readonly Mock<ITransactionWrapper> _transactionWrapperMock;
private readonly FileFsClient _client;

public FileFsClientGenericTests()
Expand All @@ -39,17 +38,13 @@ public FileFsClientGenericTests()
.Setup(r => r.Exists(PathConstants.RootDirectoryName))
.Returns(true);

_transactionWrapperMock = new Mock<ITransactionWrapper>();
_transactionWrapperMock.Setup(t => t.BeginTransaction());
_transactionWrapperMock.Setup(t => t.EndTransaction());

_client = new FileFsClient(
_fileRepositoryMock.Object,
_directoryRepositoryMock.Object,
_entryRepositoryMock.Object,
null,
null,
_transactionWrapperMock.Object,
new NullTransactionWrapper(),
new StorageOperationLocker());
}

Expand Down Expand Up @@ -403,4 +398,4 @@ public void GetEntriesInfo_WhenThereAreNoFiles_ShouldReturnEmptyCollection()
Assert.Empty(files);
}
}
}
}
46 changes: 46 additions & 0 deletions FileFS.Client.Tests/Transactions/TransactionWrapperTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Threading.Tasks;
using FileFS.Client.Transactions;
using Serilog;
using Xunit;

// Missing XML comment for publicly visible type or member...
#pragma warning disable 1591

// Elements should be documented
#pragma warning disable SA1600

namespace FileFS.Client.Tests.Transactions
{
public class TransactionWrapperTests
{
[Theory]
[InlineData(false)]
[InlineData(true)]
public void Execute_WhenOperationThrows_ShouldReleaseMutex(bool useGenericOverload)
{
// Arrange
var logger = new LoggerConfiguration().CreateLogger();
using var transactionWrapper = new TransactionWrapper($"{Guid.NewGuid()}.filefs", logger);
var expectedException = new InvalidOperationException();

// Act
void Act()
{
if (useGenericOverload)
{
transactionWrapper.Execute<object>(() => throw expectedException);
}
else
{
transactionWrapper.Execute(() => throw expectedException);
}
}

// Assert
Assert.Same(expectedException, Assert.Throws<InvalidOperationException>(Act));
var task = Task.Run(() => transactionWrapper.Execute(() => { }));
Assert.True(task.Wait(TimeSpan.FromSeconds(5)));
}
}
}
Loading