Skip to content
Merged
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
61 changes: 33 additions & 28 deletions Testing/CASLTests/NativeInterop/NativeDependencyManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace CASLTests.NativeInterop;
using Moq;
using Xunit;
using Assert = Helpers.AssertExtensions;
using FluentAssertions;
#pragma warning restore IDE0001 // Name can be simplified

/// <summary>
Expand All @@ -41,40 +42,43 @@ public NativeDependencyManagerTests()
[Fact]
public void Ctor_WhenInvokedWithNullFile_ThrowsException()
{
// Act & Assert
Assert.ThrowsWithMessage<ArgumentNullException>(() =>
{
_ = new OpenALDependencyManager(
// Act
var act = () => new OpenALDependencyManager(
null,
this.mockPath.Object,
this.mockPathResolver.Object);
}, "The parameter must not be null. (Parameter 'file')");

// Assert
act.Should().Throw<ArgumentNullException>()
.WithMessage("The parameter must not be null. (Parameter 'file')");
}

[Fact]
public void Ctor_WhenInvokedWithNullPath_ThrowsException()
{
// Act & Assert
Assert.ThrowsWithMessage<ArgumentNullException>(() =>
{
_ = new OpenALDependencyManager(
// Act
var act = () => new OpenALDependencyManager(
this.mockFile.Object,
null,
this.mockPathResolver.Object);
}, "The parameter must not be null. (Parameter 'path')");

// Assert
act.Should().Throw<ArgumentNullException>()
.WithMessage("The parameter must not be null. (Parameter 'path')");
}

[Fact]
public void Ctor_WhenInvokedWithNullPathResolver_ThrowsException()
{
// Act & Assert
Assert.ThrowsWithMessage<ArgumentNullException>(() =>
{
_ = new OpenALDependencyManager(
// Act
var act = () => new OpenALDependencyManager(
this.mockFile.Object,
this.mockPath.Object,
null);
}, "The parameter must not be null. (Parameter 'nativeLibPathResolver')");

// Assert
act.Should().Throw<ArgumentNullException>()
.WithMessage("The parameter must not be null. (Parameter 'nativeLibPathResolver')");
}
#endregion

Expand All @@ -98,8 +102,8 @@ public void NativeLibraries_WhenSettingValue_ReturnsCorrectResult()
var actual = manager.NativeLibraries;

// Assert
Xunit.Assert.Single(actual);
Xunit.Assert.Equal("test-native-lib", actual[0]);
actual.Should().HaveCount(1);
actual.First().Should().Be(libNameWithoutExtension);
}

[Theory]
Expand All @@ -122,7 +126,7 @@ public void NativeLibDirPath_WhenGettingValue_ReturnsCorrectResult(string dirPat
var actual = sut.NativeLibDirPath;

// Assert
Xunit.Assert.Equal(expected, actual);
actual.Should().Be(expected);
}
#endregion

Expand All @@ -143,11 +147,12 @@ public void VerifyDependencies_WhenLibrarySrcDoesNotExist_ThrowsException()
var manager = CreateManager();
manager.NativeLibraries = new ReadOnlyCollection<string>(new[] { "lib.dll" }.ToList());

// Act & Assert
Assert.ThrowsWithMessage<FileNotFoundException>(() =>
{
manager.VerifyDependencies();
}, $"The native dependency library '{srcDirPath}/lib.dll' does not exist.");
// Act
var act = manager.VerifyDependencies;

// Assert
act.Should().Throw<FileNotFoundException>()
.WithMessage($"The native dependency library '{srcDirPath}/lib.dll' does not exist.");
}

[Fact]
Expand All @@ -166,11 +171,11 @@ public void VerifyDependencies_WhenNativeLibExists_DoesNotThrowException()
var manager = CreateManager();
manager.NativeLibraries = new ReadOnlyCollection<string>(new[] { "lib.dll" }.ToList());

// Act & Assert
Assert.DoesNotThrow<FileNotFoundException>(() =>
{
manager.VerifyDependencies();
});
// Act
var act = manager.VerifyDependencies;

// Assert
act.Should().NotThrow<FileNotFoundException>();
}
#endregion

