From 26a35272c8fc197c9ee59c67e22a650003233b89 Mon Sep 17 00:00:00 2001 From: Alex Brown Date: Mon, 16 Jul 2018 18:12:23 +0100 Subject: [PATCH 1/3] convert csproj to vs2017 format --- .../Amido.NAuto.IntegrationTests.csproj | 94 ++---------- .../Amido.NAuto.UnitTests.csproj | 125 ++-------------- Amido.NAuto/Amido.NAuto.csproj | 140 ++---------------- 3 files changed, 42 insertions(+), 317 deletions(-) diff --git a/Amido.NAuto.IntegrationTests/Amido.NAuto.IntegrationTests.csproj b/Amido.NAuto.IntegrationTests/Amido.NAuto.IntegrationTests.csproj index 4cdf81d..2930289 100644 --- a/Amido.NAuto.IntegrationTests/Amido.NAuto.IntegrationTests.csproj +++ b/Amido.NAuto.IntegrationTests/Amido.NAuto.IntegrationTests.csproj @@ -1,87 +1,23 @@ - - - + - Debug - AnyCPU - {4A052FBA-43C7-408F-AFEE-701B03F4CC98} - Library - Properties - Amido.NAuto.IntegrationTests - Amido.NAuto.IntegrationTests - v4.0 - 512 - ..\ - true - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - true + false - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + + + net40 + Amido.NAuto.IntegrationTests + Amido.NAuto.IntegrationTests - - - ..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll - True - - - ..\packages\Should.1.1.20\lib\Should.dll - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - {29062f9c-5a4b-4a6d-a71d-42de6d5a8d9d} - Amido.NAuto - + - - - + - - - + \ No newline at end of file diff --git a/Amido.NAuto.Tests/Amido.NAuto.UnitTests.csproj b/Amido.NAuto.Tests/Amido.NAuto.UnitTests.csproj index 536b0f9..f58f51e 100644 --- a/Amido.NAuto.Tests/Amido.NAuto.UnitTests.csproj +++ b/Amido.NAuto.Tests/Amido.NAuto.UnitTests.csproj @@ -1,118 +1,23 @@ - - - + - Debug - AnyCPU - {4BC166B5-775A-48E6-9D9D-949BDF8840BF} - Library - Properties - Amido.NAuto.UnitTests - Amido.NAuto.UnitTests - v4.0 - 512 - ..\ - true - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - true + false - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + + + net40 + Amido.NAuto.UnitTests + Amido.NAuto.UnitTests - - - ..\packages\Moq.4.1.1311.0615\lib\net40\Moq.dll - - - ..\packages\NUnit.3.8.1\lib\net40\nunit.framework.dll - True - - - ..\packages\Should.1.1.20\lib\Should.dll - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {29062f9c-5a4b-4a6d-a71d-42de6d5a8d9d} - Amido.NAuto - + - + - - - + \ No newline at end of file diff --git a/Amido.NAuto/Amido.NAuto.csproj b/Amido.NAuto/Amido.NAuto.csproj index bbd1030..125c3d5 100644 --- a/Amido.NAuto/Amido.NAuto.csproj +++ b/Amido.NAuto/Amido.NAuto.csproj @@ -1,133 +1,17 @@ - - - + - Debug - AnyCPU - {29062F9C-5A4B-4A6D-A71D-42DE6D5A8D9D} - Library - Properties - Amido.NAuto - Amido.NAuto - v4.0 - 512 - ..\ - true - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - true + false - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + + + net40 + Amido.NAuto + Amido.NAuto - - - ..\packages\Newtonsoft.Json.5.0.8\lib\net40\Newtonsoft.Json.dll - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Settings.StyleCop - - - - - - - \ No newline at end of file + + From 6fc172209e72e0210dd3659612fb91eba0d2b1b7 Mon Sep 17 00:00:00 2001 From: Alex Brown Date: Tue, 17 Jul 2018 16:17:53 +0100 Subject: [PATCH 2/3] Multi target support: net40 & netstandard1.3 Unit tests updated to run both net 4.0 and netcore 1.0 Swapped Should for Shouldly (supports netstandard) .MultiTargeting namespace houses 2 helpers, to enable reflection support, without being intrusive to original code --- .../Amido.NAuto.IntegrationTests.csproj | 19 ++- .../AutoBuilderTests.cs | 101 ++++++++-------- Amido.NAuto.IntegrationTests/BuilderTests.cs | 4 +- .../GetRandomIntegerTests.cs | 8 +- .../GetRandomPropertyTypeTests.cs | 2 +- .../GetRandomStringTests.cs | 66 +++++----- .../RandomListGeneratorTests.cs | 36 +++--- .../Amido.NAuto.UnitTests.csproj | 15 ++- .../BuildConstructorParametersServiceTests.cs | 4 +- .../DataAnnotationConventionMapperTests.cs | 6 +- .../Services/PopulateArrayServiceTests.cs | 8 +- .../Services/PopulateBoolServiceTests.cs | 8 +- .../Services/PopulateByteServiceTests.cs | 6 +- .../Services/PopulateCharServiceTests.cs | 8 +- .../PopulateComplexObjectServiceTests.cs | 6 +- .../Services/PopulateDateTimeServiceTests.cs | 8 +- .../Services/PopulateDecimalServiceTests.cs | 6 +- .../PopulateDictionaryServiceTests.cs | 12 +- .../Services/PopulateDoubleServiceTests.cs | 9 +- .../Services/PopulateEnumServiceTests.cs | 8 +- .../Services/PopulateGuidServiceTests.cs | 6 +- .../Services/PopulateIntServiceTests.cs | 6 +- .../Services/PopulateListServiceTests.cs | 30 ++--- .../Services/PopulateLongServiceTests.cs | 12 +- .../PopulateNullableBoolServiceTests.cs | 8 +- .../PopulateNullableByteServiceTests.cs | 11 +- .../PopulateNullableCharServiceTests.cs | 8 +- .../PopulateNullableDateTimeServiceTests.cs | 8 +- .../PopulateNullableDecimalServiceTests.cs | 12 +- .../PopulateNullableDoubleServiceTests.cs | 10 +- .../PopulateNullableIntServiceTests.cs | 13 +- .../PopulateNullableLongServiceTests.cs | 8 +- .../Services/PopulateShortServiceTests.cs | 6 +- .../Services/PopulateStringServiceTests.cs | 6 +- .../Services/PopulateUriServiceTests.cs | 4 +- .../PropertyPopulationServiceTests.cs | 4 +- .../PropertyPopulationServiceTests.cs.orig | 4 +- .../Compare/ModelPropertyComparerTests.cs | 2 +- .../Nject/NAutoContainerTests.cs | 18 +-- Amido.NAuto/Amido.NAuto.csproj | 12 +- Amido.NAuto/Amido.NAuto.nuspec | 8 +- Amido.NAuto/Builders/AutoBuilder.cs | 88 +++++++------- .../Services/PopulateComplexObjectService.cs | 6 +- .../Services/PopulateDictionaryService.cs | 4 +- .../Builders/Services/PopulateListService.cs | 4 +- .../Services/PropertyPopulationService.cs | 17 ++- Amido.NAuto/Compare/ModelPropertyComparer.cs | 5 +- .../Multitargeting/ReflectionHelper.cs | 114 ++++++++++++++++++ Amido.NAuto/Multitargeting/StringHelper.cs | 28 +++++ Amido.NAuto/Nject/NAutoContainer.cs | 1 + .../Randomizers/RandomStringGenerator.cs | 18 +-- 51 files changed, 506 insertions(+), 315 deletions(-) create mode 100644 Amido.NAuto/Multitargeting/ReflectionHelper.cs create mode 100644 Amido.NAuto/Multitargeting/StringHelper.cs diff --git a/Amido.NAuto.IntegrationTests/Amido.NAuto.IntegrationTests.csproj b/Amido.NAuto.IntegrationTests/Amido.NAuto.IntegrationTests.csproj index 2930289..2ac9d6f 100644 --- a/Amido.NAuto.IntegrationTests/Amido.NAuto.IntegrationTests.csproj +++ b/Amido.NAuto.IntegrationTests/Amido.NAuto.IntegrationTests.csproj @@ -4,20 +4,33 @@ - net40 + net40;netcoreapp1.0 Amido.NAuto.IntegrationTests Amido.NAuto.IntegrationTests + + + + + - - + + + + + + + + + + \ No newline at end of file diff --git a/Amido.NAuto.IntegrationTests/AutoBuilderTests.cs b/Amido.NAuto.IntegrationTests/AutoBuilderTests.cs index 99b5bb3..692c469 100644 --- a/Amido.NAuto.IntegrationTests/AutoBuilderTests.cs +++ b/Amido.NAuto.IntegrationTests/AutoBuilderTests.cs @@ -4,7 +4,7 @@ using Amido.NAuto.IntegrationTests.Helpers; using Amido.NAuto.Randomizers; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.IntegrationTests { @@ -24,7 +24,7 @@ public void Should_Create_Empty_Instance_Of_Model() .Build(); testModel.ShouldNotBeNull(); - testModel.Email.ShouldEqual(Email); + testModel.Email.ShouldBe(Email); } [Test] @@ -62,7 +62,7 @@ public void Should_Persist_Json_Representation() public void Should_Use_Data_Annotation_Email_Type_As_Convention() { var testModel = NAuto.AutoBuild() - .ClearConventions() + .ClearConventions() .Construct() .Build(); @@ -106,8 +106,9 @@ public void Should_Use_Nullable_Int_Range_Data_Annotation_As_Convention() .Build(); // Assert - testModel.RangeNullableIntTest.ShouldBeGreaterThanOrEqualTo(1); - testModel.RangeNullableIntTest.ShouldBeLessThanOrEqualTo(10); + Assert.IsTrue(testModel.RangeNullableIntTest.HasValue); + testModel.RangeNullableIntTest.Value.ShouldBeGreaterThanOrEqualTo(1); + testModel.RangeNullableIntTest.Value.ShouldBeLessThanOrEqualTo(10); } [Test] @@ -119,8 +120,9 @@ public void Should_Use_Nullable_Double_Range_Data_Annotation_As_Convention() .Build(); // Assert - testModel.RangeNullableDoubleTest.ShouldBeGreaterThanOrEqualTo(1); - testModel.RangeNullableDoubleTest.ShouldBeLessThanOrEqualTo(10); + Assert.IsTrue(testModel.RangeNullableDoubleTest.HasValue); + testModel.RangeNullableDoubleTest.Value.ShouldBeGreaterThanOrEqualTo(1); + testModel.RangeNullableDoubleTest.Value.ShouldBeLessThanOrEqualTo(10); } [Test] @@ -128,7 +130,7 @@ public void Should_Construct_List_Based_Top_Level_Models_With_Parameters() { // Arrange var testListParameter = new List(); - testListParameter.Add(new TestModel{FirstName = "Sean"}); + testListParameter.Add(new TestModel { FirstName = "Sean" }); // Act var testList = NAuto.AutoBuild>() .Construct(testListParameter) @@ -175,16 +177,18 @@ public void Should_Return_New_Model_Automatically_Populated() testModel.FirstName.ShouldNotBeEmpty(); testModel.LastName.ShouldNotBeEmpty(); testModel.Byte.ShouldBeGreaterThan((byte)0); - testModel.NullableByte.ShouldBeGreaterThan((byte)0); - testModel.Bytes.Length.ShouldEqual(configuration.DefaultCollectionItemCount); - testModel.NullableBytes.Length.ShouldEqual(configuration.DefaultCollectionItemCount); - testModel.FavouriteInteger.ShouldNotEqual(default(int)); - testModel.FavouriteDouble.ShouldNotEqual(default(double)); - testModel.FavouriteDateTime.ShouldNotEqual(default(DateTime)); - testModel.SubTestModel.SubDateTime.ShouldNotEqual(default(DateTime)); - testModel.SubTestModel.SubDouble.ShouldNotEqual(default(double)); - testModel.SubTestModel.SubInteger.ShouldNotEqual(default(int)); + Assert.IsTrue(testModel.NullableByte.HasValue); + testModel.NullableByte.Value.ShouldBeGreaterThan((byte)0); + testModel.Bytes.Length.ShouldBe(configuration.DefaultCollectionItemCount); + testModel.NullableBytes.Length.ShouldBe(configuration.DefaultCollectionItemCount); + testModel.FavouriteInteger.ShouldNotBe(default(int)); + testModel.FavouriteDouble.ShouldNotBe(default(double)); + testModel.FavouriteDateTime.ShouldNotBe(default(DateTime)); + testModel.SubTestModel.SubDateTime.ShouldNotBe(default(DateTime)); + testModel.SubTestModel.SubDouble.ShouldNotBe(default(double)); + testModel.SubTestModel.SubInteger.ShouldNotBe(default(int)); testModel.SubTestModel.SubString.ShouldNotBeEmpty(); + Assert.IsTrue(testModel.SubTestModel.SubBool.HasValue); testModel.SubTestModel.SubBool.Value.ShouldBeTrue(); } @@ -200,16 +204,17 @@ public void Should_Return_New_Model_Automatically_Populated_With_Override() .Build(); // Assert - testModel.SubTestModel.SubString.ShouldEqual(overridden); + testModel.SubTestModel.SubString.ShouldBe(overridden); testModel.FirstName.ShouldNotBeEmpty(); testModel.LastName.ShouldNotBeEmpty(); - testModel.FavouriteInteger.ShouldNotEqual(default(int)); - testModel.FavouriteDouble.ShouldNotEqual(default(double)); - testModel.FavouriteDateTime.ShouldNotEqual(default(DateTime)); - testModel.SubTestModel.SubDateTime.ShouldNotEqual(default(DateTime)); - testModel.SubTestModel.SubDouble.ShouldNotEqual(default(double)); - testModel.SubTestModel.SubInteger.ShouldNotEqual(default(int)); + testModel.FavouriteInteger.ShouldNotBe(default(int)); + testModel.FavouriteDouble.ShouldNotBe(default(double)); + testModel.FavouriteDateTime.ShouldNotBe(default(DateTime)); + testModel.SubTestModel.SubDateTime.ShouldNotBe(default(DateTime)); + testModel.SubTestModel.SubDouble.ShouldNotBe(default(double)); + testModel.SubTestModel.SubInteger.ShouldNotBe(default(int)); + Assert.IsTrue(testModel.SubTestModel.SubBool.HasValue); testModel.SubTestModel.SubBool.Value.ShouldBeTrue(); } @@ -223,7 +228,7 @@ public void Should_Return_Model_With_Updated_Random_Settings_For_Top_Level_Prope .Build(); // Assert - testModel.FirstName.Length.ShouldEqual(9); + testModel.FirstName.Length.ShouldBe(9); } [Test] @@ -236,7 +241,7 @@ public void Should_Return_Model_With_Updated_Random_Settings_For_2_Levels_Deep_P .Build(); // Assert - testModel.SubTestModel.SubString.Length.ShouldEqual(7); + testModel.SubTestModel.SubString.Length.ShouldBe(7); } [Test] @@ -250,8 +255,8 @@ public void Should_Return_Model_With_Updated_Random_Settings_For_3_Levels_Deep_P .Build(); // Assert - testModel.SubTestModel.SubSubTestModel.SubSubString.Length.ShouldEqual(5); - testModel.SubTestModel.SubString.Length.ShouldEqual(12); + testModel.SubTestModel.SubSubTestModel.SubSubString.Length.ShouldBe(5); + testModel.SubTestModel.SubString.Length.ShouldBe(12); } @@ -279,8 +284,9 @@ public void Should_Return_Model_With_Updated_Random_Settings_For_2nd_Level_Integ .Build(); // Assert - testModel.SubTestModel.SubInteger.ShouldBeGreaterThanOrEqualTo(100); - testModel.SubTestModel.SubInteger.ShouldBeLessThanOrEqualTo(103); + Assert.IsTrue(testModel.SubTestModel.SubInteger.HasValue); + testModel.SubTestModel.SubInteger.Value.ShouldBeGreaterThanOrEqualTo(100); + testModel.SubTestModel.SubInteger.Value.ShouldBeLessThanOrEqualTo(103); } [Test] @@ -321,8 +327,9 @@ public void Should_Return_Model_With_Updated_Random_Settings_For_2nd_Level_Doubl .Build(); // Assert - testModel.SubTestModel.SubDouble.ShouldBeGreaterThanOrEqualTo(100); - testModel.SubTestModel.SubDouble.ShouldBeLessThanOrEqualTo(103); + Assert.IsTrue(testModel.SubTestModel.SubDouble.HasValue); + testModel.SubTestModel.SubDouble.Value.ShouldBeGreaterThanOrEqualTo(100); + testModel.SubTestModel.SubDouble.Value.ShouldBeLessThanOrEqualTo(103); } [Test] @@ -345,7 +352,7 @@ public void Should_Override_Properties_Data_Generation() // Arrange const int minLength = 5; const int maxLength = 50; - var config = new AutoBuilderConfiguration(stringMinLength:minLength, stringMaxLength:maxLength); + var config = new AutoBuilderConfiguration(stringMinLength: minLength, stringMaxLength: maxLength); // Act var testModel = NAuto.AutoBuild(config) @@ -373,7 +380,7 @@ public void Should_Override_Property_With_Random_Email() testModel.SubTestModel.SubEmail.ShouldContain("@"); testModel.SubTestModel.SubSubTestModel.SubSubEmail.ShouldContain("@"); } - + [Test] public void Should_Not_Exceed_Max_Depth_Default() { @@ -390,7 +397,7 @@ public void Should_Not_Exceed_Max_Depth_Default() public void Should_Not_Exceed_Max_Depth_Default_Of_Override_Depth_Of_4() { // Act - var testModel = NAuto.AutoBuild(new AutoBuilderConfiguration(maxDepth:4)) + var testModel = NAuto.AutoBuild(new AutoBuilderConfiguration(maxDepth: 4)) .Construct() .Build(); @@ -407,7 +414,7 @@ public void Should_Add_Simple_Item_ToArray() .Build(); // Assert - testModel.SubTestModel.SimpleArray.Length.ShouldEqual(configuration.DefaultCollectionItemCount); + testModel.SubTestModel.SimpleArray.Length.ShouldBe(configuration.DefaultCollectionItemCount); } [Test] @@ -419,7 +426,7 @@ public void Should_Add_Complex_Item_ToArray() .Build(); // Assert - testModel.FavouriteComplexArray.Length.ShouldEqual(configuration.DefaultCollectionItemCount); + testModel.FavouriteComplexArray.Length.ShouldBe(configuration.DefaultCollectionItemCount); } [Test] @@ -440,7 +447,7 @@ public void Should_Add_Multiple_String_Collections() .Build(); // Assert - testModel.FavouriteStrings.Count.ShouldEqual(configuration.DefaultCollectionItemCount); + testModel.FavouriteStrings.Count.ShouldBe(configuration.DefaultCollectionItemCount); } [Test] @@ -471,14 +478,14 @@ public void Should_Override_Property_With_Custom_Convention() var autoTestBuilderConfiguration = new AutoBuilderConfiguration(); autoTestBuilderConfiguration.Conventions.Add(new ConventionMap(ConventionFilterType.Contains, "PetName", typeof(string), config => "Rex")); - + var conventionsTestModel = NAuto.AutoBuild(autoTestBuilderConfiguration) .Construct() .Build(); // Assert - conventionsTestModel.PetName.ShouldEqual("Rex"); - conventionsTestModel.SubConventionsModel.PetName.ShouldEqual("Rex"); + conventionsTestModel.PetName.ShouldBe("Rex"); + conventionsTestModel.SubConventionsModel.PetName.ShouldBe("Rex"); } [Test] @@ -489,7 +496,7 @@ public void Should_Construct_Using_Argument_And_Populate_PrivateSetter() .Build(); // Assert - noDefautConstructor.FirstName.ShouldEqual("Blah"); + noDefautConstructor.FirstName.ShouldBe("Blah"); } [Test] @@ -527,7 +534,7 @@ public void Should_Throw_Exception_If_Interface_Used_As_Type_Argument() .Construct() .Build()); - exception.Message.ShouldEqual("Can't instantiate interfaces"); + exception.Message.ShouldBe("Can't instantiate interfaces"); } [Test] @@ -537,7 +544,7 @@ public void Should_Throw_Exception_If_Abstract_Class_Used_As_Type_Argument() .Construct() .Build()); - exception.Message.ShouldEqual("Can't instantiate abstract classes"); + exception.Message.ShouldBe("Can't instantiate abstract classes"); } [Test] @@ -560,7 +567,7 @@ public void Should_Use_Chinese_CharacterSet() .Construct() .Build(); - testModel.ShouldNotBeNull(); + testModel.ShouldNotBeNull(); } [Test] @@ -598,10 +605,10 @@ public void Should_Follow_If_Then_Logic() .Then(x => x.LastName = "Blah") .Build(); - model.LastName.ShouldEqual("Blah"); + model.LastName.ShouldBe("Blah"); } - public interface IMyInterface{} + public interface IMyInterface { } public abstract class MyAbstractClass { diff --git a/Amido.NAuto.IntegrationTests/BuilderTests.cs b/Amido.NAuto.IntegrationTests/BuilderTests.cs index 32066e1..3e5048f 100644 --- a/Amido.NAuto.IntegrationTests/BuilderTests.cs +++ b/Amido.NAuto.IntegrationTests/BuilderTests.cs @@ -1,6 +1,6 @@ using Amido.NAuto.IntegrationTests.Helpers; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.IntegrationTests { @@ -17,7 +17,7 @@ public void Should_Return_New_Model_Populated_By_Custom_Test_Data_Builder() .Build(); // Assert - testModel.FirstName.ShouldEqual(overridden); + testModel.FirstName.ShouldBe(overridden); } } } \ No newline at end of file diff --git a/Amido.NAuto.IntegrationTests/GetRandomIntegerTests.cs b/Amido.NAuto.IntegrationTests/GetRandomIntegerTests.cs index 0d03224..d2cce59 100644 --- a/Amido.NAuto.IntegrationTests/GetRandomIntegerTests.cs +++ b/Amido.NAuto.IntegrationTests/GetRandomIntegerTests.cs @@ -1,6 +1,6 @@ using System; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.IntegrationTests { @@ -20,7 +20,7 @@ public void Should_Return_A_Random_Integer_Which_Is_Less_Than_Or_Equal_To_Max() var result2 = NAuto.GetRandomInteger(max); // Assert - result1.ShouldNotEqual(result2); + result1.ShouldNotBe(result2); result1.ShouldBeLessThanOrEqualTo(max); result2.ShouldBeLessThanOrEqualTo(max); } @@ -37,7 +37,7 @@ public void Should_Return_A_Random_Integer_Which_Is_Between_Min_And_Max() var result2 = NAuto.GetRandomInteger(min, max); // Assert - result1.ShouldNotEqual(result2); + result1.ShouldNotBe(result2); result1.ShouldBeGreaterThanOrEqualTo(min); result1.ShouldBeLessThanOrEqualTo(max); result2.ShouldBeGreaterThanOrEqualTo(min); @@ -56,7 +56,7 @@ public void Should_Return_A_Random_Double_Which_Is_Between_Min_And_Max() var result2 = NAuto.GetRandomDouble(min, max); // Assert - result1.ShouldNotEqual(result2); + result1.ShouldNotBe(result2); result1.ShouldBeGreaterThanOrEqualTo(min); result1.ShouldBeLessThanOrEqualTo(max); result2.ShouldBeGreaterThanOrEqualTo(min); diff --git a/Amido.NAuto.IntegrationTests/GetRandomPropertyTypeTests.cs b/Amido.NAuto.IntegrationTests/GetRandomPropertyTypeTests.cs index 2be2039..1f91ccd 100644 --- a/Amido.NAuto.IntegrationTests/GetRandomPropertyTypeTests.cs +++ b/Amido.NAuto.IntegrationTests/GetRandomPropertyTypeTests.cs @@ -1,6 +1,6 @@ using Amido.NAuto.Builders; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.IntegrationTests { diff --git a/Amido.NAuto.IntegrationTests/GetRandomStringTests.cs b/Amido.NAuto.IntegrationTests/GetRandomStringTests.cs index f320fb6..0da5e09 100644 --- a/Amido.NAuto.IntegrationTests/GetRandomStringTests.cs +++ b/Amido.NAuto.IntegrationTests/GetRandomStringTests.cs @@ -2,7 +2,7 @@ using System.Text.RegularExpressions; using Amido.NAuto.Randomizers; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.IntegrationTests { @@ -22,9 +22,9 @@ public void Should_Return_A_Fixed_Length_Random_String_Which_Can_Include_Any_Cha var result2 = NAuto.GetRandomString(length, CharacterSetType.Anything); // Assert - result1.Length.ShouldEqual(length); - result2.Length.ShouldEqual(length); - result1.ShouldNotEqual(result2); + result1.Length.ShouldBe(length); + result2.Length.ShouldBe(length); + result1.ShouldNotBe(result2); } [Test] @@ -41,7 +41,7 @@ public void Should_Return_A_Random_String_Between_MinLength_And_MaxLength() // Assert result1.Length.ShouldBeGreaterThanOrEqualTo(minLength); result2.Length.ShouldBeLessThanOrEqualTo(maxLength); - result1.ShouldNotEqual(result2); + result1.ShouldNotBe(result2); } [Test] @@ -57,9 +57,9 @@ public void Should_Return_A_Fixed_Length_Random_String_Which_Can_Contain_Lower_O var result2 = NAuto.GetRandomString(length, CharacterSetType.Alpha); // Assert - result1.Length.ShouldEqual(length); - result2.Length.ShouldEqual(length); - result1.ShouldNotEqual(result2); + result1.Length.ShouldBe(length); + result2.Length.ShouldBe(length); + result1.ShouldNotBe(result2); regexForFalse.IsMatch(result1).ShouldBeFalse("Should only contain lower or upper case letters " + result1); regexForFalse.IsMatch(result2).ShouldBeFalse("Should only contain lower or upper case letters " + result2); regexForTrue.IsMatch(result1).ShouldBeTrue("Should only contain lower or upper case letters " + result1); @@ -79,9 +79,9 @@ public void Should_Return_A_Fixed_Length_Random_String_Which_Can_Contain_Lower_C var result2 = NAuto.GetRandomString(length, CharacterSetType.Alpha, Spaces.Any, Casing.Lowered); // Assert - result1.Length.ShouldEqual(length); - result2.Length.ShouldEqual(length); - result1.ShouldNotEqual(result2); + result1.Length.ShouldBe(length); + result2.Length.ShouldBe(length); + result1.ShouldNotBe(result2); regexForFalse.IsMatch(result1).ShouldBeFalse("Should only contain lower case letters: " + result1); regexForFalse.IsMatch(result2).ShouldBeFalse("Should only contain lower case letters: " + result2); regexForTrue.IsMatch(result1).ShouldBeTrue("Should only contain lower case letters: " + result1); @@ -101,9 +101,9 @@ public void Should_Return_A_Fixed_Length_Random_String_Which_Can_Contain_Upper_C var result2 = NAuto.GetRandomString(length, CharacterSetType.Alpha, Spaces.Any, Casing.Uppered); // Assert - result1.Length.ShouldEqual(length); - result2.Length.ShouldEqual(length); - result1.ShouldNotEqual(result2); + result1.Length.ShouldBe(length); + result2.Length.ShouldBe(length); + result1.ShouldNotBe(result2); regexForFalse.IsMatch(result1).ShouldBeFalse("Should only contain upper case letters " + result1); regexForFalse.IsMatch(result2).ShouldBeFalse("Should only contain upper case letters " + result2); regexForTrue.IsMatch(result1).ShouldBeTrue("Should only contain upper case letters " + result1); @@ -123,9 +123,9 @@ public void Should_Return_A_Fixed_Length_Random_String_Which_Can_Contain_Numbers var result2 = NAuto.GetRandomString(length, CharacterSetType.Numeric); // Assert - result1.Length.ShouldEqual(length); - result2.Length.ShouldEqual(length); - result1.ShouldNotEqual(result2); + result1.Length.ShouldBe(length); + result2.Length.ShouldBe(length); + result1.ShouldNotBe(result2); regexForFalse.IsMatch(result1).ShouldBeFalse("Should only contain numbers " + result1); regexForFalse.IsMatch(result2).ShouldBeFalse("Should only contain numbers " + result2); regexForTrue.IsMatch(result1).ShouldBeTrue("Should only contain numbers " + result1); @@ -144,9 +144,9 @@ public void Should_Return_A_Random_String_Which_Can_Contain_Spaces() var result2 = NAuto.GetRandomString(length, CharacterSetType.AlphaNumeric, Spaces.Any, Casing.Any); // Assert - result1.Length.ShouldEqual(length); - result2.Length.ShouldEqual(length); - result1.ShouldNotEqual(result2); + result1.Length.ShouldBe(length); + result2.Length.ShouldBe(length); + result1.ShouldNotBe(result2); regexForTrue.IsMatch(result1).ShouldBeTrue("Can contain spaces " + result1); regexForTrue.IsMatch(result2).ShouldBeTrue("Can contain spaces " + result2); } @@ -162,9 +162,9 @@ public void Should_Return_A_Random_String_Which_Should_Start_With_A_Space() var result2 = NAuto.GetRandomString(length, CharacterSetType.AlphaNumeric, Spaces.Start, Casing.Any); // Assert - result1.Length.ShouldEqual(length); - result2.Length.ShouldEqual(length); - result1.ShouldNotEqual(result2); + result1.Length.ShouldBe(length); + result2.Length.ShouldBe(length); + result1.ShouldNotBe(result2); result1.ShouldStartWith(" "); result2.ShouldStartWith(" "); } @@ -180,11 +180,11 @@ public void Should_Return_A_Random_String_Which_Should_End_With_A_Space() var result2 = NAuto.GetRandomString(length, CharacterSetType.AlphaNumeric, Spaces.End, Casing.Any); // Assert - result1.Length.ShouldEqual(length); - result2.Length.ShouldEqual(length); - result1.ShouldNotEqual(result2); - result1[length - 1].ShouldEqual(' '); - result2[length - 1].ShouldEqual(' '); + result1.Length.ShouldBe(length); + result2.Length.ShouldBe(length); + result1.ShouldNotBe(result2); + result1[length - 1].ShouldBe(' '); + result2[length - 1].ShouldBe(' '); } [Test] @@ -198,13 +198,13 @@ public void Should_Return_A_Random_String_Which_Should_Start_And_End_With_A_Spac var result2 = NAuto.GetRandomString(length, CharacterSetType.AlphaNumeric, Spaces.StartAndEnd, Casing.Any); // Assert - result1.Length.ShouldEqual(length); - result2.Length.ShouldEqual(length); - result1.ShouldNotEqual(result2); + result1.Length.ShouldBe(length); + result2.Length.ShouldBe(length); + result1.ShouldNotBe(result2); result1.ShouldStartWith(" "); result2.ShouldStartWith(" "); - result1[length - 1].ShouldEqual(' '); - result2[length - 1].ShouldEqual(' '); + result1[length - 1].ShouldBe(' '); + result2[length - 1].ShouldBe(' '); } } } \ No newline at end of file diff --git a/Amido.NAuto.IntegrationTests/RandomListGeneratorTests.cs b/Amido.NAuto.IntegrationTests/RandomListGeneratorTests.cs index 5f997e7..3f70bb2 100644 --- a/Amido.NAuto.IntegrationTests/RandomListGeneratorTests.cs +++ b/Amido.NAuto.IntegrationTests/RandomListGeneratorTests.cs @@ -1,6 +1,6 @@ using Amido.NAuto.IntegrationTests.Helpers; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.IntegrationTests { @@ -16,7 +16,7 @@ public void Should_Return_Random_List_With_The_Correct_Count() var list = NAuto.GetRandomList(5); // Assert - list.Count.ShouldEqual(5); + list.Count.ShouldBe(5); } [Test] @@ -26,9 +26,9 @@ public void Should_Return_Sequenced_Random_List() var list = NAuto.GetRandomList(x => x.Id); // Assert - list.Count.ShouldEqual(2); - list[0].Id.ShouldEqual(1); - list[1].Id.ShouldEqual(2); + list.Count.ShouldBe(2); + list[0].Id.ShouldBe(1); + list[1].Id.ShouldBe(2); } [Test] @@ -38,7 +38,7 @@ public void Should_Return_Sequenced_Random_List_With_Correct_Count() var list = NAuto.GetRandomList(x => x.Id, 5); // Assert - list.Count.ShouldEqual(5); + list.Count.ShouldBe(5); } [Test] @@ -48,12 +48,12 @@ public void Should_Return_Sequenced_Random_List_Starting_From_Correct_Seed_Numbe var list = NAuto.GetRandomList(x => x.Id, 5, 10); // Assert - list.Count.ShouldEqual(5); - list[0].Id.ShouldEqual(10); - list[1].Id.ShouldEqual(11); - list[2].Id.ShouldEqual(12); - list[3].Id.ShouldEqual(13); - list[4].Id.ShouldEqual(14); + list.Count.ShouldBe(5); + list[0].Id.ShouldBe(10); + list[1].Id.ShouldBe(11); + list[2].Id.ShouldBe(12); + list[3].Id.ShouldBe(13); + list[4].Id.ShouldBe(14); } [Test] @@ -63,12 +63,12 @@ public void Should_Return_Sequenced_Random_List_Using_Specified_Increment() var list = NAuto.GetRandomList(x => x.Id, 5, 10, 2); // Assert - list.Count.ShouldEqual(5); - list[0].Id.ShouldEqual(10); - list[1].Id.ShouldEqual(12); - list[2].Id.ShouldEqual(14); - list[3].Id.ShouldEqual(16); - list[4].Id.ShouldEqual(18); + list.Count.ShouldBe(5); + list[0].Id.ShouldBe(10); + list[1].Id.ShouldBe(12); + list[2].Id.ShouldBe(14); + list[3].Id.ShouldBe(16); + list[4].Id.ShouldBe(18); } } } diff --git a/Amido.NAuto.Tests/Amido.NAuto.UnitTests.csproj b/Amido.NAuto.Tests/Amido.NAuto.UnitTests.csproj index f58f51e..e825f36 100644 --- a/Amido.NAuto.Tests/Amido.NAuto.UnitTests.csproj +++ b/Amido.NAuto.Tests/Amido.NAuto.UnitTests.csproj @@ -4,17 +4,26 @@ - net40 + net40;netcoreapp1.0 Amido.NAuto.UnitTests Amido.NAuto.UnitTests + + + + + - - + + + + + + diff --git a/Amido.NAuto.Tests/Builders/Services/BuildConstructorParametersServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/BuildConstructorParametersServiceTests.cs index 0c30848..2361b56 100644 --- a/Amido.NAuto.Tests/Builders/Services/BuildConstructorParametersServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/BuildConstructorParametersServiceTests.cs @@ -2,7 +2,7 @@ using System.Reflection; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -43,7 +43,7 @@ public void Should_Call_Populate_Function_With_Correct_Parameters() private object TestPopulateFunction(int depth, string parameterName, Type parameterType, object currentValue, PropertyInfo propertyInfo) { - depth.ShouldEqual(2); + depth.ShouldBe(2); Assert.That(parameterName == "testString" || parameterName == "testInt"); Assert.That(parameterType == typeof(string) || parameterType == typeof(int)); return null; diff --git a/Amido.NAuto.Tests/Builders/Services/DataAnnotationConventionMapperTests.cs b/Amido.NAuto.Tests/Builders/Services/DataAnnotationConventionMapperTests.cs index 96d61ff..c8c7b02 100644 --- a/Amido.NAuto.Tests/Builders/Services/DataAnnotationConventionMapperTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/DataAnnotationConventionMapperTests.cs @@ -1,8 +1,10 @@ -using Amido.NAuto.Builders; +using System.Reflection; +using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; +using Amido.NAuto.MultiTargeting; using Amido.NAuto.UnitTests.Helpers; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateArrayServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateArrayServiceTests.cs index b8fc836..93c8971 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateArrayServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateArrayServiceTests.cs @@ -4,7 +4,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -37,9 +37,9 @@ public void Should_Populate_List_With_Correct_Values() var result = populateArrayService.Populate(propertyName, type, null, depth, populate) as string[]; result.ShouldNotBeNull(); - result.Length.ShouldEqual(autoBuilderConfiguration.DefaultCollectionItemCount); - result.First().ShouldEqual(arrayValue); - result.Last().ShouldEqual(arrayValue); + result.Length.ShouldBe(autoBuilderConfiguration.DefaultCollectionItemCount); + result.First().ShouldBe(arrayValue); + result.Last().ShouldBe(arrayValue); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateBoolServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateBoolServiceTests.cs index 452ac36..a8ab289 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateBoolServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateBoolServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -32,7 +32,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateBoolService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -47,7 +47,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateBoolService.Populate(propertyName, false); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -61,7 +61,7 @@ public void Should_Return_New_Random_String_Based_On_Auto_Builder_Configuration_ var result = populateBoolService.Populate(propertyName, false); // Assert - result.ShouldEqual(autoBuilderConfiguration.DefaultBoolean); + result.ShouldBe(autoBuilderConfiguration.DefaultBoolean); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateByteServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateByteServiceTests.cs index e832177..ae3ecad 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateByteServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateByteServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -32,7 +32,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateByteService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -47,7 +47,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateByteService.Populate(propertyName, default(byte)); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateCharServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateCharServiceTests.cs index ca23f8d..dd61cc4 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateCharServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateCharServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -32,7 +32,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateCharService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -47,7 +47,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateCharService.Populate(propertyName, default(char)); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -61,7 +61,7 @@ public void Should_Return_New_Random_Char_Based_On_Auto_Builder_Configuration_Wh var result = populateCharService.Populate(propertyName, default(char)); // Assert - result.ShouldNotEqual(default(char)); + result.ShouldNotBe(default(char)); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateComplexObjectServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateComplexObjectServiceTests.cs index 67b9b9e..c5e2756 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateComplexObjectServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateComplexObjectServiceTests.cs @@ -3,7 +3,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -39,7 +39,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateComplexObjectService.Populate(propertyName, typeof(TestClass), currentValue, 1, TestBuildContructor, TestPopulateSingleProperty, TestPopulateProperties); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -54,7 +54,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateComplexObjectService.Populate(propertyName, typeof(TestClass), null, 1, TestBuildContructor, TestPopulateSingleProperty, TestPopulateProperties); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateDateTimeServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateDateTimeServiceTests.cs index 47993a8..d00bdb2 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateDateTimeServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateDateTimeServiceTests.cs @@ -2,7 +2,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -33,7 +33,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateDateTimeService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -48,7 +48,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateDateTimeService.Populate(propertyName, default(DateTime)); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -62,7 +62,7 @@ public void Should_Return_New_Random_String_Based_On_Auto_Builder_Configuration_ var result = populateDateTimeService.Populate(propertyName, default(DateTime)); // Assert - result.ShouldEqual(autoBuilderConfiguration.DefaultDateTime); + result.ShouldBe(autoBuilderConfiguration.DefaultDateTime); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateDecimalServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateDecimalServiceTests.cs index 90468aa..1136a57 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateDecimalServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateDecimalServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -32,7 +32,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateDecimalService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -47,7 +47,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateDecimalService.Populate(propertyName, 0); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateDictionaryServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateDictionaryServiceTests.cs index de62001..1d17f59 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateDictionaryServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateDictionaryServiceTests.cs @@ -4,7 +4,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -40,8 +40,8 @@ public void Should_Instantiate_And_Populate_Dictionary_With_Correct_Values() var result = populateDictionaryService.Populate(propertyName, type, null, depth, populateKey, populateValue) as Dictionary; result.ShouldNotBeNull(); - result.Count.ShouldEqual(autoBuilderConfiguration.DefaultCollectionItemCount); - result[key].ShouldEqual(value); + result.Count.ShouldBe(autoBuilderConfiguration.DefaultCollectionItemCount); + result[key].ShouldBe(value); } [Test] @@ -59,9 +59,9 @@ public void Should_Use_Passed_In_Dictionary_And_Populate_Dictionary_With_Correct var result = populateDictionaryService.Populate(propertyName, type, dictionary, depth, populateKey, populateValue) as Dictionary; result.ShouldNotBeNull(); - result.ShouldEqual(dictionary); - result.Count.ShouldEqual(autoBuilderConfiguration.DefaultCollectionItemCount); - result[key].ShouldEqual(value); + result.ShouldBe(dictionary); + result.Count.ShouldBe(autoBuilderConfiguration.DefaultCollectionItemCount); + result[key].ShouldBe(value); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateDoubleServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateDoubleServiceTests.cs index 05d0d93..4e18bd7 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateDoubleServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateDoubleServiceTests.cs @@ -1,12 +1,11 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; +using Moq; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { - using Moq; - [TestFixture] public class PopulateDoubleServiceTests { @@ -36,7 +35,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateDoubleService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -51,7 +50,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateDoubleService.Populate(propertyName, 0); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateEnumServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateEnumServiceTests.cs index 4829820..1ddf9b1 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateEnumServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateEnumServiceTests.cs @@ -2,7 +2,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -39,7 +39,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateEnumService.Populate(propertyName, typeof(TestEnum), currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -54,7 +54,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateEnumService.Populate(propertyName, typeof(TestEnum), null); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -68,7 +68,7 @@ public void Should_Return_New_Random_String_Based_On_Auto_Builder_Configuration_ var result = populateEnumService.Populate(propertyName, typeof(TestEnum), null); // Assert - result.GetType().ShouldEqual(typeof(TestEnum)); + result.GetType().ShouldBe(typeof(TestEnum)); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateGuidServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateGuidServiceTests.cs index 67e9891..073f43d 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateGuidServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateGuidServiceTests.cs @@ -2,7 +2,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -34,7 +34,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateGuidService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -48,7 +48,7 @@ public void Should_Return_New_Random_Guid_Based_If_Value_Not_Defaulted() var result = populateGuidService.Populate(propertyName, currentValue); // Assert - result.ShouldNotEqual(currentValue); + result.ShouldNotBe(currentValue); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateIntServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateIntServiceTests.cs index 05f74f4..89bc372 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateIntServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateIntServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -36,7 +36,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateIntService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -51,7 +51,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateIntService.Populate(propertyName, 0); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateListServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateListServiceTests.cs index ea3a131..ac2d0c6 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateListServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateListServiceTests.cs @@ -5,7 +5,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -38,9 +38,9 @@ public void Should_Instantiate_And_Populate_List_With_Correct_Values() var result = populateListService.Populate(propertyName, type, null, depth, populate) as List; result.ShouldNotBeNull(); - result.Count.ShouldEqual(autoBuilderConfiguration.DefaultCollectionItemCount); - result.First().ShouldEqual(listValue); - result.Last().ShouldEqual(listValue); + result.Count.ShouldBe(autoBuilderConfiguration.DefaultCollectionItemCount); + result.First().ShouldBe(listValue); + result.Last().ShouldBe(listValue); } [Test] @@ -55,9 +55,9 @@ public void Should_Instantiate_And_Populate_IEnumerable_With_Correct_Values() var result = populateListService.Populate(propertyName, type, null, depth, populate) as IEnumerable; result.ShouldNotBeNull(); - result.Count().ShouldEqual(autoBuilderConfiguration.DefaultCollectionItemCount); - result.First().ShouldEqual(listValue); - result.Last().ShouldEqual(listValue); + result.Count().ShouldBe(autoBuilderConfiguration.DefaultCollectionItemCount); + result.First().ShouldBe(listValue); + result.Last().ShouldBe(listValue); } [Test] @@ -73,10 +73,10 @@ public void Should_Use_Passed_In_List_And_Populate_List_With_Correct_Values() var result = populateListService.Populate(propertyName, type, list, depth, populate) as List; result.ShouldNotBeNull(); - result.ShouldEqual(list); - result.Count.ShouldEqual(autoBuilderConfiguration.DefaultCollectionItemCount); - result.First().ShouldEqual(listValue); - result.Last().ShouldEqual(listValue); + result.ShouldBe(list); + result.Count.ShouldBe(autoBuilderConfiguration.DefaultCollectionItemCount); + result.First().ShouldBe(listValue); + result.Last().ShouldBe(listValue); } [Test] @@ -92,10 +92,10 @@ public void Should_Use_Passed_In_IEnumerable_And_Populate_IEnumerable_With_Corre var result = populateListService.Populate(propertyName, type, list, depth, populate) as IEnumerable; result.ShouldNotBeNull(); - result.ShouldEqual(list); - result.Count().ShouldEqual(autoBuilderConfiguration.DefaultCollectionItemCount); - result.First().ShouldEqual(listValue); - result.Last().ShouldEqual(listValue); + result.ShouldBe(list); + result.Count().ShouldBe(autoBuilderConfiguration.DefaultCollectionItemCount); + result.First().ShouldBe(listValue); + result.Last().ShouldBe(listValue); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateLongServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateLongServiceTests.cs index e97dfa5..360df58 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateLongServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateLongServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -33,7 +33,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateLongService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -48,8 +48,8 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateLongService.Populate(propertyName, 0); // Assert - result.ShouldEqual(testConventionResult); - result.ShouldBeType(); + result.ShouldBe(testConventionResult); + result.ShouldBeOfType(); } [Test] @@ -63,8 +63,8 @@ public void Should_Return_New_Random_Long_Based_If_Value_Not_Defaulted() var result = populateLongService.Populate(propertyName, currentValue); // Assert - result.ShouldNotEqual(currentValue); - result.ShouldBeType(); + result.ShouldNotBe(currentValue); + result.ShouldBeOfType(); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateNullableBoolServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateNullableBoolServiceTests.cs index 2241071..beaf6eb 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateNullableBoolServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateNullableBoolServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -32,7 +32,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateNullableBoolService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -47,7 +47,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateNullableBoolService.Populate(propertyName, null); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -61,7 +61,7 @@ public void Should_Return_New_Random_String_Based_On_Auto_Builder_Configuration_ var result = populateNullableBoolService.Populate(propertyName, null); // Assert - result.ShouldEqual(autoBuilderConfiguration.DefaultBoolean); + result.ShouldBe(autoBuilderConfiguration.DefaultBoolean); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateNullableByteServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateNullableByteServiceTests.cs index 1282e1f..99e942e 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateNullableByteServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateNullableByteServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -27,12 +27,12 @@ public void Should_Return_Passed_In_Value_If_Not_Default() // Arrange const string propertyName = "testname"; byte? currentValue = 1; - + // Act var result = populateByteService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -47,7 +47,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateByteService.Populate(propertyName, default(byte?)); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -61,7 +61,8 @@ public void Should_Return_New_Random_Byte_Based_On_Auto_Builder_Configuration_Wh var result = populateByteService.Populate(propertyName, default(byte?)); // Assert - result.ShouldBeGreaterThan((byte?)0); + Assert.IsTrue(result.HasValue); + result.Value.ShouldBeGreaterThan((byte)0); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateNullableCharServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateNullableCharServiceTests.cs index 72ef284..77a5f39 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateNullableCharServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateNullableCharServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -32,7 +32,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateNullableCharService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -47,7 +47,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateNullableCharService.Populate(propertyName, default(char?)); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -61,7 +61,7 @@ public void Should_Return_New_Random_Char_Based_On_Auto_Builder_Configuration_Wh var result = populateNullableCharService.Populate(propertyName, default(char?)); // Assert - result.ShouldNotEqual(default(char?)); + result.ShouldNotBe(default(char?)); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateNullableDateTimeServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateNullableDateTimeServiceTests.cs index 3a02ebb..b638030 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateNullableDateTimeServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateNullableDateTimeServiceTests.cs @@ -2,7 +2,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -33,7 +33,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateNullableDateTimeService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -48,7 +48,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateNullableDateTimeService.Populate(propertyName, default(DateTime?)); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -62,7 +62,7 @@ public void Should_Return_New_Random_String_Based_On_Auto_Builder_Configuration_ var result = populateNullableDateTimeService.Populate(propertyName, default(DateTime?)); // Assert - result.ShouldEqual(autoBuilderConfiguration.DefaultDateTime); + result.ShouldBe(autoBuilderConfiguration.DefaultDateTime); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateNullableDecimalServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateNullableDecimalServiceTests.cs index 55c9e16..89e6b8d 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateNullableDecimalServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateNullableDecimalServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -32,7 +32,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateNullableDecimalService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -47,7 +47,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateNullableDecimalService.Populate(propertyName, null); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -61,8 +61,10 @@ public void Should_Return_New_Random_Decimal_Based_On_Auto_Builder_Configuration var result = populateNullableDecimalService.Populate(propertyName, null); // Assert - result.ShouldBeGreaterThanOrEqualTo((decimal?)autoBuilderConfiguration.DoubleMinimum); - result.ShouldBeLessThanOrEqualTo((decimal?)autoBuilderConfiguration.DoubleMaximum); + + Assert.IsTrue(result.HasValue); + result.Value.ShouldBeGreaterThanOrEqualTo((decimal)autoBuilderConfiguration.DoubleMinimum); + result.Value.ShouldBeLessThanOrEqualTo((decimal)autoBuilderConfiguration.DoubleMaximum); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateNullableDoubleServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateNullableDoubleServiceTests.cs index d9a3c96..53902bc 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateNullableDoubleServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateNullableDoubleServiceTests.cs @@ -2,7 +2,7 @@ using Amido.NAuto.Builders.Services; using Moq; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -35,7 +35,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateNullableDoubleService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -50,7 +50,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateNullableDoubleService.Populate(propertyName, null); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -64,8 +64,8 @@ public void Should_Return_New_Random_String_Based_On_Auto_Builder_Configuration_ var result = populateNullableDoubleService.Populate(propertyName, null); // Assert - result.ShouldBeGreaterThanOrEqualTo(autoBuilderConfiguration.DoubleMinimum); - result.ShouldBeLessThanOrEqualTo(autoBuilderConfiguration.DoubleMaximum); + Assert.That(result, Is.GreaterThanOrEqualTo(autoBuilderConfiguration.DoubleMinimum)); + Assert.That(result, Is.LessThanOrEqualTo(autoBuilderConfiguration.DoubleMaximum)); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateNullableIntServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateNullableIntServiceTests.cs index 52e94a5..8f2db3d 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateNullableIntServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateNullableIntServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -31,12 +31,12 @@ public void Should_Return_Passed_In_Value_If_Not_Default() // Arrange const string propertyName = "testname"; const int currentValue = 1; - + // Act var result = populateNullableIntService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -51,7 +51,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateNullableIntService.Populate(propertyName, null); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -65,8 +65,9 @@ public void Should_Return_New_Random_String_Based_On_Auto_Builder_Configuration_ var result = populateNullableIntService.Populate(propertyName, null); // Assert - result.ShouldBeGreaterThanOrEqualTo(autoBuilderConfiguration.IntMinimum); - result.ShouldBeLessThanOrEqualTo(autoBuilderConfiguration.IntMaximum); + Assert.IsTrue(result.HasValue); + result.Value.ShouldBeGreaterThanOrEqualTo(autoBuilderConfiguration.IntMinimum); + result.Value.ShouldBeLessThanOrEqualTo(autoBuilderConfiguration.IntMaximum); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateNullableLongServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateNullableLongServiceTests.cs index b1fc501..ad13d2f 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateNullableLongServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateNullableLongServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -34,7 +34,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateNullableLongService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -49,7 +49,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateNullableLongService.Populate(propertyName, null); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] @@ -63,7 +63,7 @@ public void Should_Return_New_Random_Nullable_Long_Based_If_Value_Not_Defaulted( var result = populateNullableLongService.Populate(propertyName, null); // Assert - result.ShouldNotEqual(currentValue); + result.ShouldNotBe(currentValue); } } } diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateShortServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateShortServiceTests.cs index cd89a50..676cf9f 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateShortServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateShortServiceTests.cs @@ -1,7 +1,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -32,7 +32,7 @@ public void Should_Return_Passed_In_Value_If_Not_Default() var result = populateShortService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -47,7 +47,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateShortService.Populate(propertyName, 0); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateStringServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateStringServiceTests.cs index 6eda93d..4a8ec46 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateStringServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateStringServiceTests.cs @@ -2,7 +2,7 @@ using Amido.NAuto.Builders.Services; using Moq; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -35,7 +35,7 @@ public void Should_Return_Passed_In_Value_If_Not_Null() var result = populateStringService.Populate(propertyName, currentValue); // Assert - result.ShouldEqual(currentValue); + result.ShouldBe(currentValue); } [Test] @@ -50,7 +50,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateStringService.Populate(propertyName, null); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] diff --git a/Amido.NAuto.Tests/Builders/Services/PopulateUriServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PopulateUriServiceTests.cs index 409838f..dd6a5d7 100644 --- a/Amido.NAuto.Tests/Builders/Services/PopulateUriServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PopulateUriServiceTests.cs @@ -2,7 +2,7 @@ using Amido.NAuto.Builders; using Amido.NAuto.Builders.Services; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -34,7 +34,7 @@ public void Should_Return_Convention_Result_If_Convention_Exists() var result = populateUriService.Populate(propertyName, null); // Assert - result.ShouldEqual(testConventionResult); + result.ShouldBe(testConventionResult); } [Test] diff --git a/Amido.NAuto.Tests/Builders/Services/PropertyPopulationServiceTests.cs b/Amido.NAuto.Tests/Builders/Services/PropertyPopulationServiceTests.cs index 2f5c25b..6d9ca7a 100644 --- a/Amido.NAuto.Tests/Builders/Services/PropertyPopulationServiceTests.cs +++ b/Amido.NAuto.Tests/Builders/Services/PropertyPopulationServiceTests.cs @@ -6,7 +6,7 @@ using Amido.NAuto.UnitTests.Helpers; using Moq; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -278,7 +278,7 @@ public void Should_Call_Correct_Populate_Service_When_Passed_A_String() // Assert populateStringService.VerifyAll(); - objectToPopulate.Test.ShouldEqual(resultString); + objectToPopulate.Test.ShouldBe(resultString); } [Test] diff --git a/Amido.NAuto.Tests/Builders/Services/PropertyPopulationServiceTests.cs.orig b/Amido.NAuto.Tests/Builders/Services/PropertyPopulationServiceTests.cs.orig index b092df2..8406652 100644 --- a/Amido.NAuto.Tests/Builders/Services/PropertyPopulationServiceTests.cs.orig +++ b/Amido.NAuto.Tests/Builders/Services/PropertyPopulationServiceTests.cs.orig @@ -6,7 +6,7 @@ using Amido.NAuto.Builders.Services; using Amido.NAuto.UnitTests.Helpers; using Moq; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Builders.Services { @@ -278,7 +278,7 @@ namespace Amido.NAuto.UnitTests.Builders.Services // Assert populateStringService.VerifyAll(); - objectToPopulate.Test.ShouldEqual(resultString); + objectToPopulate.Test.ShouldBe(resultString); } [Test] diff --git a/Amido.NAuto.Tests/Compare/ModelPropertyComparerTests.cs b/Amido.NAuto.Tests/Compare/ModelPropertyComparerTests.cs index 0698b5f..cf101ec 100644 --- a/Amido.NAuto.Tests/Compare/ModelPropertyComparerTests.cs +++ b/Amido.NAuto.Tests/Compare/ModelPropertyComparerTests.cs @@ -3,7 +3,7 @@ using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Compare { diff --git a/Amido.NAuto.Tests/Nject/NAutoContainerTests.cs b/Amido.NAuto.Tests/Nject/NAutoContainerTests.cs index 951285f..46562c0 100644 --- a/Amido.NAuto.Tests/Nject/NAutoContainerTests.cs +++ b/Amido.NAuto.Tests/Nject/NAutoContainerTests.cs @@ -4,7 +4,7 @@ using System.Threading.Tasks; using Amido.NAuto.Nject; using NUnit.Framework; -using Should; +using Shouldly; namespace Amido.NAuto.UnitTests.Nject { @@ -29,18 +29,18 @@ public void Should_Successfully_Add_Entry_To_Mapping_Dictionary() { nAutoContainer.Register, List>(); - NAutoContainer.Mappings.Count.ShouldEqual(1); - NAutoContainer.Mappings.First().Key.ShouldEqual(typeof (IList)); - NAutoContainer.Mappings.First().Value.ShouldEqual(typeof(List)); + NAutoContainer.Mappings.Count.ShouldBe(1); + NAutoContainer.Mappings.First().Key.ShouldBe(typeof (IList)); + NAutoContainer.Mappings.First().Value.ShouldBe(typeof(List)); } [Test] public void Should_Successfully_Add_Entry_To_Mapping_Dictionary_Across_Multiple_Threads() { Parallel.ForEach(Enumerable.Range(1, 1000), x => nAutoContainer.Register, List>()); - NAutoContainer.Mappings.Count.ShouldEqual(1); - NAutoContainer.Mappings.First().Key.ShouldEqual(typeof(IList)); - NAutoContainer.Mappings.First().Value.ShouldEqual(typeof(List)); + NAutoContainer.Mappings.Count.ShouldBe(1); + NAutoContainer.Mappings.First().Key.ShouldBe(typeof(IList)); + NAutoContainer.Mappings.First().Value.ShouldBe(typeof(List)); } } @@ -54,14 +54,14 @@ public void Should_Return_An_Implementation_Based_On_The_Passed_In_Interface() var instance = nAutoContainer.Resolve>(); instance.ShouldNotBeNull(); - instance.GetType().ShouldEqual(typeof(List)); + instance.GetType().ShouldBe(typeof(List)); } [Test] public void Should_Throw_Argument_Exception_When_Interface_Not_Registered() { var argumentException = Assert.Throws(() => nAutoContainer.Resolve>()); - argumentException.Message.ShouldEqual("Type not registered"); + argumentException.Message.ShouldBe("Type not registered"); } [Test] diff --git a/Amido.NAuto/Amido.NAuto.csproj b/Amido.NAuto/Amido.NAuto.csproj index 125c3d5..af5b415 100644 --- a/Amido.NAuto/Amido.NAuto.csproj +++ b/Amido.NAuto/Amido.NAuto.csproj @@ -4,7 +4,7 @@ - net40 + net40;netstandard1.3 Amido.NAuto Amido.NAuto @@ -14,4 +14,14 @@ + + + + + + + + + + diff --git a/Amido.NAuto/Amido.NAuto.nuspec b/Amido.NAuto/Amido.NAuto.nuspec index 328b872..6be4786 100644 --- a/Amido.NAuto/Amido.NAuto.nuspec +++ b/Amido.NAuto/Amido.NAuto.nuspec @@ -18,7 +18,13 @@ Multi Language data generation including English, Traditional Chinese, Pinyin, R Amido Development Ltd © 2013 Test Data Builder Data Helpers Auto Build Generation Unit Testing TDD BDD NUnit MSTest Multi Language - + + + + + + + \ No newline at end of file diff --git a/Amido.NAuto/Builders/AutoBuilder.cs b/Amido.NAuto/Builders/AutoBuilder.cs index cb81e18..2c22d11 100644 --- a/Amido.NAuto/Builders/AutoBuilder.cs +++ b/Amido.NAuto/Builders/AutoBuilder.cs @@ -1,11 +1,9 @@ using System; using System.Linq; using System.Linq.Expressions; -using System.Reflection; - using Amido.NAuto.Builders.Services; +using Amido.NAuto.MultiTargeting; using Amido.NAuto.Randomizers; - using Amido.NAuto.Serializers; namespace Amido.NAuto.Builders @@ -44,8 +42,8 @@ public AutoBuilder(IPropertyPopulationService propertyPopulationService, AutoBui this.propertyPopulationService = propertyPopulationService; this.configuration = configuration; - this.Actions = new List(); - this.hasInstance = false; + Actions = new List(); + hasInstance = false; } internal TModel Entity { get; set; } @@ -139,17 +137,17 @@ public IAutoBuilder Configure(Action configure /// public IAutoBuilderOverrides Construct(params object[] constructorArguments) { - if (typeof(TModel).IsInterface) + if (typeof(TModel).IsInterface()) { throw new ArgumentException("Can't instantiate interfaces"); } - if (typeof(TModel).IsAbstract) + if (typeof(TModel).IsAbstract()) { throw new ArgumentException("Can't instantiate abstract classes"); } - this.constructorParameters = constructorArguments; + constructorParameters = constructorArguments; propertyPopulationService.AddConfiguration(configuration); @@ -178,13 +176,13 @@ public IAutoBuilderOverrides Empty() public IAutoBuilderOverrides Load(string relativeFilePath) { propertyPopulationService.AddConfiguration(configuration); - var currentDirectory = Path.Combine(new Uri(Assembly.GetAssembly(typeof(AutoBuilder<>)).CodeBase).LocalPath, @"..\..\..\"); + var currentDirectory = Path.Combine(ReflectionHelper.GetAssemblyPath(typeof(AutoBuilder<>)), @"..\..\..\"); var fullPath = currentDirectory + relativeFilePath; if (File.Exists(fullPath)) { Entity = JsonSerializer.FromJsonString(File.ReadAllText(fullPath)); - this.hasInstance = true; + hasInstance = true; } else { @@ -201,7 +199,7 @@ public IAutoBuilderOverrides Load(string relativeFilePath) /// Returns this. public IAutoBuilderOverrides With(Action expression) { - this.Actions.Add(() => expression(this.Entity)); + Actions.Add(() => expression(Entity)); return this; } @@ -215,7 +213,7 @@ public IAutoBuilderOverrides With( Expression> expression, PropertyType propertyType) { - this.Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomPropertyType(propertyType), expression)); + Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomPropertyType(propertyType), expression)); return this; } @@ -229,7 +227,7 @@ public IAutoBuilderOverrides With( Expression> expression, int length) { - this.Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(length), expression)); + Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(length), expression)); return this; } @@ -245,7 +243,7 @@ public IAutoBuilderOverrides With( int length, CharacterSetType characterSetType) { - this.Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(length, characterSetType), expression)); + Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(length, characterSetType), expression)); return this; } @@ -263,7 +261,7 @@ public IAutoBuilderOverrides With( CharacterSetType characterSetType, Spaces spaces) { - this.Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(length, characterSetType, spaces), expression)); + Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(length, characterSetType, spaces), expression)); return this; } @@ -283,7 +281,7 @@ public IAutoBuilderOverrides With( Spaces spaces, Casing casing) { - this.Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(length, characterSetType, spaces, casing), expression)); + Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(length, characterSetType, spaces, casing), expression)); return this; } @@ -305,7 +303,7 @@ public IAutoBuilderOverrides With( Spaces spaces, Casing casing) { - this.Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(minLength, minLength, characterSetType, spaces, casing), expression)); + Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(minLength, minLength, characterSetType, spaces, casing), expression)); return this; } @@ -325,7 +323,7 @@ public IAutoBuilderOverrides With( CharacterSetType characterSetType, Spaces spaces) { - this.Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(minLength, minLength, characterSetType, spaces), expression)); + Actions.Add(() => SetStringPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomString(minLength, minLength, characterSetType, spaces), expression)); return this; } @@ -339,7 +337,7 @@ public IAutoBuilderOverrides With( Expression> expression, int max) { - this.Actions.Add(() => SetIntegerPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomInteger(max), expression)); + Actions.Add(() => SetIntegerPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomInteger(max), expression)); return this; } @@ -355,7 +353,7 @@ public IAutoBuilderOverrides With( int min, int max) { - this.Actions.Add(() => SetIntegerPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomInteger(min, max), expression)); + Actions.Add(() => SetIntegerPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomInteger(min, max), expression)); return this; } @@ -369,7 +367,7 @@ public IAutoBuilderOverrides With( Expression> expression, int max) { - this.Actions.Add(() => SetIntegerPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomInteger(max), expression)); + Actions.Add(() => SetIntegerPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomInteger(max), expression)); return this; } @@ -385,7 +383,7 @@ public IAutoBuilderOverrides With( int min, int max) { - this.Actions.Add(() => SetIntegerPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomInteger(min, max), expression)); + Actions.Add(() => SetIntegerPropertyUsingNewRandomizerSetting(() => NAuto.GetRandomInteger(min, max), expression)); return this; } @@ -401,7 +399,7 @@ public IAutoBuilderOverrides With( double min, double max) { - this.Actions.Add(() => SetDoublePropertyUsingNewRandomizerSetting(() => NAuto.GetRandomDouble(min, max), expression)); + Actions.Add(() => SetDoublePropertyUsingNewRandomizerSetting(() => NAuto.GetRandomDouble(min, max), expression)); return this; } @@ -417,7 +415,7 @@ public IAutoBuilderOverrides With( double min, double max) { - this.Actions.Add(() => SetDoublePropertyUsingNewRandomizerSetting(() => NAuto.GetRandomDouble(min, max), expression)); + Actions.Add(() => SetDoublePropertyUsingNewRandomizerSetting(() => NAuto.GetRandomDouble(min, max), expression)); return this; } @@ -428,7 +426,7 @@ public IAutoBuilderOverrides With( /// Returns this. public IConditionalResult If(Func expression) { - return new ConditionalResult(this, this.Entity, b => expression(this.Entity)); + return new ConditionalResult(this, Entity, b => expression(Entity)); } /// @@ -437,18 +435,18 @@ public IConditionalResult If(Func expression) /// Returns the populated model. public TModel Build() { - if (!this.hasInstance) + if (!hasInstance) { if (this.constructorParameters != null && this.constructorParameters.Length > 0) { - this.Entity = (TModel)Activator.CreateInstance(typeof(TModel), this.constructorParameters); + Entity = (TModel)Activator.CreateInstance(typeof(TModel), constructorParameters); } else { var constructors = typeof(TModel).GetConstructors(); - if (typeof(TModel).BaseType == typeof(Array)) + if (typeof(TModel).BaseType() == typeof(Array)) { - this.Entity = + Entity = (TModel)Activator.CreateInstance(typeof(TModel), configuration.DefaultCollectionItemCount); } else if (constructors.All(x => x.GetParameters().Count() != 0)) @@ -456,29 +454,29 @@ public TModel Build() var constructorParameters = propertyPopulationService.BuildConstructorParameters( constructors, 1); - this.Entity = (TModel)Activator.CreateInstance(typeof(TModel), constructorParameters); + Entity = (TModel)Activator.CreateInstance(typeof(TModel), constructorParameters); } else { - this.Entity = (TModel)Activator.CreateInstance(typeof(TModel)); + Entity = (TModel)Activator.CreateInstance(typeof(TModel)); } } - this.Entity = (TModel)propertyPopulationService.PopulateProperties(this.Entity, 1); + Entity = (TModel)propertyPopulationService.PopulateProperties(Entity, 1); } - foreach (var action in this.Actions) + foreach (var action in Actions) { action(); } - return this.Entity; + return Entity; } public TModel Persist(string relativeFilePath, bool overWrite = false) { - var json = this.ToJson(); - var currentDirectory = Path.Combine(new Uri(Assembly.GetAssembly(typeof(AutoBuilder<>)).CodeBase).LocalPath, @"..\..\..\"); + var json = ToJson(); + var currentDirectory = Path.Combine(new Uri(ReflectionHelper.GetAssemblyPath(typeof(AutoBuilder<>))).LocalPath, @"..\..\..\"); var fullPath = currentDirectory + relativeFilePath; if (!File.Exists(fullPath) || overWrite) { @@ -505,8 +503,8 @@ public TModel Persist(string relativeFilePath, bool overWrite = false) /// public string ToJson(bool useCamelCase = true, bool ignoreNulls = true, bool indentJson = true) { - this.Build(); - return JsonSerializer.ToIndentedJsonString(this.Entity, useCamelCase, ignoreNulls, indentJson); + Build(); + return JsonSerializer.ToIndentedJsonString(Entity, useCamelCase, ignoreNulls, indentJson); } private void SetStringPropertyUsingNewRandomizerSetting( @@ -514,7 +512,7 @@ private void SetStringPropertyUsingNewRandomizerSetting( Expression> expression) { var memberExpression = (MemberExpression)expression.Body; - var property = memberExpression.Member as PropertyInfo; + var property = memberExpression.Member as System.Reflection.PropertyInfo; var instanceToUpdate = GetInstance(memberExpression); if (property != null) { @@ -527,7 +525,7 @@ private void SetIntegerPropertyUsingNewRandomizerSetting( Expression> expression) { var memberExpression = (MemberExpression)expression.Body; - var property = memberExpression.Member as PropertyInfo; + var property = memberExpression.Member as System.Reflection.PropertyInfo; var instanceToUpdate = GetInstance(memberExpression); if (property != null) { @@ -540,7 +538,7 @@ private void SetIntegerPropertyUsingNewRandomizerSetting( Expression> expression) { var memberExpression = (MemberExpression)expression.Body; - var property = memberExpression.Member as PropertyInfo; + var property = memberExpression.Member as System.Reflection.PropertyInfo; var instanceToUpdate = GetInstance(memberExpression); if (property != null) { @@ -553,7 +551,7 @@ private void SetDoublePropertyUsingNewRandomizerSetting( Expression> expression) { var memberExpression = (MemberExpression)expression.Body; - var property = memberExpression.Member as PropertyInfo; + var property = memberExpression.Member as System.Reflection.PropertyInfo; var instanceToUpdate = GetInstance(memberExpression); if (property != null) { @@ -566,7 +564,7 @@ private void SetDoublePropertyUsingNewRandomizerSetting( Expression> expression) { var memberExpression = (MemberExpression)expression.Body; - var property = memberExpression.Member as PropertyInfo; + var property = memberExpression.Member as System.Reflection.PropertyInfo; var instanceToUpdate = GetInstance(memberExpression); if (property != null) { @@ -578,12 +576,12 @@ private object GetInstance(MemberExpression expression) { if (expression.Expression as MemberExpression == null) { - return this.Entity; + return Entity; } var body = GetInstance(expression.Expression as MemberExpression); - var property = (expression.Expression as MemberExpression).Member as PropertyInfo; + var property = (expression.Expression as MemberExpression).Member as System.Reflection.PropertyInfo; if (property != null) { var nextLevelInstance = property.GetValue(body, null); diff --git a/Amido.NAuto/Builders/Services/PopulateComplexObjectService.cs b/Amido.NAuto/Builders/Services/PopulateComplexObjectService.cs index 7486842..2666d05 100644 --- a/Amido.NAuto/Builders/Services/PopulateComplexObjectService.cs +++ b/Amido.NAuto/Builders/Services/PopulateComplexObjectService.cs @@ -1,5 +1,5 @@ using System; -using System.Reflection; +using Amido.NAuto.MultiTargeting; namespace Amido.NAuto.Builders.Services { @@ -17,8 +17,8 @@ public object Populate( Type propertyType, object currentValue, int depth, - Func, object[]> buildConstructorParametersFunction, - Func populate, + Func, object[]> buildConstructorParametersFunction, + Func populate, Func populateProperties) { if (currentValue != null) diff --git a/Amido.NAuto/Builders/Services/PopulateDictionaryService.cs b/Amido.NAuto/Builders/Services/PopulateDictionaryService.cs index bb20ad1..7600460 100644 --- a/Amido.NAuto/Builders/Services/PopulateDictionaryService.cs +++ b/Amido.NAuto/Builders/Services/PopulateDictionaryService.cs @@ -1,6 +1,6 @@ using System; using System.Collections; -using System.Reflection; +using Amido.NAuto.MultiTargeting; namespace Amido.NAuto.Builders.Services { @@ -13,7 +13,7 @@ public void SetAutoBuilderConfiguration(AutoBuilderConfiguration autoBuilderConf AutoBuilderConfiguration = autoBuilderConfiguration; } - public object Populate(string propertyName, Type propertyType, object currentValue, int depth, Func populateKey, Func populateValue) + public object Populate(string propertyName, Type propertyType, object currentValue, int depth, Func populateKey, Func populateValue) { if (currentValue != null && ((IDictionary)currentValue).Count > 0) { diff --git a/Amido.NAuto/Builders/Services/PopulateListService.cs b/Amido.NAuto/Builders/Services/PopulateListService.cs index 6ed4835..ac09810 100644 --- a/Amido.NAuto/Builders/Services/PopulateListService.cs +++ b/Amido.NAuto/Builders/Services/PopulateListService.cs @@ -1,7 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Reflection; +using Amido.NAuto.MultiTargeting; namespace Amido.NAuto.Builders.Services { @@ -19,7 +19,7 @@ public object Populate( Type propertyType, object currentValue, int depth, - Func populate) + Func populate) { if (currentValue != null && ((IList)currentValue).Count > 0) { diff --git a/Amido.NAuto/Builders/Services/PropertyPopulationService.cs b/Amido.NAuto/Builders/Services/PropertyPopulationService.cs index 1b0bcfb..8173833 100644 --- a/Amido.NAuto/Builders/Services/PropertyPopulationService.cs +++ b/Amido.NAuto/Builders/Services/PropertyPopulationService.cs @@ -1,8 +1,7 @@ using System; using System.Collections; -using System.Collections.Generic; using System.Linq; -using System.Reflection; +using Amido.NAuto.MultiTargeting; namespace Amido.NAuto.Builders.Services { @@ -141,7 +140,7 @@ public object PopulateProperties(object objectToPopulate, int depth) { populateDictionaryService.Populate(string.Empty, objectToPopulateType, objectToPopulate, depth - 1, Populate, Populate); } - else if (objectToPopulateType.BaseType == typeof(Array)) + else if (objectToPopulateType.BaseType() == typeof(Array)) { objectToPopulate = populateArrayService.Populate(string.Empty, objectToPopulateType, objectToPopulate, depth - 1, Populate); } @@ -155,7 +154,7 @@ public object PopulateProperties(object objectToPopulate, int depth) } else { - var properties = objectToPopulate.GetType().GetProperties(); + var properties = ReflectionHelper.GetProperties(objectToPopulate.GetType()); foreach (var propertyInfo in properties) { @@ -171,17 +170,17 @@ public object PopulateProperties(object objectToPopulate, int depth) return objectToPopulate; } - public object[] BuildConstructorParameters(ConstructorInfo[] constructors, int depth) + public object[] BuildConstructorParameters(System.Reflection.ConstructorInfo[] constructors, int depth) { return buildConstructorParametersService.Build(constructors, depth, Populate); } private static bool IsPotentialComplexType(Type propertyType) { - return propertyType.BaseType != typeof(ValueType) && !propertyType.IsPrimitive && propertyType != typeof(string) && propertyType != typeof(Uri); + return propertyType.BaseType() != typeof(ValueType) && !propertyType.IsPrimitive() && propertyType != typeof(string) && propertyType != typeof(Uri); } - private object Populate(int depth, string propertyName, Type propertyType, object value, PropertyInfo propertyInfo = null) + private object Populate(int depth, string propertyName, Type propertyType, object value, System.Reflection.PropertyInfo propertyInfo = null) { if (propertyInfo != null) { @@ -198,7 +197,7 @@ private object Populate(int depth, string propertyName, Type propertyType, objec return populateListService.Populate(propertyName, propertyType, value, depth, Populate); } - if (propertyType.BaseType == typeof(Array) && value == null) + if (propertyType.BaseType() == typeof(Array) && value == null) { return populateArrayService.Populate(propertyName, propertyType, null, depth, Populate); } @@ -319,7 +318,7 @@ private object Populate(int depth, string propertyName, Type propertyType, objec return populateNullableDecimalService.Populate(propertyName, (decimal?)value); } - if (propertyType.BaseType == typeof(Enum)) + if (propertyType.BaseType() == typeof(Enum)) { return populateEnumService.Populate(propertyName, propertyType, value); } diff --git a/Amido.NAuto/Compare/ModelPropertyComparer.cs b/Amido.NAuto/Compare/ModelPropertyComparer.cs index f062783..9e96cd9 100644 --- a/Amido.NAuto/Compare/ModelPropertyComparer.cs +++ b/Amido.NAuto/Compare/ModelPropertyComparer.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using Amido.NAuto.MultiTargeting; namespace Amido.NAuto.Compare { @@ -58,8 +59,8 @@ private static void PopulateComparisons(string path, object modelA, object model || modelAProperty.PropertyType == typeof(string) || modelAProperty.PropertyType == typeof(decimal) || modelAProperty.PropertyType == typeof(DateTime) - || modelAProperty.PropertyType.IsEnum - || modelAProperty.PropertyType.IsPrimitive) + || modelAProperty.PropertyType.IsEnum() + || modelAProperty.PropertyType.IsPrimitive()) { compareResult.ModelValueA = modelAPropertyValue; compareResult.ModelValueB = modelBPropertyValue; diff --git a/Amido.NAuto/Multitargeting/ReflectionHelper.cs b/Amido.NAuto/Multitargeting/ReflectionHelper.cs new file mode 100644 index 0000000..596adf4 --- /dev/null +++ b/Amido.NAuto/Multitargeting/ReflectionHelper.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Amido.NAuto.MultiTargeting +{ + internal static class ReflectionHelper + { + public static bool IsAbstract(this Type type) + { +#if NET40 + return type.IsAbstract; +#else + return type.GetTypeInfo().IsAbstract; +#endif + } + + public static bool IsPrimitive(this Type type) + { +#if NET40 + return type.IsPrimitive; +#else + return type.GetTypeInfo().IsPrimitive; +#endif + } + + public static bool IsEnum(this Type type) + { +#if NET40 + return type.IsPrimitive; +#else + return type.GetTypeInfo().IsAbstract; +#endif + } + + public static bool IsInterface(this Type type) + { +#if NET40 + return type.IsInterface; +#else + return type.GetTypeInfo().IsInterface; +#endif + } + + public static Type BaseType(this Type type) + { +#if NET40 + return type.BaseType; +#else + return type.GetTypeInfo().BaseType; +#endif + } + + public static ConstructorInfo[] GetConstructors(this Type type) + { +#if NET40 + return type.GetConstructors(); +#else + return type.GetTypeInfo().DeclaredConstructors.ToArray(); +#endif + } + + public static PropertyInfo GetProperty(this Type type, string name) + { +#if NET40 + return type.GetProperty(name); +#else + return type.GetTypeInfo().GetDeclaredProperty(name); +#endif + } + + public static PropertyInfo[] GetProperties(this Type type) + { +#if NET40 + return type.GetProperties(); +#else + return type.GetTypeInfo().DeclaredProperties.ToArray(); +#endif + } + + public static Type[] GetInterfaces(this Type type) + { +#if NET40 + return type.GetInterfaces(); +#else + return type.GetTypeInfo().ImplementedInterfaces.ToArray(); +#endif + } + + + + public static Type[] GetGenericArguments(this Type type) + { +#if NET40 + return type.GetGenericArguments(); +#else + return type.GetTypeInfo().IsGenericTypeDefinition + ? type.GetTypeInfo().GenericTypeParameters + : type.GetTypeInfo().GenericTypeArguments; +#endif + } + + public static string GetAssemblyPath(Type type) + { +#if NET40 + return type.Assembly.CodeBase; +#else + + return new Uri(AppContext.BaseDirectory).LocalPath; +#endif + } + } +} \ No newline at end of file diff --git a/Amido.NAuto/Multitargeting/StringHelper.cs b/Amido.NAuto/Multitargeting/StringHelper.cs new file mode 100644 index 0000000..240027f --- /dev/null +++ b/Amido.NAuto/Multitargeting/StringHelper.cs @@ -0,0 +1,28 @@ +using System; +using System.Globalization; + +namespace Amido.NAuto.MultiTargeting +{ + internal static class StringHelper + { + internal static string ToTitleCase(this string text) + { +#if NET40 + var textInfo = new CultureInfo("en-GB", false).TextInfo; + return textInfo.ToTitleCase(text.ToLower()); +#else + var tokens = text.Split(new[] { " ", "-" }, StringSplitOptions.RemoveEmptyEntries); + for (var i = 0; i < tokens.Length; i++) + { + var token = tokens[i]; + tokens[i] = token == token.ToUpper() + ? token + : token.Substring(0, 1).ToUpper() + token.Substring(1).ToLower(); + } + + return string.Join(" ", tokens); +#endif + } + + } +} diff --git a/Amido.NAuto/Nject/NAutoContainer.cs b/Amido.NAuto/Nject/NAutoContainer.cs index bcd1498..4b56270 100644 --- a/Amido.NAuto/Nject/NAutoContainer.cs +++ b/Amido.NAuto/Nject/NAutoContainer.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using Amido.NAuto.MultiTargeting; namespace Amido.NAuto.Nject { diff --git a/Amido.NAuto/Randomizers/RandomStringGenerator.cs b/Amido.NAuto/Randomizers/RandomStringGenerator.cs index 24445e0..fa8fb00 100644 --- a/Amido.NAuto/Randomizers/RandomStringGenerator.cs +++ b/Amido.NAuto/Randomizers/RandomStringGenerator.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Globalization; using System.Text; +using Amido.NAuto.MultiTargeting; namespace Amido.NAuto.Randomizers { @@ -31,7 +32,7 @@ public class RandomStringGenerator private static readonly List GermanUppercase = new List { "ä", "ö", "ü", "ß", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; private static readonly List Pinyin = new List { "ēi", "bǐ", "xī", "dí", "yī", "ài fú", "jí", "ài chǐ", "ài", "jié", "kāi", "ài lè", "ài mǎ", "ài nà", "ó", "pì", "jí wú", "ài ér", "ài sī", "tí", "yī wú", "wéi", "dòu bèi ěr wéi", "yī kè sī", "wú ài", "zéi dé" }; - + private static readonly List Chinese = new List { "安", "吧", "爸", "八", "百", "北", "不", "大", "岛", "的", "弟", "地", "东", "都", "对", "多", "儿", "二", "方", "港", "哥", "个", "关", "贵", "国", "过", "海", "好", "很", "会", "家", "见", "叫", "姐", "京", "九", "可", "老", "李", "零", "六", "吗", "妈", "么", "没", "美", "妹", "们", "明", "名", "哪", "那", "南", "你", "您", "朋", "七", "起", "千", "去", "人", "认", "日", "三", "上", "谁", "什", "生", "师", "识", "十", "是", "四", "他", "她", "台", "天", "湾", "万", "王", "我", "五", "西", "息", "系", "先", "香", "想", "小", "谢", "姓", "休", "学", "也", "一", "亿", "英", "友", "月", "再", "张", "这", "中", "字" }; private static readonly List ChineseNumbers = new List { "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" }; @@ -83,27 +84,27 @@ private void SetLanguageCharacterSets(Language language) _uppercase.Clear(); switch (language) { - case Language.Russian: + case Language.Russian: _lowercase.AddRange(CyrillicLowercase); _uppercase.AddRange(CyrillicUppercase); break; - case Language.Chinese: + case Language.Chinese: _lowercase.AddRange(Chinese); _uppercase.AddRange(Chinese); break; - case Language.German: + case Language.German: _lowercase.AddRange(GermanLowercase); _uppercase.AddRange(GermanUppercase); break; - case Language.Spanish: + case Language.Spanish: _lowercase.AddRange(SpanishLowercase); _uppercase.AddRange(SpanishUppercase); break; - case Language.Italian: + case Language.Italian: _lowercase.AddRange(ItalianLowercase); _uppercase.AddRange(ItalianUppercase); break; - case Language.Pinyin: + case Language.Pinyin: _lowercase.AddRange(Pinyin); _uppercase.AddRange(Pinyin); break; @@ -123,8 +124,7 @@ private static string ConvertToProperCaseIfRequired(string text, Casing casing) { if (casing == Casing.ProperCase) { - var textInfo = new CultureInfo("en-GB", false).TextInfo; - return textInfo.ToTitleCase(text.ToLower()); + text.ToLower().ToTitleCase(); } return text; From d8af4d141c023c8eaf4676e768f9fb11ee616791 Mon Sep 17 00:00:00 2001 From: Alex Brown Date: Tue, 17 Jul 2018 16:23:52 +0100 Subject: [PATCH 3/3] bump version to 2.0.0 --- Amido.NAuto/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Amido.NAuto/Properties/AssemblyInfo.cs b/Amido.NAuto/Properties/AssemblyInfo.cs index 4d1421a..fcbb8a8 100644 --- a/Amido.NAuto/Properties/AssemblyInfo.cs +++ b/Amido.NAuto/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.6")] -[assembly: AssemblyFileVersion("1.0.0.6")] +[assembly: AssemblyVersion("2.0.0")] +[assembly: AssemblyFileVersion("2.0.0")]