Skip to content

Commit e04ec8b

Browse files
authored
Merge pull request #138 from Tynamix/develop
FI from DEV
2 parents b2b260e + 49e3acb commit e04ec8b

22 files changed

+635
-175
lines changed

ObjectFillerNET.sln

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26430.16
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.32112.339
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0EC5FD26-A565-4D47-A192-0FC142C3B7F0}"
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tynamix.ObjectFiller", "Tynamix.ObjectFiller\Tynamix.ObjectFiller.csproj", "{7F8E176C-12A7-45B7-886E-5A4923B2F252}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tynamix.ObjectFiller.Test", "Tynamix.ObjectFiller.Test\Tynamix.ObjectFiller.Test.csproj", "{F2BFBBDC-E8A0-4263-AD9A-DDC87C4CD4DE}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tynamix.ObjectFiller.Test", "Tynamix.ObjectFiller.Test\Tynamix.ObjectFiller.Test.csproj", "{F2BFBBDC-E8A0-4263-AD9A-DDC87C4CD4DE}"
1111
EndProject
1212
Global
1313
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -27,6 +27,9 @@ Global
2727
GlobalSection(SolutionProperties) = preSolution
2828
HideSolutionNode = FALSE
2929
EndGlobalSection
30+
GlobalSection(ExtensibilityGlobals) = postSolution
31+
SolutionGuid = {49C4194A-811F-47D8-A814-46F89C1B897E}
32+
EndGlobalSection
3033
GlobalSection(TestCaseManagementSettings) = postSolution
3134
CategoryFile = ObjectFillerNET.vsmdi
3235
EndGlobalSection

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
[![Build status](https://ci.appveyor.com/api/projects/status/pa49pti5v13iux3i?svg=true)](https://ci.appveyor.com/project/Tynamix/objectfiller-net)
22
[![Join the chat at https://gitter.im/Tynamix/ObjectFiller.NET](https://badges.gitter.im/Tynamix/ObjectFiller.NET.svg)](https://gitter.im/Tynamix/ObjectFiller.NET?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
33

4+
# ObjectFiller.NET
5+
<p align="center">
6+
<img src="https://raw.githubusercontent.com/Tynamix/ObjectFiller.NET/master/logo.png">
7+
</p>
48

5-
#ObjectFiller.NET
6-
7-
<img align="left" src="https://raw.githubusercontent.com/Tynamix/ObjectFiller.NET/master/logo.png" alt="Logo" />
89
The **.NET ObjectFiller** fills the properties of your .NET objects with random data!
910
It has a very comfortable Fluent API.
1011
You are able to fill object instances or you just let them create for you.
1112
It is also possible to create instances of classes which have constructors with parameters.
1213
You can also fill properties which are derived by an interface.
1314
The **.NET ObjectFiller** also supports IEnumerable<T> (and all derivations) as well as Dictionaries.
15+
16+
----------
17+
18+
### Donate
19+
I do not make any money with ObjectFiller.NET. It is a pure hobby project. But if I could save your time with this project or if you like to use the library I would be very happy about a small donation!
20+
21+
<p align="center">
22+
<a href="https://www.paypal.com/donate/?hosted_button_id=P89J29HBE3WBC" target="_blank"><img src="https://www.paypalobjects.com/webstatic/de_DE/i/de-pp-logo-200px.png"></a>
23+
</p>
1424

25+
----------
1526

1627
### Get it on
1728
[NuGet](https://www.nuget.org/packages/Tynamix.ObjectFiller)!
@@ -20,9 +31,8 @@ The **.NET ObjectFiller** also supports IEnumerable<T> (and all derivations) as
2031

2132
----------
2233

23-
2434
### Quick Start
25-
<img src="https://raw.githubusercontent.com/Tynamix/ObjectFiller.NET/master/objectfiller-quickstart.gif" alt="ObjectFiller.NET Quickstart" />
35+
![ObjectFiller.NET Quickstart](https://raw.githubusercontent.com/Tynamix/ObjectFiller.NET/master/objectfiller-quickstart.gif)
2636

2737
----------
2838

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
4+
namespace Tynamix.ObjectFiller.Test.BugfixTests
5+
{
6+
[TestClass]
7+
public class Bug129WrongDateTimeGeneration
8+
{
9+
public class TestEntity
10+
{
11+
public DateTime Date { get; set; }
12+
}
13+
14+
[TestMethod]
15+
public void InvalidDateTimeValuesDueToDaylightSavingsTime()
16+
{
17+
Filler<TestEntity> filler = new Filler<TestEntity>();
18+
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
19+
filler.Setup().OnType<DateTime>().Use(new DateTimeRange(new DateTime(2007, 3, 11, 1, 0, 0, DateTimeKind.Unspecified), new DateTime(2007, 3, 11, 4, 00, 0, DateTimeKind.Unspecified), timeZoneInfo));
20+
21+
for (int i = 0; i < 1000; i++)
22+
{
23+
var result = filler.Create();
24+
Assert.IsFalse(timeZoneInfo.IsInvalidTime(result.Date), $"{result.Date} is invalid");
25+
}
26+
27+
filler = new Filler<TestEntity>();
28+
filler.Setup().OnType<DateTime>().Use(new DateTimeRange(new DateTime(2022, 3, 27, 1, 0, 0, DateTimeKind.Unspecified), new DateTime(2022, 3, 27, 4, 00, 0, DateTimeKind.Unspecified)));
29+
30+
for (int i = 0; i < 1000; i++)
31+
{
32+
var result = filler.Create();
33+
Assert.IsFalse(TimeZoneInfo.Local.IsInvalidTime(result.Date), $"{result.Date} is invalid");
34+
}
35+
}
36+
}
37+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Tynamix.ObjectFiller.Test.BugfixTests
9+
{
10+
[TestClass]
11+
public class Bug132PropertiesOnBaseClassesNotPopulatedBeyond2Levels
12+
{
13+
public class BaseId
14+
{
15+
public string Id { get; set; }
16+
}
17+
18+
public class BaseWithAudit : BaseId
19+
{
20+
public string CreatedBy { get; set; }
21+
public string UpdatedBy { get; set; }
22+
}
23+
24+
public class Person : BaseWithAudit
25+
{
26+
public string Name { get; set; }
27+
public string LastName { get; set; }
28+
}
29+
[TestMethod]
30+
public void Bug132PropertiesOnBaseClassNotPopulated()
31+
{
32+
var filler = new Filler<Person>();
33+
var x = filler.Create();
34+
Assert.IsFalse(string.IsNullOrWhiteSpace(x.Name));
35+
Assert.IsFalse(string.IsNullOrWhiteSpace(x.LastName));
36+
Assert.IsFalse(string.IsNullOrWhiteSpace(x.CreatedBy));
37+
Assert.IsFalse(string.IsNullOrWhiteSpace(x.UpdatedBy));
38+
Assert.IsFalse(string.IsNullOrWhiteSpace(x.Id));
39+
}
40+
}
41+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
#if NET6_0_OR_GREATER
9+
namespace Tynamix.ObjectFiller.Test.BugfixTests
10+
{
11+
public record Product
12+
{
13+
public string Name { get; init; }
14+
public int CategoryId { get; set; }
15+
}
16+
17+
public record Person(string Name, string Username);
18+
19+
[TestClass]
20+
public class Bug136RecordsObjectReferenceException
21+
{
22+
[TestMethod]
23+
public void RecordsShouldBeFilled()
24+
{
25+
Filler<Product> filler = new Filler<Product>();
26+
var product = filler.Create();
27+
Assert.IsNotNull(product);
28+
Assert.IsFalse(string.IsNullOrWhiteSpace(product.Name));
29+
30+
var filler2 = new Filler<Person>();
31+
var person = filler2.Create();
32+
Assert.IsNotNull(person);
33+
Assert.IsFalse(string.IsNullOrWhiteSpace(person.Name));
34+
Assert.IsFalse(string.IsNullOrWhiteSpace(person.Username));
35+
}
36+
}
37+
}
38+
#endif

Tynamix.ObjectFiller.Test/BugfixTests/Bug68HashsetCanNotBeCreated.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Tynamix.ObjectFiller.Test.BugfixTests
66
{
7+
8+
[TestClass]
79
public class Bug68HashsetCanNotBeCreated
810
{
911
[TestMethod]

Tynamix.ObjectFiller.Test/BugfixTests/Bug89FillTypesInheritsFromDictionary.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
namespace Tynamix.ObjectFiller.Test.BugfixTests
77
{
8+
9+
[TestClass]
810
public class Bug89FillTypesInheritsFromDictionary
911
{
1012
public class EntityA

Tynamix.ObjectFiller.Test/BugfixTests/Bug89FillTypesInheritsFromList.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
namespace Tynamix.ObjectFiller.Test.BugfixTests
77
{
8+
9+
[TestClass]
810
public class Bug89FillTypesInheritsFromList
911
{
1012
public class EntityA

Tynamix.ObjectFiller.Test/BugfixTests/Bug91FailToCreateIReadOnlyCollection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Tynamix.ObjectFiller.Test.BugfixTests
88
using System.Collections;
99
using Microsoft.VisualStudio.TestTools.UnitTesting;
1010

11+
1112
public class OrderWithObject
1213
{
1314
public IReadOnlyCollection<Book> OrderLines { get; set; }

Tynamix.ObjectFiller.Test/CollectionizerTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ public class CollectionizerPoco
1212

1313
public List<int> IntRange { get; set; }
1414

15+
#if !NET6
1516
public ArrayList ArrayList { get; set; }
16-
17+
#endif
1718
public string[] StringArray { get; set; }
1819
}
1920

2021
[TestClass]
2122
public class CollectionizerTest
2223
{
24+
#if !NET6
2325
[TestMethod]
2426
public void TestCityNames()
2527
{
@@ -31,6 +33,7 @@ public void TestCityNames()
3133
Assert.IsTrue(arrayList.ArrayList.Count >= 3 && arrayList.ArrayList.Count <= 10);
3234
Assert.IsTrue(arrayList.ArrayList.ToArray().Cast<string>().All(x => x.Length >= 20 && x.Length <= 25));
3335
}
36+
#endif
3437

3538
[TestMethod]
3639
public void TestMnemonicStringPlugin()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
7+
namespace Tynamix.ObjectFiller.Test
8+
{
9+
[TestClass]
10+
public class DictionaryFillingTest
11+
{
12+
public class EntityA
13+
{
14+
public string Name { get; set; }
15+
public int ID { get; set; }
16+
public IDictionary<string, string> InterfaceDictionary { get; set; }
17+
public Dictionary<string, string> ConcreteDictionary { get; set; }
18+
19+
public NestedEntity NestedEntity { get; set; }
20+
}
21+
22+
public class NestedEntity
23+
{
24+
public IDictionary<string, string> InterfaceDictionary { get; set; }
25+
public Dictionary<string, string> ConcreteDictionary { get; set; }
26+
}
27+
28+
29+
[TestMethod]
30+
public void TestDictionaryType()
31+
{
32+
Filler<EntityA> filler = new Filler<EntityA>();
33+
34+
var result = filler.Create();
35+
36+
Assert.IsNotNull(result.Name);
37+
Assert.IsNotNull(result.ID);
38+
Assert.IsNotNull(result.InterfaceDictionary);
39+
Assert.IsTrue(result.InterfaceDictionary.Any());
40+
Assert.IsNotNull(result.ConcreteDictionary);
41+
Assert.IsTrue(result.ConcreteDictionary.Any());
42+
43+
Assert.IsNotNull(result.NestedEntity);
44+
Assert.IsNotNull(result.NestedEntity.InterfaceDictionary);
45+
Assert.IsTrue(result.NestedEntity.InterfaceDictionary.Any());
46+
Assert.IsNotNull(result.NestedEntity.ConcreteDictionary);
47+
Assert.IsTrue(result.NestedEntity.ConcreteDictionary.Any());
48+
49+
}
50+
}
51+
}

Tynamix.ObjectFiller.Test/RangePluginTest.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,69 @@ public void TestFloateRangeWithMinMaxValue()
5151
Assert.IsNotNull(sl.ChildList);
5252
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
5353
}
54+
55+
[TestMethod]
56+
public void TestLongRangeWithMaxValue()
57+
{
58+
long max = int.MaxValue * 10L;
59+
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();
60+
61+
filler.Setup().OnType<long>().Use(new LongRange(max));
62+
var sl = filler.Create();
63+
64+
Assert.IsNotNull(sl);
65+
Assert.IsNotNull(sl.ChildList);
66+
Assert.IsTrue(sl.ChildList.All(x => x < max));
67+
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
68+
}
69+
70+
[TestMethod]
71+
public void TestLongRangeWithMinMaxValue()
72+
{
73+
long min = int.MinValue * 10L;
74+
long max = int.MaxValue * 10L;
75+
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();
76+
77+
filler.Setup().OnType<long>().Use(new LongRange(min, max));
78+
var sl = filler.Create();
79+
80+
Assert.IsNotNull(sl);
81+
Assert.IsNotNull(sl.ChildList);
82+
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
83+
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
84+
}
85+
86+
[TestMethod]
87+
public void TestLongRangeWithMinMaxValueLowSmallRange()
88+
{
89+
long min = long.MinValue;
90+
long max = long.MinValue + 10;
91+
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();
92+
93+
filler.Setup().OnType<long>().Use(new LongRange(min, max));
94+
var sl = filler.Create();
95+
96+
Assert.IsNotNull(sl);
97+
Assert.IsNotNull(sl.ChildList);
98+
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
99+
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
100+
}
101+
102+
[TestMethod]
103+
public void TestLongRangeWithMinMaxValueHighSmallRange()
104+
{
105+
long min = long.MaxValue - 10;
106+
long max = long.MaxValue;
107+
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();
108+
109+
filler.Setup().OnType<long>().Use(new LongRange(min, max));
110+
var sl = filler.Create();
111+
112+
Assert.IsNotNull(sl);
113+
Assert.IsNotNull(sl.ChildList);
114+
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
115+
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
116+
}
117+
54118
}
55119
}

0 commit comments

Comments
 (0)