Пример #1
0
            public void Should_Compare_Properties_Of_Different_Models_With_Different_Properties_And_Return_False()
            {
                var modelA  = NAuto.AutoBuild <ModelATestClass>().Construct().Build();
                var modelB  = NAuto.AutoBuild <ModelBTestClass>().Construct().Build();
                var results = NAuto.CompareModelProperties(modelA, modelB);

                results.AreEqual.ShouldBeFalse();
            }
Пример #2
0
        public void Should_Throw_Exception_If_Abstract_Class_Used_As_Type_Argument()
        {
            var exception = Assert.Throws <ArgumentException>(() => NAuto.AutoBuild <MyAbstractClass>()
                                                              .Construct()
                                                              .Build());

            exception.Message.ShouldEqual("Can't instantiate abstract classes");
        }
Пример #3
0
        public void Should_Throw_Exception_If_Interface_Used_As_Type_Argument()
        {
            var exception = Assert.Throws <ArgumentException>(() => NAuto.AutoBuild <IMyInterface>()
                                                              .Construct()
                                                              .Build());

            exception.Message.ShouldEqual("Can't instantiate interfaces");
        }
Пример #4
0
        public void Should_Populate_Arrays_Of_All_Supported_Types()
        {
            var testModel = NAuto.AutoBuild <ArraysModel>()
                            .Construct()
                            .Build();

            testModel.ShouldNotBeNull();
        }
Пример #5
0
        public void Should_Add_Multiple_String_Collections()
        {
            var testModel = NAuto.AutoBuild <StringCollectionsModel>()
                            .Construct()
                            .Build();

            // Assert
            testModel.FavouriteStrings.Count.ShouldEqual(configuration.DefaultCollectionItemCount);
        }
Пример #6
0
        public void Should_Construct_Using_Argument_And_Populate_PrivateSetter()
        {
            var noDefautConstructor = NAuto.AutoBuild <NoDefaultConstructor>()
                                      .Construct("Blah")
                                      .Build();

            // Assert
            noDefautConstructor.FirstName.ShouldEqual("Blah");
        }
Пример #7
0
        public void Should_Construct_Automatically_And_Populate_PrivateSetter()
        {
            var noDefautConstructor = NAuto.AutoBuild <NoDefaultConstructor>()
                                      .Construct()
                                      .Build();

            // Assert
            noDefautConstructor.FirstName.ShouldNotBeNull();
        }
Пример #8
0
        public void Should_Return_Json_Representation_Of_Model()
        {
            // Act
            var testModel = NAuto.AutoBuild <TestModel>()
                            .Construct()
                            .ToJson();

            testModel.ShouldNotBeNull();
        }
Пример #9
0
        public void Should_Handle_Array_Based_Top_Level_Models()
        {
            // Act
            var testArray = NAuto.AutoBuild <TestModel[]>()
                            .Construct()
                            .Build();

            // Assert
            testArray.ShouldNotBeEmpty();
        }
Пример #10
0
        public void Should_Handle_List_Based_Top_Level_Models()
        {
            // Act
            var testList = NAuto.AutoBuild <List <TestModel> >()
                           .Construct()
                           .Build();

            // Assert
            testList.ShouldNotBeEmpty();
        }
Пример #11
0
        public void Should_Not_Exceed_Max_Depth_Default()
        {
            // Act
            var testModel = NAuto.AutoBuild <TestModel>()
                            .Construct()
                            .Build();

            // Assert
            testModel.SubTestModel.SubSubTestModel.FavouriteComplexList[0].FavouriteComplexList[0].SubSubString.ShouldBeNull();
        }
Пример #12
0
        public void Should_Generate_Sequenced_List_With_Specified_Number_Of_Arguments()
        {
            var testModel = NAuto.AutoBuild <TestModel>()
                            .Configure(x => x.DefaultLanguage = Language.Chinese)
                            .Construct()
                            .With(x => x.Sequencing = NAuto.GetRandomList <ClassForSequencing>(s => s.Id, 10, 5, 10, language: Language.Chinese))
                            .Build();

            testModel.ShouldNotBeNull();
        }
