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
24 changes: 24 additions & 0 deletions BuilderPattern.Tests/BuilderPattern.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BuilderPattern\BuilderPattern.csproj" />
</ItemGroup>

</Project>
78 changes: 78 additions & 0 deletions BuilderPattern.Tests/BuilderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
namespace BuilderPattern.Tests
{
[TestFixture]
public class BuilderTests
{
[TestCaseSource(nameof(_sizeCases))]
public void AddSize_TwoBuilderCases_ReturnsInstanceOfHamburgerClassWithFilledSize(IBuilder builder, int expected)
{
// Arrange, Act
builder.Reset();
builder.AddSize();
var hamburger = builder.Build();

// Assert
Assert.Multiple(() =>
{
Assert.That(hamburger.Size, Is.EqualTo(expected));
Assert.That(hamburger.Shape, Is.Null);
Assert.That(hamburger.Ingredients, Is.Null);
});
}

[TestCaseSource(nameof(_shapeCases))]
public void AddShape_TwoBuilderCases_ReturnsInstanceOfHamburgerClassWithFilledShape(IBuilder builder, string expected)
{
// Arrange, Act
builder.Reset();
builder.AddShape();
var hamburger = builder.Build();

// Assert
Assert.Multiple(() =>
{
Assert.That(hamburger.Size, Is.Zero);
Assert.That(hamburger.Shape, Is.EqualTo(expected));
Assert.That(hamburger.Ingredients, Is.Null);
});
}

[TestCaseSource(nameof(_ingredientsCases))]
public void AddIngredients_TwoBuilderCases_ReturnsInstanceOfHamburgerClassWithFilledIngredients(IBuilder builder, string[] expected)
{
// Arrange, Act
builder.Reset();
builder.AddIngredients();
var hamburger = builder.Build();

// Assert
Assert.Multiple(() =>
{
Assert.That(hamburger.Size, Is.Zero);
Assert.That(hamburger.Shape, Is.Null);
Assert.That(hamburger.Ingredients, Is.EquivalentTo(expected));
});
}

private static readonly List<TestCaseData> _sizeCases =
new(new[]
{
new TestCaseData(new MyHamburgerBuilder(), 10),
new TestCaseData(new WifesHamburgerBuilder(), 6)
});

private static readonly List<TestCaseData> _shapeCases =
new(new[]
{
new TestCaseData(new MyHamburgerBuilder(), "Kite"),
new TestCaseData(new WifesHamburgerBuilder(), "Cuboid")
});

private static readonly List<TestCaseData> _ingredientsCases =
new(new[]
{
new TestCaseData(new MyHamburgerBuilder(), new string[] { "Bread", "Meat", "Tomato", "Salad", "Mayonnaise" }),
new TestCaseData(new WifesHamburgerBuilder(), new string[] { "Bread", "Salad" })
});
}
}
41 changes: 41 additions & 0 deletions BuilderPattern.Tests/DirectorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Moq;

namespace BuilderPattern.Tests
{
[TestFixture]
public class DirectorTests
{
private Cook _cook;
private Mock<IBuilder> _builder;

[OneTimeSetUp]
public void SetUp()
{
_builder = new Mock<IBuilder>();
_cook = new Cook(_builder.Object);
}

[Test]
public void ChangeBuilder_DeclareMyHamburgerBuilder_ReturnsHamburgerByWifesHamburgerBuilder()
{
// Arrange, Act
_cook.ChangeBuilder(new WifesHamburgerBuilder());

// Assert
_builder.Verify(s => s.Reset());
}

[Test]
public void Build_TwoBuilderCases_ReturnsFilledInstanceOfHamburgerClass()
{
// Arrange, Act
var actual = _cook.Build();

// Assert
_builder.Verify(s => s.AddIngredients());
_builder.Verify(s => s.AddShape());
_builder.Verify(s => s.AddSize());
_builder.Verify(s => s.Build());
}
}
}
1 change: 1 addition & 0 deletions BuilderPattern.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using NUnit.Framework;
20 changes: 17 additions & 3 deletions DesignPatternsDotNetCore.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29920.165
# Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdapterPattern", "AdapterPattern\AdapterPattern.csproj", "{79553F75-E8DC-4988-B511-A79CC6A9CDF7}"
EndProject
Expand Down Expand Up @@ -38,7 +38,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatorPattern", "Mediator
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BuilderPattern", "BuilderPattern\BuilderPattern.csproj", "{274786D8-2E30-40D7-81B5-DFA3872CF9B6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxyPattern", "ProxyPattern\ProxyPattern.csproj", "{0F8297F6-FA4F-44B6-BF99-0FF71ECCF87A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProxyPattern", "ProxyPattern\ProxyPattern.csproj", "{0F8297F6-FA4F-44B6-BF99-0FF71ECCF87A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuilderPattern.Tests", "BuilderPattern.Tests\BuilderPattern.Tests.csproj", "{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -278,6 +280,18 @@ Global
{0F8297F6-FA4F-44B6-BF99-0FF71ECCF87A}.Release|x64.Build.0 = Release|Any CPU
{0F8297F6-FA4F-44B6-BF99-0FF71ECCF87A}.Release|x86.ActiveCfg = Release|Any CPU
{0F8297F6-FA4F-44B6-BF99-0FF71ECCF87A}.Release|x86.Build.0 = Release|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Debug|x64.ActiveCfg = Debug|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Debug|x64.Build.0 = Debug|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Debug|x86.ActiveCfg = Debug|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Debug|x86.Build.0 = Debug|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Release|Any CPU.Build.0 = Release|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Release|x64.ActiveCfg = Release|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Release|x64.Build.0 = Release|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Release|x86.ActiveCfg = Release|Any CPU
{2B52592E-AA8A-4C2E-ADE8-BDA8942CDFFA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down