-
Notifications
You must be signed in to change notification settings - Fork 647
/
Copy pathAbstractFactoryTests.cs
92 lines (78 loc) · 3.49 KB
/
AbstractFactoryTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
namespace FactoryPattern.Tests
{
[TestFixture]
public class AbstractFactoryTests
{
[TestCaseSource(nameof(_cheeseCases))]
public void CreateCheese_CheeseFromIngredientsFactories_ReturnsCertainCheeseType(object ingredientsFactory, Type expected)
{
// Arrange, Act
var actual = ((IIngredientsFactory)ingredientsFactory).CreateCheese();
// Assert
Assert.That(actual, Is.InstanceOf(expected));
}
[TestCaseSource(nameof(_clamCases))]
public void CreateClam_ClamFromIngredientsFactories_ReturnsCertainClamType(object ingredientsFactory, Type expected)
{
// Arrange, Act
var actual = ((IIngredientsFactory)ingredientsFactory).CreateClam();
// Assert
Assert.That(actual, Is.InstanceOf(expected));
}
[TestCaseSource(nameof(_doughCases))]
public void CreateDough_DoughFromIngredientsFactories_ReturnsCertainDoughType(object ingredientsFactory, Type expected)
{
// Arrange, Act
var actual = ((IIngredientsFactory)ingredientsFactory).CreateDough();
// Assert
Assert.That(actual, Is.InstanceOf(expected));
}
[TestCaseSource(nameof(_sauceCases))]
public void CreateSauce_SauceFromIngredientsFactories_ReturnsCertainSauceType(object ingredientsFactory, Type expected)
{
// Arrange, Act
var actual = ((IIngredientsFactory)ingredientsFactory).CreateSauce();
// Assert
Assert.That(actual, Is.InstanceOf(expected));
}
[TestCaseSource(nameof(_veggiesCases))]
public void CreateVeggies_VeggiesFromIngredientsFactories_ReturnsCertainVeggiesSet(object ingredientsFactory, string[] expected)
{
// Arrange, Act
var veggies = ((IIngredientsFactory)ingredientsFactory).CreateVeggies();
var actual = veggies.Select(v => v.Name);
// Assert
Assert.That(actual, Is.EqualTo(expected));
}
private static readonly List<TestCaseData> _cheeseCases =
new(new[]
{
new TestCaseData(new NyIngredientsFactory(), typeof(Mozarella)),
new TestCaseData(new ChicagoIngredientsFactory(), typeof(Parmesan))
});
private static readonly List<TestCaseData> _clamCases =
new(new[]
{
new TestCaseData(new NyIngredientsFactory(), typeof(FrozenClam)),
new TestCaseData(new ChicagoIngredientsFactory(), typeof(FreshClam))
});
private static readonly List<TestCaseData> _doughCases =
new(new[]
{
new TestCaseData(new NyIngredientsFactory(), typeof(ThinCrust)),
new TestCaseData(new ChicagoIngredientsFactory(), typeof(DeepDish))
});
private static readonly List<TestCaseData> _sauceCases =
new(new[]
{
new TestCaseData(new NyIngredientsFactory(), typeof(CherryTomato)),
new TestCaseData(new ChicagoIngredientsFactory(), typeof(PlumTomato))
});
private static readonly List<TestCaseData> _veggiesCases =
new(new[]
{
new TestCaseData(new NyIngredientsFactory(), new string[] { "Onions", "Bell Peppers", "Olives" }),
new TestCaseData(new ChicagoIngredientsFactory(), new string[] { "Onions", "Cucumber", "Bell Peppers" })
});
}
}