Skip to content

Commit

Permalink
Add unit tests for AbstractFactory.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Feb 3, 2024
1 parent dbb9a53 commit 0406979
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Azure.Storage.Files.DataLake;
using DesignPatterns.AbstractFactory.DataLake;
using FluentAssertions;
using FluentAssertions.Execution;
using Moq;
using Xunit;

namespace DesignPatterns.AbstractFactory.UnitTests.DataLake;

public class StorageFactoryTests
{
[Fact]
public void Given_WhenCallCreate_ThenResultAsExpected()
{
var mockSettings = new Mock<StorageSettings>();
var mockServiceClient = new Mock<DataLakeServiceClient>();
var storageFactory = new StorageFactory(mockSettings.Object, mockServiceClient.Object);

IStorage? result = null;
var action = () => result = storageFactory.Create();
using (new AssertionScope())
{
action.Should().NotThrow();
result.Should().NotBeNull();
result.Should().BeOfType<Storage>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>DesignPatterns.AbstractFactory.UnitTests</RootNamespace>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DesignPatterns.AbstractFactory\DesignPatterns.AbstractFactory.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using DesignPatterns.AbstractFactory.Local;
using FluentAssertions;
using FluentAssertions.Execution;
using Moq;
using Xunit;

namespace DesignPatterns.AbstractFactory.UnitTests.Local;

public class StorageFactoryTests
{
[Fact]
public void Given_WhenCallCreate_ThenResultAsExpected()
{
var mockSettings = new Mock<StorageSettings>();
var storageFactory = new StorageFactory(mockSettings.Object);

IStorage? result = null;
var action = () => result = storageFactory.Create();
using (new AssertionScope())
{
action.Should().NotThrow();
result.Should().NotBeNull();
result.Should().BeOfType<Storage>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.17.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.17.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions DesignPatterns.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Creational", "Creational",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns.AbstractFactory", "Creational\DesignPatterns.AbstractFactory\DesignPatterns.AbstractFactory.csproj", "{0C5CFC73-F6E4-4796-A11C-9CA378B80517}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPatterns.AbstractFactory.UnitTests", "Creational\DesignPatterns.AbstractFactory.UnitTests\DesignPatterns.AbstractFactory.UnitTests.csproj", "{1E56CC89-45C1-45F7-9EC8-88D648572816}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -28,10 +30,15 @@ Global
{0C5CFC73-F6E4-4796-A11C-9CA378B80517}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C5CFC73-F6E4-4796-A11C-9CA378B80517}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C5CFC73-F6E4-4796-A11C-9CA378B80517}.Release|Any CPU.Build.0 = Release|Any CPU
{1E56CC89-45C1-45F7-9EC8-88D648572816}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E56CC89-45C1-45F7-9EC8-88D648572816}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E56CC89-45C1-45F7-9EC8-88D648572816}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E56CC89-45C1-45F7-9EC8-88D648572816}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DCE06EB6-BAB5-4573-AF67-128DBCCDB90C} = {7FF0E83F-EBEB-4103-BCD1-2F100E82FCD1}
{02AA0F74-2EFE-4804-8938-A92542860F74} = {7FF0E83F-EBEB-4103-BCD1-2F100E82FCD1}
{0C5CFC73-F6E4-4796-A11C-9CA378B80517} = {AE005ED4-5F0B-4AF9-81AE-AAE3AD6F8901}
{1E56CC89-45C1-45F7-9EC8-88D648572816} = {AE005ED4-5F0B-4AF9-81AE-AAE3AD6F8901}
EndGlobalSection
EndGlobal

0 comments on commit 0406979

Please sign in to comment.