Skip to content

FI from DEV #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 9, 2022
Merged
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
9 changes: 6 additions & 3 deletions ObjectFillerNET.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0EC5FD26-A565-4D47-A192-0FC142C3B7F0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tynamix.ObjectFiller", "Tynamix.ObjectFiller\Tynamix.ObjectFiller.csproj", "{7F8E176C-12A7-45B7-886E-5A4923B2F252}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tynamix.ObjectFiller.Test", "Tynamix.ObjectFiller.Test\Tynamix.ObjectFiller.Test.csproj", "{F2BFBBDC-E8A0-4263-AD9A-DDC87C4CD4DE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tynamix.ObjectFiller.Test", "Tynamix.ObjectFiller.Test\Tynamix.ObjectFiller.Test.csproj", "{F2BFBBDC-E8A0-4263-AD9A-DDC87C4CD4DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +27,9 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {49C4194A-811F-47D8-A814-46F89C1B897E}
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = ObjectFillerNET.vsmdi
EndGlobalSection
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
[![Build status](https://ci.appveyor.com/api/projects/status/pa49pti5v13iux3i?svg=true)](https://ci.appveyor.com/project/Tynamix/objectfiller-net)
[![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)

# ObjectFiller.NET
<p align="center">
<img src="https://raw.githubusercontent.com/Tynamix/ObjectFiller.NET/master/logo.png">
</p>

#ObjectFiller.NET

<img align="left" src="https://raw.githubusercontent.com/Tynamix/ObjectFiller.NET/master/logo.png" alt="Logo" />
The **.NET ObjectFiller** fills the properties of your .NET objects with random data!
It has a very comfortable Fluent API.
You are able to fill object instances or you just let them create for you.
It is also possible to create instances of classes which have constructors with parameters.
You can also fill properties which are derived by an interface.
The **.NET ObjectFiller** also supports IEnumerable<T> (and all derivations) as well as Dictionaries.

----------

### Donate
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!

<p align="center">
<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>
</p>

----------

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

----------


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

----------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Tynamix.ObjectFiller.Test.BugfixTests
{
[TestClass]
public class Bug129WrongDateTimeGeneration
{
public class TestEntity
{
public DateTime Date { get; set; }
}

[TestMethod]
public void InvalidDateTimeValuesDueToDaylightSavingsTime()
{
Filler<TestEntity> filler = new Filler<TestEntity>();
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
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));

for (int i = 0; i < 1000; i++)
{
var result = filler.Create();
Assert.IsFalse(timeZoneInfo.IsInvalidTime(result.Date), $"{result.Date} is invalid");
}

filler = new Filler<TestEntity>();
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)));

for (int i = 0; i < 1000; i++)
{
var result = filler.Create();
Assert.IsFalse(TimeZoneInfo.Local.IsInvalidTime(result.Date), $"{result.Date} is invalid");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tynamix.ObjectFiller.Test.BugfixTests
{
[TestClass]
public class Bug132PropertiesOnBaseClassesNotPopulatedBeyond2Levels
{
public class BaseId
{
public string Id { get; set; }
}

public class BaseWithAudit : BaseId
{
public string CreatedBy { get; set; }
public string UpdatedBy { get; set; }
}

public class Person : BaseWithAudit
{
public string Name { get; set; }
public string LastName { get; set; }
}
[TestMethod]
public void Bug132PropertiesOnBaseClassNotPopulated()
{
var filler = new Filler<Person>();
var x = filler.Create();
Assert.IsFalse(string.IsNullOrWhiteSpace(x.Name));
Assert.IsFalse(string.IsNullOrWhiteSpace(x.LastName));
Assert.IsFalse(string.IsNullOrWhiteSpace(x.CreatedBy));
Assert.IsFalse(string.IsNullOrWhiteSpace(x.UpdatedBy));
Assert.IsFalse(string.IsNullOrWhiteSpace(x.Id));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

#if NET6_0_OR_GREATER
namespace Tynamix.ObjectFiller.Test.BugfixTests
{
public record Product
{
public string Name { get; init; }
public int CategoryId { get; set; }
}

public record Person(string Name, string Username);

[TestClass]
public class Bug136RecordsObjectReferenceException
{
[TestMethod]
public void RecordsShouldBeFilled()
{
Filler<Product> filler = new Filler<Product>();
var product = filler.Create();
Assert.IsNotNull(product);
Assert.IsFalse(string.IsNullOrWhiteSpace(product.Name));

var filler2 = new Filler<Person>();
var person = filler2.Create();
Assert.IsNotNull(person);
Assert.IsFalse(string.IsNullOrWhiteSpace(person.Name));
Assert.IsFalse(string.IsNullOrWhiteSpace(person.Username));
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Tynamix.ObjectFiller.Test.BugfixTests
{

[TestClass]
public class Bug68HashsetCanNotBeCreated
{
[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Tynamix.ObjectFiller.Test.BugfixTests
{

[TestClass]
public class Bug89FillTypesInheritsFromDictionary
{
public class EntityA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Tynamix.ObjectFiller.Test.BugfixTests
{

[TestClass]
public class Bug89FillTypesInheritsFromList
{
public class EntityA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Tynamix.ObjectFiller.Test.BugfixTests
using System.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;


public class OrderWithObject
{
public IReadOnlyCollection<Book> OrderLines { get; set; }
Expand Down
5 changes: 4 additions & 1 deletion Tynamix.ObjectFiller.Test/CollectionizerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ public class CollectionizerPoco

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

#if !NET6
public ArrayList ArrayList { get; set; }

#endif
public string[] StringArray { get; set; }
}

[TestClass]
public class CollectionizerTest
{
#if !NET6
[TestMethod]
public void TestCityNames()
{
Expand All @@ -31,6 +33,7 @@ public void TestCityNames()
Assert.IsTrue(arrayList.ArrayList.Count >= 3 && arrayList.ArrayList.Count <= 10);
Assert.IsTrue(arrayList.ArrayList.ToArray().Cast<string>().All(x => x.Length >= 20 && x.Length <= 25));
}
#endif

[TestMethod]
public void TestMnemonicStringPlugin()
Expand Down
51 changes: 51 additions & 0 deletions Tynamix.ObjectFiller.Test/DictionaryFillingTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tynamix.ObjectFiller.Test
{
[TestClass]
public class DictionaryFillingTest
{
public class EntityA
{
public string Name { get; set; }
public int ID { get; set; }
public IDictionary<string, string> InterfaceDictionary { get; set; }
public Dictionary<string, string> ConcreteDictionary { get; set; }

public NestedEntity NestedEntity { get; set; }
}

public class NestedEntity
{
public IDictionary<string, string> InterfaceDictionary { get; set; }
public Dictionary<string, string> ConcreteDictionary { get; set; }
}


[TestMethod]
public void TestDictionaryType()
{
Filler<EntityA> filler = new Filler<EntityA>();

var result = filler.Create();

Assert.IsNotNull(result.Name);
Assert.IsNotNull(result.ID);
Assert.IsNotNull(result.InterfaceDictionary);
Assert.IsTrue(result.InterfaceDictionary.Any());
Assert.IsNotNull(result.ConcreteDictionary);
Assert.IsTrue(result.ConcreteDictionary.Any());

Assert.IsNotNull(result.NestedEntity);
Assert.IsNotNull(result.NestedEntity.InterfaceDictionary);
Assert.IsTrue(result.NestedEntity.InterfaceDictionary.Any());
Assert.IsNotNull(result.NestedEntity.ConcreteDictionary);
Assert.IsTrue(result.NestedEntity.ConcreteDictionary.Any());

}
}
}
64 changes: 64 additions & 0 deletions Tynamix.ObjectFiller.Test/RangePluginTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,69 @@ public void TestFloateRangeWithMinMaxValue()
Assert.IsNotNull(sl.ChildList);
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
}

[TestMethod]
public void TestLongRangeWithMaxValue()
{
long max = int.MaxValue * 10L;
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();

filler.Setup().OnType<long>().Use(new LongRange(max));
var sl = filler.Create();

Assert.IsNotNull(sl);
Assert.IsNotNull(sl.ChildList);
Assert.IsTrue(sl.ChildList.All(x => x < max));
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
}

[TestMethod]
public void TestLongRangeWithMinMaxValue()
{
long min = int.MinValue * 10L;
long max = int.MaxValue * 10L;
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();

filler.Setup().OnType<long>().Use(new LongRange(min, max));
var sl = filler.Create();

Assert.IsNotNull(sl);
Assert.IsNotNull(sl.ChildList);
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
}

[TestMethod]
public void TestLongRangeWithMinMaxValueLowSmallRange()
{
long min = long.MinValue;
long max = long.MinValue + 10;
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();

filler.Setup().OnType<long>().Use(new LongRange(min, max));
var sl = filler.Create();

Assert.IsNotNull(sl);
Assert.IsNotNull(sl.ChildList);
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
}

[TestMethod]
public void TestLongRangeWithMinMaxValueHighSmallRange()
{
long min = long.MaxValue - 10;
long max = long.MaxValue;
Filler<SimpleList<long>> filler = new Filler<SimpleList<long>>();

filler.Setup().OnType<long>().Use(new LongRange(min, max));
var sl = filler.Create();

Assert.IsNotNull(sl);
Assert.IsNotNull(sl.ChildList);
Assert.IsTrue(sl.ChildList.All(x => x >= min && x <= max));
Assert.IsFalse(sl.ChildList.All(x => x == sl.ChildList[0]));
}

}
}
Loading