Skip to content

Commit

Permalink
ApplicationGetAboutInformationTests
Browse files Browse the repository at this point in the history
  • Loading branch information
PABERTHIER committed Jan 4, 2025
1 parent 19c75e6 commit c1aba26
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using PhotoManager.UI;
using System.Reflection;
using System.Reflection.Emit;

namespace PhotoManager.Tests.Integration.Application;

[TestFixture]
public class ApplicationGetAboutInformationTests
{

private string? _dataDirectory;
private string? _databaseDirectory;
private string? _databasePath;
private const string DATABASE_END_PATH = "v1.0";

private PhotoManager.Application.Application? _application;

[OneTimeSetUp]
public void OneTimeSetUp()
{
_dataDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestFiles");
_databaseDirectory = Path.Combine(_dataDirectory, "DatabaseTests");
_databasePath = Path.Combine(_databaseDirectory, DATABASE_END_PATH);
}

private void ConfigureApplication(string assetsDirectory, string projectName, string projectOwner)
{
Mock<IConfigurationRoot> configurationRootMock = new();
configurationRootMock.GetDefaultMockConfig();
configurationRootMock.MockGetValue(UserConfigurationKeys.ASSETS_DIRECTORY, assetsDirectory);
configurationRootMock.MockGetValue(UserConfigurationKeys.PROJECT_NAME, projectName);
configurationRootMock.MockGetValue(UserConfigurationKeys.PROJECT_OWNER, projectOwner);

UserConfigurationService userConfigurationService = new (configurationRootMock.Object);

Mock<IStorageService> storageServiceMock = new();
storageServiceMock.Setup(x => x.ResolveDataDirectory(It.IsAny<string>())).Returns(_databasePath!);
storageServiceMock.Setup(x => x.LoadBitmapThumbnailImage(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>())).Returns(new BitmapImage());

Database database = new (new ObjectListStorage(), new BlobStorage(), new BackupStorage());
AssetRepository assetRepository = new (database, storageServiceMock.Object, userConfigurationService);
StorageService storageService = new (userConfigurationService);
AssetHashCalculatorService assetHashCalculatorService = new (userConfigurationService);
AssetCreationService assetCreationService = new (assetRepository, storageService, assetHashCalculatorService, userConfigurationService);
AssetsComparator assetsComparator = new();
CatalogAssetsService catalogAssetsService = new (assetRepository, storageService, assetCreationService, userConfigurationService, assetsComparator);
MoveAssetsService moveAssetsService = new (assetRepository, storageService, assetCreationService);
SyncAssetsService syncAssetsService = new (assetRepository, storageService, assetsComparator, moveAssetsService);
FindDuplicatedAssetsService findDuplicatedAssetsService = new (assetRepository, storageService, userConfigurationService);
_application = new (assetRepository, syncAssetsService, catalogAssetsService, moveAssetsService, findDuplicatedAssetsService, userConfigurationService, storageService);
}

[Test]
[TestCase("PhotoManager", "Toto", "PhotoManager", "Toto")]
[TestCase("Photo Toto", "Tutu", "PhotoManager", "Tutu")]
public void GetAboutInformation_WithValidAssembly_ReturnsAboutInformation(
string projectName,
string projectOwner,
string expectedProjectName,
string expectedProjectOwner)
{
ConfigureApplication(_dataDirectory!, projectName, projectOwner);

try
{
AboutInformation aboutInformation = _application!.GetAboutInformation(typeof(App).Assembly);

Assert.That(aboutInformation.Product, Is.EqualTo(expectedProjectName));
Assert.That(aboutInformation.Author, Is.EqualTo(expectedProjectOwner));
Assert.That(string.IsNullOrWhiteSpace(aboutInformation.Version), Is.False);
Assert.That(aboutInformation.Version, Does.StartWith("v"));
Assert.That(aboutInformation.Version, Is.EqualTo("v1.0.0"));
}
finally
{
Directory.Delete(_databaseDirectory!, true);
}
}

[Test]
public void GetAboutInformation_WithDifferentAssembly_ReturnsDifferentProduct()
{
ConfigureApplication(_dataDirectory!, "PhotoManager", "Toto");

try
{
AboutInformation aboutInformation = _application!.GetAboutInformation(typeof(int).Assembly);

Assert.That(aboutInformation.Product, Is.Not.EqualTo("PhotoManager"));
Assert.That(aboutInformation.Author, Is.EqualTo("Toto"));
Assert.That(aboutInformation.Version, Is.EqualTo("v1.0.0"));
}
finally
{
Directory.Delete(_databaseDirectory!, true);
}
}

[Test]
[TestCase("Manager Photo", "Toto")]
[TestCase("Photo Toto", "Tutu")]
public void GetAboutInformation_WithAssemblyWithoutProductAttribute_ReturnsDefaultProduct(string expectedProjectName, string expectedProjectOwner)
{
ConfigureApplication(_dataDirectory!, expectedProjectName, expectedProjectOwner);

AssemblyName assemblyName = new ("TestAssemblyWithoutProductAttribute");
AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);

try
{
AboutInformation aboutInformation = _application!.GetAboutInformation(assemblyBuilder);

Assert.That(aboutInformation.Product, Is.EqualTo(expectedProjectName));
Assert.That(aboutInformation.Author, Is.EqualTo(expectedProjectOwner));
Assert.That(aboutInformation.Version, Is.EqualTo("v1.0.0"));
}
finally
{
Directory.Delete(_databaseDirectory!, true);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using PhotoManager.UI;
using System.Reflection;
using System.Reflection.Emit;

namespace PhotoManager.Tests.Integration.Infrastructure;

Expand Down Expand Up @@ -70,7 +72,7 @@ public void GetAboutInformation_WithValidAssembly_ReturnsAboutInformation()
}

[Test]
public void GetAboutInformation_WithInvalidAssembly_ReturnsDefaultProduct()
public void GetAboutInformation_WithDifferentAssembly_ReturnsDifferentProduct()
{
AboutInformation aboutInformation = _userConfigurationService!.GetAboutInformation(typeof(int).Assembly);

Expand All @@ -79,6 +81,19 @@ public void GetAboutInformation_WithInvalidAssembly_ReturnsDefaultProduct()
Assert.That(aboutInformation.Version, Is.EqualTo("v1.0.0"));
}

[Test]
public void GetAboutInformation_WithAssemblyWithoutProductAttribute_ReturnsDefaultProduct()
{
AssemblyName assemblyName = new ("TestAssemblyWithoutProductAttribute");
AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);

AboutInformation aboutInformation = _userConfigurationService!.GetAboutInformation(assemblyBuilder);

Assert.That(aboutInformation.Product, Is.EqualTo("PhotoManager"));
Assert.That(aboutInformation.Author, Is.EqualTo("Toto"));
Assert.That(aboutInformation.Version, Is.EqualTo("v1.0.0"));
}

