Skip to content

ObjectFiller moved to .NET Core #55

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 8 commits into from
Dec 15, 2015
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
80 changes: 40 additions & 40 deletions ObjectFiller.Test/AddressFillingTest.cs
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
using ObjectFiller.Test.TestPoco.Person;
using Tynamix.ObjectFiller;

namespace ObjectFiller.Test
{
using System.Linq;

[TestClass]

public class AddressFillingTest
{
[TestMethod]
[Fact]
public void FillAllAddressProperties()
{
Filler<Address> addressFiller = new Filler<Address>();
Address a = addressFiller.Create();

Assert.IsNotNull(a.City);
Assert.IsNotNull(a.Country);
Assert.AreNotEqual(0, a.HouseNumber);
Assert.IsNotNull(a.PostalCode);
Assert.IsNotNull(a.Street);
Assert.NotNull(a.City);
Assert.NotNull(a.Country);
Assert.NotEqual(0, a.HouseNumber);
Assert.NotNull(a.PostalCode);
Assert.NotNull(a.Street);
}

[TestMethod]
[Fact]
public void IgnoreCountry()
{
Filler<Address> addressFiller = new Filler<Address>();
addressFiller.Setup()
.OnProperty(x => x.Country).IgnoreIt();
Address a = addressFiller.Create();

Assert.IsNotNull(a.City);
Assert.IsNull(a.Country);
Assert.AreNotEqual(0, a.HouseNumber);
Assert.IsNotNull(a.PostalCode);
Assert.IsNotNull(a.Street);
Assert.NotNull(a.City);
Assert.Null(a.Country);
Assert.NotEqual(0, a.HouseNumber);
Assert.NotNull(a.PostalCode);
Assert.NotNull(a.Street);
}

[TestMethod]
[Fact]
public void IgnoreCountryAndCity()
{
Filler<Address> addressFiller = new Filler<Address>();
addressFiller.Setup()
.OnProperty(x => x.Country, x => x.City).IgnoreIt();
Address a = addressFiller.Create();

Assert.IsNull(a.City);
Assert.IsNull(a.Country);
Assert.AreNotEqual(0, a.HouseNumber);
Assert.IsNotNull(a.PostalCode);
Assert.IsNotNull(a.Street);
Assert.Null(a.City);
Assert.Null(a.Country);
Assert.NotEqual(0, a.HouseNumber);
Assert.NotNull(a.PostalCode);
Assert.NotNull(a.Street);
}

[TestMethod]
[Fact]
public void SetupCityPropertyWithConstantValue()
{
Filler<Address> addressFiller = new Filler<Address>();
addressFiller.Setup()
.OnProperty(ad => ad.City).Use(() => "City");
Address a = addressFiller.Create();

Assert.AreEqual("City", a.City);
Assert.IsNotNull(a.Country);
Assert.AreNotEqual(0, a.HouseNumber);
Assert.IsNotNull(a.PostalCode);
Assert.IsNotNull(a.Street);
Assert.Equal("City", a.City);
Assert.NotNull(a.Country);
Assert.NotEqual(0, a.HouseNumber);
Assert.NotNull(a.PostalCode);
Assert.NotNull(a.Street);
}

[TestMethod]
[Fact]
public void SetupCityAndCountryPropertyWithConstantValue()
{
Filler<Address> addressFiller = new Filler<Address>();
addressFiller.Setup()
.OnProperty(ad => ad.City, ad => ad.Country).Use(() => "CityCountry");
Address a = addressFiller.Create();

Assert.AreEqual("CityCountry", a.City);
Assert.IsNotNull(a.Country);
Assert.AreNotEqual(0, a.HouseNumber);
Assert.IsNotNull(a.PostalCode);
Assert.IsNotNull(a.Street);
Assert.Equal("CityCountry", a.City);
Assert.NotNull(a.Country);
Assert.NotEqual(0, a.HouseNumber);
Assert.NotNull(a.PostalCode);
Assert.NotNull(a.Street);
}

[TestMethod]
[Fact]
public void SetupTheAdressWithStaticValues()
{
Filler<Address> addressFiller = new Filler<Address>();
Expand All @@ -93,13 +93,13 @@ public void SetupTheAdressWithStaticValues()
.OnProperty(x => x.PostalCode).Use(() => "0011100");

var address = addressFiller.Create();
Assert.AreEqual("Dresden", address.City);
Assert.AreEqual("Germany", address.Country);
Assert.AreEqual("0011100", address.PostalCode);
Assert.AreEqual(10, address.HouseNumber);
Assert.Equal("Dresden", address.City);
Assert.Equal("Germany", address.Country);
Assert.Equal("0011100", address.PostalCode);
Assert.Equal(10, address.HouseNumber);
}

[TestMethod]
[Fact]
public void RandomListPluginShallReturnDifferentValues()
{
Filler<Address> addressFiller = new Filler<Address>();
Expand All @@ -108,15 +108,15 @@ public void RandomListPluginShallReturnDifferentValues()

var addresses = addressFiller.Create(1000);

Assert.IsTrue(addresses.Any(x => x.City == "Test2"));
Assert.True(addresses.Any(x => x.City == "Test2"));

addressFiller = new Filler<Address>();

addressFiller.Setup().OnProperty(x => x.City).Use(new RandomListItem<string>("Test1"));

addresses = addressFiller.Create(1000);

Assert.IsTrue(addresses.All(x => x.City == "Test1"));
Assert.True(addresses.All(x => x.City == "Test1"));

}

Expand Down
8 changes: 4 additions & 4 deletions ObjectFiller.Test/CityNamesPluginTest.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
namespace ObjectFiller.Test
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;

using Tynamix.ObjectFiller;

[TestClass]

public class CityNamesPluginTest
{
[TestMethod]
[Fact]
public void RandomNameIsReturned()
{
var sut = new CityName();
var value = sut.GetValue();

Assert.IsFalse(string.IsNullOrEmpty(value));
Assert.False(string.IsNullOrEmpty(value));
}
}
}
13 changes: 6 additions & 7 deletions ObjectFiller.Test/CopyConstructorTest.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
using Tynamix.ObjectFiller;

namespace ObjectFiller.Test
{
[TestClass]

public class CopyConstructorTest
{

[TestMethod]
[Fact]
public void WhenClassWithCopyConstructorIsCreatedNoExceptionShallBeThrown()
{
var f = new Filler<ClassWithCopyConstructorAndNormalConstructor>();
var cc = f.Create();

Assert.IsNotNull(cc);
Assert.NotNull(cc);
}

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
[Fact]
public void WhenClassWithJustCopyConstructorIsCreatedAExceptionShallBeThrown()
{
var f = new Filler<ClassWithCopyConstructor>();
var cc = f.Create();
Assert.Throws<InvalidOperationException>(() => f.Create());

}
}
Expand Down
8 changes: 4 additions & 4 deletions ObjectFiller.Test/CountryNamesPlugin.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
namespace ObjectFiller.Test
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;

using Tynamix.ObjectFiller;

[TestClass]

public class CountryNamesPlugin
{
[TestMethod]
[Fact]
public void RandomNameIsReturned()
{
var sut = new CountryName();
var value = sut.GetValue();

Assert.IsFalse(string.IsNullOrEmpty(value));
Assert.False(string.IsNullOrEmpty(value));
}
}
}
17 changes: 8 additions & 9 deletions ObjectFiller.Test/CreateInstanceTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
using Tynamix.ObjectFiller;

namespace ObjectFiller.Test
Expand Down Expand Up @@ -50,11 +49,11 @@ public ParentOfParent()
}