Пример #13
0
        public void Should_Not_Exceed_Max_Depth_Default_Of_Override_Depth_Of_4()
        {
            // Act
            var testModel = NAuto.AutoBuild <TestModel>(new AutoBuilderConfiguration(maxDepth: 4))
                            .Construct()
                            .Build();

            // Assert
            testModel.SubTestModel.SubSubTestModel.FavouriteComplexList[0].SubSubString.ShouldBeNull();
        }
Пример #14
0
        public void Should_Return_Email_Type_Base_On_Property_Name()
        {
            var autoTestBuilderConfiguration = new AutoBuilderConfiguration();
            var conventionsTestModel         = NAuto.AutoBuild <ConventionsModel>(autoTestBuilderConfiguration)
                                               .Configure(x => x.DefaultLanguage = Language.Russian)
                                               .Construct()
                                               .Build();

            conventionsTestModel.Email.ShouldContain("@");
        }
Пример #15
0
        public void Should_Add_Complex_Item_ToArray()
        {
            // Act
            var testModel = NAuto.AutoBuild <TestModel>(new AutoBuilderConfiguration())
                            .Construct()
                            .Build();

            // Assert
            testModel.FavouriteComplexArray.Length.ShouldEqual(configuration.DefaultCollectionItemCount);
        }
Пример #16
0
        public void Should_Follow_If_Then_Logic()
        {
            var model = NAuto.AutoBuild <TestModel>()
                        .Construct()
                        .If(x => x.Email != null)
                        .Then(x => x.LastName = "Blah")
                        .Build();

            model.LastName.ShouldEqual("Blah");
        }
Пример #17
0
        public void Should_Use_Data_Annotation_Email_Type_As_Convention()
        {
            var testModel = NAuto.AutoBuild <TestAnnotationModelIntegrationTests>()
                            .ClearConventions()
                            .Construct()
                            .Build();

            // Assert
            testModel.Email.ShouldContain("@");
        }
Пример #18
0
        public void Should_Use_Chinese_CharacterSet()
        {
            var testModel = NAuto.AutoBuild <TestModel>()
                            .ClearConventions()
                            .Configure(x => x.DefaultLanguage = Language.Chinese)
                            .Construct()
                            .Build();

            testModel.ShouldNotBeNull();
        }
Пример #19
0
        public void Should_Return_Model_With_Updated_Random_Settings_For_2_Levels_Deep_Property_In_Graph()
        {
            // Act
            var testModel = NAuto.AutoBuild <TestModel>()
                            .Construct()
                            .With(x => x.SubTestModel.SubString, 7, CharacterSetType.Anything, Spaces.Middle, Casing.Lowered)
                            .Build();

            // Assert
            testModel.SubTestModel.SubString.Length.ShouldEqual(7);
        }
Пример #20
0
        public void Should_Use_Nullable_Int_Range_Data_Annotation_As_Convention()
        {
            var testModel = NAuto.AutoBuild <TestAnnotationModelIntegrationTests>()
                            .ClearConventions()
                            .Construct()
                            .Build();

            // Assert
            testModel.RangeNullableIntTest.ShouldBeGreaterThanOrEqualTo(1);
            testModel.RangeNullableIntTest.ShouldBeLessThanOrEqualTo(10);
        }
Пример #21
0
        public void Should_Create_Empty_Instance_Of_Model()
        {
            const string Email = "*****@*****.**";

            var testModel = NAuto.AutoBuild <TestModel>()
                            .Empty()
                            .With(x => x.Email = Email)
                            .Build();

            testModel.ShouldNotBeNull();
            testModel.Email.ShouldEqual(Email);
        }
Пример #22
0
        public void Should_Return_Model_With_Updated_Random_Settings_For_3rd_Level_Double_Property_In_Graph()
        {
            // Act
            var testModel = NAuto.AutoBuild <TestModel>()
                            .Construct()
                            .With(x => x.SubTestModel.SubSubTestModel.SubSubDouble, 100, 103)
                            .Build();

            // Assert
            testModel.SubTestModel.SubSubTestModel.SubSubDouble.ShouldBeGreaterThanOrEqualTo(100);
            testModel.SubTestModel.SubSubTestModel.SubSubDouble.ShouldBeLessThanOrEqualTo(103);
        }