Expand Down
7 changes: 4 additions & 3 deletions Testing/CASLTests/NativeInterop/NativeLibPathResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace CASLTests.NativeInterop;
using CASL.NativeInterop;
using Moq;
using Xunit;
using FluentAssertions;

/// <summary>
/// Tests the <see cref="NativeLibPathResolver"/> class.
Expand Down Expand Up @@ -67,7 +68,7 @@ public void GetPath_WhenWindows_ReturnsCorrectPath(
var actual = resolver.GetFilePath(libName);

// Assert
Assert.Equal(expected, actual);
actual.Should().Be(expected);
}

[Theory]
Expand Down Expand Up @@ -100,7 +101,7 @@ public void GetPath_WhenMacOSX_ReturnsCorrectPath(
var actual = resolver.GetFilePath(libName);

// Assert
Assert.Equal(expected, actual);
actual.Should().Be(expected);
}

[Theory]
Expand Down Expand Up @@ -132,7 +133,7 @@ public void GetPath_WhenLinuxOS_ReturnsCorrectPath(
var actual = resolver.GetFilePath(libName);

// Assert
Assert.Equal(expected, actual);
actual.Should().Be(expected);
}
#endregion

Expand Down
105 changes: 57 additions & 48 deletions Testing/CASLTests/NativeInterop/NativeLibraryLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace CASLTests.NativeInterop;
using System.IO.Abstractions;
using CASL.Exceptions;
using CASL.NativeInterop;
using FluentAssertions;
using Moq;
using Xunit;
using Assert = Helpers.AssertExtensions;
#pragma warning restore IDE0001 // Name can be simplified