[TestClass]

public class CreateInstanceTest
{

[TestMethod]
[Fact]
public void TestCreateInstanceOfChildOne()
{
Filler<ParentOfParent> p = new Filler<ParentOfParent>();
Expand All @@ -65,12 +64,12 @@ public void TestCreateInstanceOfChildOne()

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.NotNull(pop);
Assert.NotNull(pop.Parents);
Assert.True(pop.Parents.All(x => x is ChildOne));
Assert.False(pop.Parents.Any(x => x is ChildTwo));

Assert.IsTrue(pop.Parents.Cast<ChildOne>().All(x => x.Name == "TEST"));
Assert.True(pop.Parents.Cast<ChildOne>().All(x => x.Name == "TEST"));


}
Expand Down
29 changes: 21 additions & 8 deletions ObjectFiller.Test/DateTimeRangeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System;
using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;

using Tynamix.ObjectFiller;

Expand All @@ -12,10 +12,10 @@ public class DateRangeTestClass
public DateTime Date { get; set; }
}

[TestClass]

public class DateTimeRangeTest
{
[TestMethod]
[Fact]
public void WhenGettingDatesBetweenNowAnd31DaysAgo()
{
Filler<DateRangeTestClass> filler = new Filler<DateRangeTestClass>();
Expand All @@ -25,10 +25,10 @@ public void WhenGettingDatesBetweenNowAnd31DaysAgo()

var d = filler.Create(1000);

Assert.IsTrue(d.All(x => x.Date < DateTime.Now && x.Date > DateTime.Now.AddDays(-31)));
Assert.True(d.All(x => x.Date < DateTime.Now && x.Date > DateTime.Now.AddDays(-31)));
}

[TestMethod]
[Fact]
public void WhenStartDateIsBiggerThenEndDateTheDatesShouldBeSwitched()
{
Filler<DateRangeTestClass> filler = new Filler<DateRangeTestClass>();
Expand All @@ -38,10 +38,10 @@ public void WhenStartDateIsBiggerThenEndDateTheDatesShouldBeSwitched()

var d = filler.Create(1000);

Assert.IsTrue(d.All(x => x.Date < DateTime.Now && x.Date > DateTime.Now.AddDays(-31)));
Assert.True(d.All(x => x.Date < DateTime.Now && x.Date > DateTime.Now.AddDays(-31)));
}

[TestMethod]
[Fact]
public void WhenStartDateAndEndDateIsSetItShouldFindOnlyDatesInBetweenThisTwoDates()
{
var startDate = new DateTime(2000, 11, 10);
Expand All @@ -53,7 +53,20 @@ public void WhenStartDateAndEndDateIsSetItShouldFindOnlyDatesInBetweenThisTwoDat

var d = filler.Create(1000);
d.ToList().ForEach(x => Console.WriteLine(x.Date));
Assert.IsTrue(d.All(x => x.Date < endDate && x.Date > startDate));
Assert.True(d.All(x => x.Date < endDate && x.Date > startDate));
}

[Fact]
public void WhenConstructorWithDateTimeNowWillBeCalledNoExceptionShouldBeThrown()
{
Filler<DateRangeTestClass> filler = new Filler<DateRangeTestClass>();

filler.Setup().OnProperty(x => x.Date).Use(new DateTimeRange(DateTime.Now));

var dateTime = filler.Create();

Assert.True(dateTime.Date > DateTime.MinValue);
Assert.True(dateTime.Date < DateTime.MaxValue);
}
}
}
14 changes: 7 additions & 7 deletions ObjectFiller.Test/DefaultDatatypeMappingsTest.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
using System;
using System.Diagnostics;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
using Tynamix.ObjectFiller;

namespace ObjectFiller.Test
{
[TestClass]

public class DefaultDatatypeMappingsTest
{
[TestMethod]
[Fact]
public void Ensure_that_double_does_not_return_infinity()
{
var filler = new Filler<MyClass>();
var myClass = filler.Create();
Assert.IsFalse(double.IsInfinity(myClass._double));
Assert.False(double.IsInfinity(myClass._double));
}

[TestMethod]
[Fact]
public void Ensure_that_each_primitive_datatype_is_mapped_by_default()
{
var filler = new Filler<MyClass>();
var myClasses = filler.Create(100).ToArray();
foreach (var myClass in myClasses)
{
Assert.AreNotEqual(default(Guid), myClass._Guid);
Assert.AreNotEqual(default(decimal), myClass._Decimal);
Assert.NotEqual(default(Guid), myClass._Guid);
Assert.NotEqual(default(decimal), myClass._Decimal);
}
}

Expand Down
Loading