Пример #23
0
        public void Should_Return_Model_With_Updated_Random_Settings_For_Top_Level_Integer_Property_In_Graph()
        {
            // Act
            var testModel = NAuto.AutoBuild <TestModel>()
                            .Construct()
                            .With(x => x.FavouriteInteger, 10, 13)
                            .Build();

            // Assert
            testModel.FavouriteInteger.ShouldBeGreaterThanOrEqualTo(10);
            testModel.FavouriteInteger.ShouldBeLessThanOrEqualTo(13);
        }
Пример #24
0
        public void Should_Create_Empty_Instance_Of_Model_In_Json()
        {
            const string Email = "*****@*****.**";

            var testModel = NAuto.AutoBuild <TestModel>()
                            .Empty()
                            .With(x => x.Email = Email)
                            .ToJson();

            testModel.ShouldNotBeNull();
            testModel.ShouldContain(Email);
        }
Пример #25
0
        public void Should_Generate_List_With_Specified_Number_Of_Arguments()
        {
            var config = new AutoBuilderConfiguration(defaultLanguage: Language.Chinese);

            var testModel = NAuto.AutoBuild <TestModel>(config)
                            .Configure(x => x.DefaultLanguage = Language.Chinese)
                            .Construct()
                            .With(x => x.FavouriteStringList = NAuto.GetRandomList <string>(5, autoBuilderConfiguration: config))
                            .Build();

            testModel.ShouldNotBeNull();
        }
Пример #26
0
        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 <ConventionsModel>(autoTestBuilderConfiguration)
                                       .Construct()
                                       .Build();

            // Assert
            conventionsTestModel.PetName.ShouldEqual("Rex");
            conventionsTestModel.SubConventionsModel.PetName.ShouldEqual("Rex");
        }
Пример #27
0
        public void Should_Override_Property_With_Random_Email()
        {
            // Act
            var testModel = NAuto.AutoBuild <TestModel>()
                            .Construct()
                            .With(x => x.Email, PropertyType.Email)
                            .With(x => x.SubTestModel.SubEmail, PropertyType.Email)
                            .With(x => x.SubTestModel.SubSubTestModel.SubSubEmail, PropertyType.Email)
                            .Build();

            // Assert
            testModel.Email.ShouldContain("@");
            testModel.SubTestModel.SubEmail.ShouldContain("@");
            testModel.SubTestModel.SubSubTestModel.SubSubEmail.ShouldContain("@");
        }
Пример #28
0
        public static List <TModel> Get <TModel>(int numberOfItems = 2, AutoBuilderConfiguration configuration = null, Language language = Language.English) where TModel : class
        {
            var autoBuilder = configuration != null?NAuto.AutoBuild <List <TModel> >(configuration) : NAuto.AutoBuild <List <TModel> >();

            if (language == Language.English && configuration != null)
            {
                language = configuration.DefaultLanguage;
            }

            return(autoBuilder
                   .Configure(x => x.DefaultCollectionItemCount = numberOfItems)
                   .Configure(x => x.DefaultLanguage = language)
                   .Construct()
                   .Build());
        }
Пример #29
0
        public void Should_Override_Properties_Data_Generation()
        {
            // Arrange
            const int minLength = 5;
            const int maxLength = 50;
            var       config    = new AutoBuilderConfiguration(stringMinLength: minLength, stringMaxLength: maxLength);

            // Act
            var testModel = NAuto.AutoBuild <TestModel>(config)
                            .Construct()
                            .Build();

            // Assert
            testModel.SubTestModel.SubString.Length.ShouldBeGreaterThanOrEqualTo(minLength);
            testModel.SubTestModel.SubString.Length.ShouldBeLessThanOrEqualTo(maxLength);
        }
Пример #30
0
        public void Should_Construct_List_Based_Top_Level_Models_With_Parameters()
        {
            // Arrange
            var testListParameter = new List <TestModel>();

            testListParameter.Add(new TestModel {
                FirstName = "Sean"
            });
            // Act
            var testList = NAuto.AutoBuild <List <TestModel> >()
                           .Construct(testListParameter)
                           .Build();

            // Assert
            testList.ShouldNotBeEmpty();
        }