/// <summary>
Expand Down Expand Up @@ -57,97 +57,103 @@ public NativeLibraryLoaderTests()
[Fact]
public void Ctor_WithNullDependencyManager_ThrowsException()
{
//Act & Assert
Assert.ThrowsWithMessage<ArgumentNullException>(() =>
{
_ = new NativeLibraryLoader(
// Act
var act = () => new NativeLibraryLoader(
null,
this.mockPlatform.Object,
this.mockDirectory.Object,
this.mockFile.Object,
this.mockPath.Object,
this.mockLibrary.Object);
}, "The parameter must not be null. (Parameter 'dependencyManager')");

// Assert
act.Should().Throw<ArgumentNullException>()
.WithMessage("The parameter must not be null. (Parameter 'dependencyManager')");
}

[Fact]
public void Ctor_WithNullPlatform_ThrowsException()
{
//Act & Assert
Assert.ThrowsWithMessage<ArgumentNullException>(() =>
{
_ = new NativeLibraryLoader(
// Act
var act = () => new NativeLibraryLoader(
this.mockDependencyManager.Object,
null,
this.mockDirectory.Object,
this.mockFile.Object,
this.mockPath.Object,
this.mockLibrary.Object);
}, "The parameter must not be null. (Parameter 'platform')");

// Assert
act.Should().Throw<ArgumentNullException>()
.WithMessage("The parameter must not be null. (Parameter 'platform')");
}

[Fact]
public void Ctor_WithNullDirectoryObject_ThrowsException()
{
//Act & Assert
Assert.ThrowsWithMessage<ArgumentNullException>(() =>
{
_ = new NativeLibraryLoader(
// Act
var act = () => new NativeLibraryLoader(
this.mockDependencyManager.Object,
this.mockPlatform.Object,
null,
this.mockFile.Object,
this.mockPath.Object,
this.mockLibrary.Object);
}, "The parameter must not be null. (Parameter 'directory')");

// Assert
act.Should().Throw<ArgumentNullException>()
.WithMessage("The parameter must not be null. (Parameter 'directory')");
}

[Fact]
public void Ctor_WithNullFileObject_ThrowsException()
{
//Act & Assert
Assert.ThrowsWithMessage<ArgumentNullException>(() =>
{
_ = new NativeLibraryLoader(
// Act
var act = () => new NativeLibraryLoader(
this.mockDependencyManager.Object,
this.mockPlatform.Object,
this.mockDirectory.Object,
null,
this.mockPath.Object,
this.mockLibrary.Object);
}, "The parameter must not be null. (Parameter 'file')");

// Assert
act.Should().Throw<ArgumentNullException>()
.WithMessage("The parameter must not be null. (Parameter 'file')");
}

[Fact]
public void Ctor_WithNullPath_ThrowsException()
{
//Act & Assert
Assert.ThrowsWithMessage<ArgumentNullException>(() =>
{
_ = new NativeLibraryLoader(
// Act
var act = () => new NativeLibraryLoader(
this.mockDependencyManager.Object,
this.mockPlatform.Object,
this.mockDirectory.Object,
this.mockFile.Object,
null,
this.mockLibrary.Object);
}, "The parameter must not be null. (Parameter 'path')");

// Assert
act.Should().Throw<ArgumentNullException>()
.WithMessage("The parameter must not be null. (Parameter 'path')");
}

[Fact]
public void Ctor_WithNullLibrary_ThrowsException()
{
//Act & Assert
Assert.ThrowsWithMessage<ArgumentNullException>(() =>
{
_ = new NativeLibraryLoader(
// Act
var act = () => new NativeLibraryLoader(
this.mockDependencyManager.Object,
this.mockPlatform.Object,
this.mockDirectory.Object,
this.mockFile.Object,
this.mockPath.Object,
null);
}, "The parameter must not be null. (Parameter 'library')");

// Assert
act.Should().Throw<ArgumentNullException>()
.WithMessage("The parameter must not be null. (Parameter 'library')");
}

[Fact]
Expand All @@ -157,11 +163,12 @@ public void Ctor_WhenLibraryDoesNotExist_ThrowsException()
MockPlatformAsWindows();
this.mockLibrary.SetupGet(p => p.LibraryName).Returns(string.Empty);

// Act & Assert
Assert.ThrowsWithMessage<ArgumentNullException>(() =>
{
_ = CreateLoader();
}, "The parameter must not be null or empty. (Parameter 'libraryName')");
// Act
var act = CreateLoader;

// Assert
act.Should().Throw<ArgumentNullException>()
.WithMessage("The parameter must not be null or empty. (Parameter 'libraryName')");
}

[Theory]
Expand All @@ -181,7 +188,7 @@ public void Ctor_WhenUsingLibraryNameWithIncorrectLibraryExtension_FixesExtensio
var loader = CreateLoader();

//Assert
Xunit.Assert.Equal(WinLibNameWithExt, loader.LibraryName);
loader.LibraryName.Should().Be(WinLibNameWithExt);
}
#endregion

Expand Down Expand Up @@ -214,11 +221,12 @@ public void LoadLibrary_WhenLibraryDoesNotLoad_ThrowsException(

var loader = CreateLoader();

//Act & Assert
Assert.ThrowsWithMessage<LoadLibraryException>(() =>
{
loader.LoadLibrary();
}, $"{systemError}\n\nLibrary Path: '{expectedPath}'");
// Act
var act = loader.LoadLibrary;

// Assert
act.Should().Throw<LoadLibraryException>()
.WithMessage($"{systemError}\n\nLibrary Path: '{expectedPath}'");
}

[Fact]
Expand All @@ -244,7 +252,7 @@ public void LoadLibrary_WhenInvoked_ReturnsLibraryPointer()
var actual = loader.LoadLibrary();

// Assert
Xunit.Assert.Equal(expected, actual);
actual.Should().Be(expected);
}

[Fact]
Expand All @@ -265,11 +273,12 @@ public void LoadLibrary_WhenLibraryFileDoesNotExist_ThrowsException()

var loader = CreateLoader();

// Act & Assert
Assert.ThrowsWithMessage<FileNotFoundException>(() =>
{
_ = loader.LoadLibrary();
}, $"Could not find the library '{WinLibNameWithExt}' in directory path '{CrossPlatWinDirPath}'");
// Act
var act = loader.LoadLibrary;

// Assert
act.Should().Throw<FileNotFoundException>()
.WithMessage($"Could not find the library '{WinLibNameWithExt}' in directory path '{CrossPlatWinDirPath}'");
}
#endregion

Expand Down
Loading