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)); }
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(); }
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); }
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); }
public void Create_DefaultValue_IsNotNull() { // arrange var builder = new TestClassBuilder(); // act var result = builder.Create(); // assert Assert.IsNotNull(result.MeToo); }
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); }
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; }"); }
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; }"); }
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; }"); }
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)); }
public void TestClassBuilderConstructor_Always_Succeeds() { var instance = new TestClassBuilder(assemblyTraverser, generators); instance.Should().NotBeNull(); }