-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathCreateInstanceTest.cs
77 lines (56 loc) · 1.53 KB
/
CreateInstanceTest.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
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Tynamix.ObjectFiller.Test
{
public abstract class Parent
{
public Parent(int id)
{
Id = id;
}
public int Id { get; set; }
}
public class ChildOne : Parent
{
public ChildOne(int id)
: base(id)
{
}
public string Name { get; set; }
}
public class ChildTwo : Parent
{
public ChildTwo(int id)
: base(id)
{
}
public string OtherName { get; set; }
}
public class ParentOfParent
{
public ParentOfParent()
{
Parents = new List<Parent>();
}
public List<Parent> Parents { get; private set; }
}
[TestClass]
public class CreateInstanceTest
{
[TestMethod]
public void TestCreateInstanceOfChildOne()
{
Filler<ParentOfParent> p = new Filler<ParentOfParent>();
p.Setup().OnType<Parent>().CreateInstanceOf<ChildOne>()
.SetupFor<ChildOne>()
.OnProperty(x => x.Name).Use(() => "TEST");
var pop = p.Create();
Assert.IsNotNull(pop);
Assert.IsNotNull(pop.Parents);
Assert.IsTrue(pop.Parents.All(x => x is ChildOne));
Assert.IsFalse(pop.Parents.Any(x => x is ChildTwo));
Assert.IsTrue(pop.Parents.Cast<ChildOne>().All(x => x.Name == "TEST"));
}
}
}