[Test]
public void AnalyseVideos_CorrectValue_ReturnsAnalyseVideosValue()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using PhotoManager.UI;
using System.Reflection;
using System.Reflection.Emit;

namespace PhotoManager.Tests.Unit.Infrastructure;

Expand Down Expand Up @@ -29,7 +31,7 @@ public void GetAboutInformation_WithValidAssembly_ReturnsAboutInformation()
}

[Test]
public void GetAboutInformation_WithInvalidAssembly_ReturnsDefaultProduct()
public void GetAboutInformation_WithDifferentAssembly_ReturnsDifferentProduct()
{
AboutInformation aboutInformation = _userConfigurationService!.GetAboutInformation(typeof(int).Assembly);

Expand All @@ -38,6 +40,19 @@ public void GetAboutInformation_WithInvalidAssembly_ReturnsDefaultProduct()
Assert.That(aboutInformation.Version, Is.EqualTo("v1.0.0"));
}

[Test]
public void GetAboutInformation_WithAssemblyWithoutProductAttribute_ReturnsDefaultProduct()
{
AssemblyName assemblyName = new ("TestAssemblyWithoutProductAttribute");
AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);

AboutInformation aboutInformation = _userConfigurationService!.GetAboutInformation(assemblyBuilder);

Assert.That(aboutInformation.Product, Is.EqualTo("PhotoManager"));
Assert.That(aboutInformation.Author, Is.EqualTo("Toto"));
Assert.That(aboutInformation.Version, Is.EqualTo("v1.0.0"));
}

[Test]
public void AnalyseVideos_CorrectValue_ReturnsAnalyseVideosValue()
{
Expand Down

0 comments on commit c1aba26

Please sign in to comment.