Skip to content

Commit

Permalink
Unit test for Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasstich committed Oct 8, 2024
1 parent 270b9a0 commit ba980b0
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 4 deletions.
11 changes: 11 additions & 0 deletions Moyou.UnitTest/Factory/Factory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Moyou.Aspects.Factory;

namespace Moyou.UnitTest.Factory;

[Factory]
[FactoryMember(TargetType = typeof(TypeA))]
[FactoryMember(TargetType = typeof(TypeB), PrimaryInterface = typeof(ITypeB))]
public partial class Factory
{

}
26 changes: 26 additions & 0 deletions Moyou.UnitTest/Factory/FactoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using NUnit.Framework;

namespace Moyou.UnitTest.Factory;

public class FactoryTest
{
[Test]
public void FactoryInstantiatesCorrectly()
{
var sut = new Factory();
var typeA = sut.CreateTypeA(321);
var typeB = sut.CreateTypeB();

Assert.Multiple(() =>
{
Assert.That(typeA, Is.Not.Null);
Assert.That(typeB, Is.Not.Null);
});

Assert.Multiple(() =>
{
Assert.That(typeA.Foo, Is.EqualTo(321));
Assert.That(typeB.Bar, Is.EqualTo("foobar"));
});
}
}
6 changes: 6 additions & 0 deletions Moyou.UnitTest/Factory/ISomeOtherInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Moyou.UnitTest.Factory;

public interface ISomeOtherInterface
{

}
6 changes: 6 additions & 0 deletions Moyou.UnitTest/Factory/ITypeA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Moyou.UnitTest.Factory;

public interface ITypeA
{
int Foo { get; set; }
}
6 changes: 6 additions & 0 deletions Moyou.UnitTest/Factory/ITypeB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Moyou.UnitTest.Factory;

public interface ITypeB
{
string Bar { get; }
}
19 changes: 19 additions & 0 deletions Moyou.UnitTest/Factory/TypeA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Moyou.Aspects.Factory;

namespace Moyou.UnitTest.Factory;

public class TypeA : ITypeA
{
public TypeA()
{
Foo = 123;
}

[FactoryConstructor]
public TypeA(int foo)
{
Foo = foo;
}

public int Foo { get; set; }
}
11 changes: 11 additions & 0 deletions Moyou.UnitTest/Factory/TypeB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Moyou.UnitTest.Factory;

public class TypeB : ITypeB, ISomeOtherInterface
{
public TypeB()
{
Bar = "foobar";
}

public string Bar { get; init; }
}
5 changes: 1 addition & 4 deletions Moyou.UnitTest/Moyou.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,10 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Moyou.Aspects\Moyou.Aspects.Factory\Moyou.Aspects.Factory.csproj" />
<ProjectReference Include="..\Moyou.Aspects\Moyou.Aspects.Memento\Moyou.Aspects.Memento.csproj" />
<ProjectReference Include="..\Moyou.Aspects\Moyou.Aspects.Singleton\Moyou.Aspects.Singleton.csproj" />
<ProjectReference Include="..\Moyou.Aspects\Moyou.Aspects.UnsavedChanges\Moyou.Aspects.UnsavedChanges.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Factory\" />
</ItemGroup>

</Project>

0 comments on commit ba980b0

Please sign in to comment.