コード例 #1
0
        public void SetPropertyValueTestClassSuccess(string propertyName, object value, bool includeNonPublic)
        {
            var obj = TestClassBuilder.Build(RandomUtil.Randomizer.Next(), NestedTestClassBuilder.Build(RandomUtil.Randomizer.Next()));

            _ = obj.SetPropertyValue(propertyName, value, includeNonPublic);
            Assert.That(obj.GetPropertyValue(propertyName, includeNonPublic), Is.EqualTo(value));
        }
コード例 #2
0
        public override void TestInitialize()
        {
            base.TestInitialize();

            ConfigOptions = new ConfigOptions()
            {
                FetchConfig = TypeCollectionTester.GetDefaultFetchConfig(),
                QueryParams = new NameValueCollection()
            };

            WorkspaceBuilder.DefaultProject
            .AddFakeMvc();

            // Test class to use as return/param
            AddClass("TestClass")
            .AddScriptObjectAttribute()
            .AddProperty("DontCare", "int")
            .Commit();

            // Test generic class to use as return/param
            AddClass("TestGenericClass")
            .AddScriptObjectAttribute()
            .AddGenericParameter("T")
            .AddProperty("GenericProp", "T")
            .Commit();

            ControllerBuilder = AddClass(ControllerFullName)
                                .WithControllerBaseClass()

                                // Fake Json method
                                .AddMethod("Json", MvcConstants.JsonResult_AspNetCore)
                                .AddParameter("data", "object")
                                .AddLineOfCode("return null;", 0)
                                .Commit();
        }
コード例 #3
0
        public void With_Field_ThrowsKeyNotFoundException()
        {
            // arrange
            var builder = new TestClassBuilder();

            // act
            void SetField() => builder.With(tc => tc.IAmMostDefinitelyNotAProperty, "test");

            // assert
            Assert.ThrowsException <KeyNotFoundException>((Action)SetField);
        }
コード例 #4
0
        public void With_GetOnlyProperty_ThrowsKeyNotFoundException()
        {
            // arrange
            var builder = new TestClassBuilder();

            // act
            void SetReadOnlyProperty() => builder.With(tc => tc.ICannotBeWrittenTo, 1.0);

            // assert
            Assert.ThrowsException <KeyNotFoundException>((Action)SetReadOnlyProperty);
        }
コード例 #5
0
        public void Create_DefaultValue_IsNotNull()
        {
            // arrange
            var builder = new TestClassBuilder();

            // act
            var result = builder.Create();

            // assert
            Assert.IsNotNull(result.MeToo);
        }
コード例 #6
0
        public void With_SetterProperty_IsExpected()
        {
            // arrange
            var       builder  = new TestClassBuilder();
            const int expected = 2;

            // act
            var result = builder.With(tc => tc.IAmAProperty, expected).Create();

            // assert
            Assert.AreEqual(expected, result.IAmAProperty);
        }
コード例 #7
0
        public void DefaultCamelCase_PropNamesAreConverted()
        {
            WorkspaceBuilder.ProcessorSettings.NamingStrategy = NamingStrategy.Create(NamingStrategyType.Camel);
            TestClassBuilder builder = AddExtractedClass("MyType");

            builder.AddPropertyAndBuildAttributes("PropName", "string")
            .AddAttribute(KnownTypes.NewtonsoftJsonPropertyName_v12)
            .Commit();

            builder.Commit();

            AssertClassScriptTextIs(@"
/**  */
export interface MyType {
	/**  */
	propName: string;
}");
        }
コード例 #8
0
        public void NewtonsoftJson_NamingStratNone_NoOverride_NameIsNotConverted()
        {
            WorkspaceBuilder.ProcessorSettings.NamingStrategy = NamingStrategy.Create(NamingStrategyType.None);
            TestClassBuilder builder = AddExtractedClass("MyType");

            builder.AddPropertyAndBuildAttributes("PropName", "string")
            .AddAttribute(KnownTypes.NewtonsoftJsonPropertyName_v12)
            .Commit();

            builder.Commit();

            AssertClassScriptTextIs(@"
/**  */
export interface MyType {
	/**  */
	PropName: string;
}");
        }
コード例 #9
0
        public void NewtonsoftJson_NameIsConverted()
        {
            TestClassBuilder builder = AddExtractedClass("MyType");

            builder.AddPropertyAndBuildAttributes("PropName", "string")
            .AddAttribute(KnownTypes.NewtonsoftJsonPropertyName_v12)
            .AddNamedArg("PropertyName", "\"name\"")
            .Commit();

            builder.Commit();

            AssertClassScriptTextIs(@"
/**  */
export interface MyType {
	/**  */
	name: string;
}");
        }
コード例 #10
0
        public void BuildTestClasses_TraverserWithAtLeastOnePublicTypeGiven_ShouldReturnTestClass()
        {
            //Arrange
            var testMethod = new TestMethod(typeof(string).GetMethods().First(), "name", "code");

            assemblyTraverser.Expect(x => x.GetTypes())
            .Return(new[] { typeof(string) })
            .Repeat.Once();

            testMethodGenerator.Expect(m => m.GenerateTestMethods(null))
            .IgnoreArguments()
            .Return(new[] { testMethod });

            var instance = new TestClassBuilder(assemblyTraverser, generators);

            //Act
            var classes = instance.BuildTestClasses();

            //Assert
            assemblyTraverser.VerifyAllExpectations();
            classes.Should().OnlyContain(x => x.Methods.All(m => m == testMethod));
        }
コード例 #11
0
        public void BuildTestClasses_TraverserWithAtLeastOnePublicTypeGiven_ShouldReturnTestClass()
        {
            //Arrange
            var testMethod = new TestMethod(typeof(string).GetMethods().First(), "name", "code");

            assemblyTraverser.Expect(x => x.GetTypes())
                .Return(new[] { typeof(string) })
                .Repeat.Once();

            testMethodGenerator.Expect(m => m.GenerateTestMethods(null))
                .IgnoreArguments()
                .Return(new[] { testMethod });

            var instance = new TestClassBuilder(assemblyTraverser, generators);

            //Act
            var classes = instance.BuildTestClasses();

            //Assert
            assemblyTraverser.VerifyAllExpectations();
            classes.Should().OnlyContain(x => x.Methods.All(m => m == testMethod));
        }
コード例 #12
0
        public void TestClassBuilderConstructor_Always_Succeeds()
        {
            var instance = new TestClassBuilder(assemblyTraverser, generators);

            instance.Should().NotBeNull();
        }
コード例 #13
0
        public void TestClassBuilderConstructor_Always_Succeeds()
        {
            var instance = new TestClassBuilder(assemblyTraverser, generators);

            instance.Should().NotBeNull();
        }