public void SupportsNullDoubleProperties() { var excelGivenClass = ExcelGivenClass( "Target", new GivenClassSimpleProperty("NullableDoubleProperty", ExcelPropertyType.Null) ); var actual = new SpecificationSpecificClassGenerator( new ExcelCsharpPropertyMatcher(), excelGivenClass ).CsharpCode( "SampleTests", new List <string>(), typeof(ITarget) ); var expectedSetter = @"internal SpecificationSpecificTarget NullableDoubleProperty_of(Double? nullableDoubleProperty) { AddValueProperty(GetCurrentMethod(), nullableDoubleProperty); target.Setup(m => m.NullableDoubleProperty).Returns(nullableDoubleProperty); return this; }"; StringAssert.Contains(expectedSetter, actual); }
public void SupportsComplexProperties() { var excelGivenClass = ExcelGivenClass( "Target", new GivenClassComplexProperty("ComplexProperty", "Target") ); var actual = new SpecificationSpecificClassGenerator( new ExcelCsharpPropertyMatcher(), excelGivenClass ).CsharpCode( "SampleTests", new List <string>(), typeof(ITarget) ); var expectedSetter = @"internal SpecificationSpecificTarget ComplexProperty_of(SpecificationSpecificTarget complexProperty) { AddClassProperty(new ReportSpecificationSetupClass(GetCurrentMethod(), complexProperty)); target.Setup(m => m.ComplexProperty).Returns(complexProperty?.Target); return this; }"; StringAssert.Contains(expectedSetter, actual); }
public void SupportsIEnumerableProperties() { var excelGivenClass = ExcelGivenClass( "Target", new GivenClassComplexListProperty("IEnumerableProperty", "Target") ); var actual = new SpecificationSpecificClassGenerator( new ExcelCsharpPropertyMatcher(), excelGivenClass ).CsharpCode( "SampleTests", new List <string>(), typeof(ITarget) ); var expectedListDeclaration = @"readonly List<SpecificationSpecificTarget> iEnumerablePropertys = new List<SpecificationSpecificTarget>();"; var expectedMockSetup = @"target.Setup(m => m.IEnumerableProperty).Returns(iEnumerablePropertys.Select(l => l.Target));"; var expectedListOfSetters = @"internal SpecificationSpecificTarget IEnumerableProperty_of(SpecificationSpecificTarget iEnumerableProperty) { AddClassProperty(new ReportSpecificationSetupClass(GetCurrentMethod(), iEnumerableProperty)); this.iEnumerablePropertys.Add(iEnumerableProperty); return this; }"; var expectedTableOfSetters = @"internal SpecificationSpecificTarget IEnumerableProperty_table_of(ReportSpecificationSetupClassUsingTable<SpecificationSpecificTarget> iEnumerablePropertys) { iEnumerablePropertys.PropertyName = GetCurrentMethod().Name; AddClassTableProperty(iEnumerablePropertys); foreach (var row in iEnumerablePropertys.Rows) this.iEnumerablePropertys.Add(row.Properties); return this; }"; StringAssert.Contains(expectedListDeclaration, actual); StringAssert.Contains(expectedMockSetup, actual); StringAssert.Contains(expectedListOfSetters, actual); StringAssert.Contains(expectedTableOfSetters, actual); StringAssert.DoesNotContain( "AddValueProperty(GetCurrentMethod(), iEnumerableProperty)", actual, "'Object' Code is being generated for a 'List' property"); }
void GeneratedSpecificationSpecificMatchedClass( GivenClass excelGivenClass, Type matchingType) { var code = new SpecificationSpecificClassGenerator( excelCsharpPropertyMatcher, excelGivenClass) .CsharpCode( projectRootNamespace, usings, matchingType ); AddGeneratedFile(excelGivenClass, code); }
public void SupportsListProperties() { var excelGivenClass = ExcelGivenClass( "Target", new GivenClassComplexListProperty("ListProperty", "Target") ); var actual = new SpecificationSpecificClassGenerator( new ExcelCsharpPropertyMatcher(), excelGivenClass ).CsharpCode( "SampleTests", new List <string>(), typeof(ITarget) ); var expectedMockSetup = @"target.Setup(m => m.ListProperty).Returns(listPropertys.Select(l => l.Target));"; // Everything apart from the mock setup is the same as the IEnumerable properties, so not replicating here StringAssert.Contains(expectedMockSetup, actual); }
public void SupportsSimpleProperties() { var excelGivenClass = ExcelGivenClass( "Target", new GivenClassSimpleProperty("IntegerProperty", ExcelPropertyType.Number), new GivenClassSimpleProperty("FloatProperty", ExcelPropertyType.Number), new GivenClassSimpleProperty("StringProperty", ExcelPropertyType.String), new GivenClassSimpleProperty("DateTimeProperty", ExcelPropertyType.DateTime) ); var actual = new SpecificationSpecificClassGenerator( new ExcelCsharpPropertyMatcher(), excelGivenClass ).CsharpCode( "SampleTests", new List <string> { "SampleSystemUnderTest.VermeulenNearWakeLength" }, typeof(ITarget) ); var expected = @"using System; using System.Collections.Generic; using System.Linq; using static System.Reflection.MethodBase; using Moq; using CustomerTestsExcel; using CustomerTestsExcel.SpecificationSpecificClassGeneration; using SampleSystemUnderTest.VermeulenNearWakeLength; namespace SampleTests.Setup { public partial class SpecificationSpecificTarget : ReportsSpecificationSetup { readonly Mock<ITarget> target; public ITarget Target => target.Object; public SpecificationSpecificTarget() { target = new Mock<ITarget>(); } internal SpecificationSpecificTarget IntegerProperty_of(Int32 integerProperty) { AddValueProperty(GetCurrentMethod(), integerProperty); target.Setup(m => m.IntegerProperty).Returns(integerProperty); return this; } internal SpecificationSpecificTarget FloatProperty_of(Single floatProperty) { AddValueProperty(GetCurrentMethod(), floatProperty); target.Setup(m => m.FloatProperty).Returns(floatProperty); return this; } internal SpecificationSpecificTarget StringProperty_of(String stringProperty) { AddValueProperty(GetCurrentMethod(), stringProperty); target.Setup(m => m.StringProperty).Returns(stringProperty); return this; } internal SpecificationSpecificTarget DateTimeProperty_of(DateTime dateTimeProperty) { AddValueProperty(GetCurrentMethod(), dateTimeProperty); target.Setup(m => m.DateTimeProperty).Returns(dateTimeProperty); return this; } } } "; IncrementallyAssertEqual(expected, actual); }