static CellReferenceTest() { StringRepresentationTestScenarios .RemoveAllScenarios() .AddScenario( new StringRepresentationTestScenario <CellReference> { Name = "ToString() should return 'KNOWN MISSING' when the cell is Known Missing.", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <CellReference> { SystemUnderTest = CellReference.GetKnownMissing(), ExpectedStringRepresentation = "KNOWN MISSING", }, }) .AddScenario( new StringRepresentationTestScenario <CellReference> { Name = "ToString() should return WorksheetQualifiedA1Reference when cell is NOT Known Missing.", SystemUnderTestExpectedStringRepresentationFunc = () => { var systemUnderTest = A.Dummy <CellReference>(); var result = new SystemUnderTestExpectedStringRepresentation <CellReference> { SystemUnderTest = systemUnderTest, ExpectedStringRepresentation = systemUnderTest.WorksheetQualifiedA1Reference, }; return(result); }, }); }
public static void ToString___Should_generate_friendly_string_representation_of_object___When_called() { var scenarios = StringRepresentationTestScenarios.ValidateAndPrepareForTesting(); foreach (var scenario in scenarios) { // Arrange, Act var actual = scenario.SystemUnderTest.ToString(); // Assert actual.AsTest().Must().BeEqualTo(scenario.ExpectedStringRepresentation, because: scenario.Id); } }
static GenericUnboundedTest() { var referenceGenericUnbounded = A.Dummy <GenericUnbounded>(); ComparableTestScenarios .RemoveAllScenarios() .AddScenario(() => new ComparableTestScenario <GenericUnbounded> { Name = "Comparable Test Scenario", ReferenceObject = referenceGenericUnbounded, ObjectsThatAreLessThanReferenceObject = new GenericUnbounded[] { }, ObjectsThatAreGreaterThanReferenceObject = new GenericUnbounded[] { }, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { referenceGenericUnbounded.DeepClone(), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), } .Concat(TestCommon.GetDummyOfEachUnitOfTimeKind().Where(_ => _.GetType() != typeof(GenericUnbounded))) .ToList(), ObjectsThatDeriveFromScenarioTypeButAreNotOfTheSameTypeAsReferenceObject = new GenericUnbounded[] { }, }); StringRepresentationTestScenarios .RemoveAllScenarios() .AddScenario(() => new StringRepresentationTestScenario <GenericUnbounded> { Name = "String Representation - case 1", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <GenericUnbounded> { SystemUnderTest = new GenericUnbounded(), ExpectedStringRepresentation = "generic unbounded", }, }); }
static ModelPrivateSetMultilevelGrandchild1ATest() { StringRepresentationTestScenarios.RemoveAllScenarios(); StringRepresentationTestScenarios.AddScenario(StringRepresentationTestScenario <ModelPrivateSetMultilevelGrandchild1A> .ForceGeneratedTestsToPassAndWriteMyOwnScenario); ConstructorArgumentValidationTestScenarios.AddScenario( ConstructorArgumentValidationTestScenario <ModelPrivateSetMultilevelGrandchild1A> .ConstructorCannotThrowScenario); ComparableTestScenarios.AddScenario(new ComparableTestScenario <ModelPrivateSetMultilevelGrandchild1A> { Name = "Scenario 1", ReferenceObject = new ModelPrivateSetMultilevelGrandchild1A(1, 2, 3), ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { new ModelPrivateSetMultilevelGrandchild1A(1, 2, 3), new ModelPrivateSetMultilevelGrandchild1A(3, 2, 1), new ModelPrivateSetMultilevelGrandchild1A(0, 6, 0), }, ObjectsThatAreLessThanReferenceObject = new[] { new ModelPrivateSetMultilevelGrandchild1A(1, 2, 2), new ModelPrivateSetMultilevelGrandchild1A(6, -2, -1), new ModelPrivateSetMultilevelGrandchild1A(0, 5, 0), }, ObjectsThatAreGreaterThanReferenceObject = new[] { new ModelPrivateSetMultilevelGrandchild1A(2, 2, 3), new ModelPrivateSetMultilevelGrandchild1A(3, 3, 1), new ModelPrivateSetMultilevelGrandchild1A(0, 7, 0), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new object[] { 1, "dummy-string", new ModelPrivateSetMultilevelGrandchild1B(1, 2, 3), new ModelPrivateSetMultilevelGrandchild2A(1, 2, 3), new ModelPrivateSetMultilevelGrandchild2B(1, 2, 3), }, }); }
static NotificationTrackingCodeTest() { ConstructorArgumentValidationTestScenarios .AddScenario(ConstructorArgumentValidationTestScenario <NotificationTrackingCode> .ConstructorCannotThrowScenario); StringRepresentationTestScenarios .AddScenario(() => new StringRepresentationTestScenario <NotificationTrackingCode> { Name = "ToString() gets friendly string representation", SystemUnderTestExpectedStringRepresentationFunc = () => { var systemUnderTest = A.Dummy <NotificationTrackingCode>(); var result = new SystemUnderTestExpectedStringRepresentation <NotificationTrackingCode> { SystemUnderTest = systemUnderTest, ExpectedStringRepresentation = Invariant($"{systemUnderTest.Id}"), }; return(result); }, }); }
static ModelStringRepresentationPublicSetArrayChild1Test() { StringRepresentationTestScenarios.AddScenario(StringRepresentationTestScenario <ModelStringRepresentationPublicSetArrayChild1> .ForceGeneratedTestsToPassAndWriteMyOwnScenario); }
static GenericQuarterTest() { var referenceGenericQuarter = A.Dummy <GenericQuarter>(); ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario(() => new ConstructorArgumentValidationTestScenario <GenericQuarter> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' is < 0", ConstructionFunc = () => new GenericQuarter(A.Dummy <NegativeInteger>(), referenceGenericQuarter.QuarterNumber), ExpectedExceptionMessageContains = new[] { "'year' < '1'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <GenericQuarter> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' = 0", ConstructionFunc = () => new GenericQuarter(0, referenceGenericQuarter.QuarterNumber), ExpectedExceptionMessageContains = new[] { "'year' < '1'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <GenericQuarter> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' = 10000", ConstructionFunc = () => new GenericQuarter(10000, referenceGenericQuarter.QuarterNumber), ExpectedExceptionMessageContains = new[] { "'year' > '9999'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <GenericQuarter> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' > 9999", ConstructionFunc = () => new GenericQuarter(A.Dummy <PositiveInteger>().ThatIs(_ => _ > 9999, -1), referenceGenericQuarter.QuarterNumber), ExpectedExceptionMessageContains = new[] { "'year' > '9999'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <GenericQuarter> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'quarterNumber' is QuarterNumber.Invalid", ConstructionFunc = () => new GenericQuarter(referenceGenericQuarter.Year, QuarterNumber.Invalid), ExpectedExceptionMessageContains = new[] { "quarterNumber", "Invalid" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }); ComparableTestScenarios .RemoveAllScenarios() .AddScenario(() => new ComparableTestScenario <GenericQuarter> { Name = "Comparable Test Scenario", ReferenceObject = referenceGenericQuarter, ObjectsThatAreLessThanReferenceObject = new[] { referenceGenericQuarter.TweakBy(-1, GenericQuarterComponent.Quarter), referenceGenericQuarter.TweakBy(-1, GenericQuarterComponent.Year), }, ObjectsThatAreGreaterThanReferenceObject = new[] { referenceGenericQuarter.TweakBy(1, GenericQuarterComponent.Quarter), referenceGenericQuarter.TweakBy(1, GenericQuarterComponent.Year), }, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { referenceGenericQuarter.DeepClone(), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), } .Concat(TestCommon.GetDummyOfEachUnitOfTimeKind().Where(_ => _.GetType() != typeof(GenericQuarter))) .ToList(), ObjectsThatDeriveFromScenarioTypeButAreNotOfTheSameTypeAsReferenceObject = new GenericQuarter[] { }, }); StringRepresentationTestScenarios .RemoveAllScenarios() .AddScenario(() => new StringRepresentationTestScenario <GenericQuarter> { Name = "String Representation - case 1", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <GenericQuarter> { SystemUnderTest = new GenericQuarter(2017, QuarterNumber.Q1), ExpectedStringRepresentation = "1Q2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <GenericQuarter> { Name = "String Representation - case 2", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <GenericQuarter> { SystemUnderTest = new GenericQuarter(2020, QuarterNumber.Q4), ExpectedStringRepresentation = "4Q2020", }, }); }
static ReportingPeriodTest() { DeepCloneWithTestScenarios .RemoveAllScenarios() .AddScenario(() => new DeepCloneWithTestScenario <ReportingPeriod> { Name = Invariant($"{nameof(ReportingPeriod.DeepCloneWithStart)} should deep clone object and replace {nameof(ReportingPeriod.Start)} with the provided start when {nameof(ReportingPeriod.End)} is {nameof(UnitOfTimeGranularity.Unbounded)} and provided start has the same {nameof(UnitOfTimeKind)} as {nameof(ReportingPeriod.End)}"), WithPropertyName = nameof(ReportingPeriod.Start), SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <ReportingPeriod>().Whose(_ => _.End.UnitOfTimeGranularity == UnitOfTimeGranularity.Unbounded); var referenceObject = A.Dummy <ReportingPeriod>().Whose(_ => _.GetUnitOfTimeKind() == systemUnderTest.GetUnitOfTimeKind()); var result = new SystemUnderTestDeepCloneWithValue <ReportingPeriod> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.Start, }; return(result); }, }) .AddScenario(() => new DeepCloneWithTestScenario <ReportingPeriod> { Name = Invariant($"{nameof(ReportingPeriod.DeepCloneWithStart)} should deep clone object and replace {nameof(ReportingPeriod.Start)} with the provided start when {nameof(ReportingPeriod.End)} is bounded and provided start is {nameof(UnitOfTimeGranularity.Unbounded)} having the same {nameof(UnitOfTimeKind)}"), WithPropertyName = nameof(ReportingPeriod.Start), SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <ReportingPeriod>().Whose(_ => _.End.UnitOfTimeGranularity != UnitOfTimeGranularity.Unbounded); var referenceObject = A.Dummy <ReportingPeriod>().Whose(_ => (_.Start.UnitOfTimeGranularity == UnitOfTimeGranularity.Unbounded) && (_.Start.UnitOfTimeKind == systemUnderTest.End.UnitOfTimeKind)); var result = new SystemUnderTestDeepCloneWithValue <ReportingPeriod> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.Start, }; return(result); }, }) .AddScenario(() => new DeepCloneWithTestScenario <ReportingPeriod> { Name = Invariant($"{nameof(ReportingPeriod.DeepCloneWithStart)} should deep clone object and replace {nameof(ReportingPeriod.Start)} with the provided start when {nameof(ReportingPeriod.End)} is bounded and provided start is of the same type as and <= {nameof(ReportingPeriod.End)}"), WithPropertyName = nameof(ReportingPeriod.Start), SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <ReportingPeriod>().Whose(_ => _.End.UnitOfTimeGranularity != UnitOfTimeGranularity.Unbounded); var referenceObject = A.Dummy <ReportingPeriod>().Whose(_ => (_.Start.GetType() == systemUnderTest.End.GetType()) && (_.Start <= systemUnderTest.End)); var result = new SystemUnderTestDeepCloneWithValue <ReportingPeriod> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.Start, }; return(result); }, }) .AddScenario(() => new DeepCloneWithTestScenario <ReportingPeriod> { Name = Invariant($"{nameof(ReportingPeriod.DeepCloneWithEnd)} should deep clone object and replace {nameof(ReportingPeriod.End)} with the provided end when {nameof(ReportingPeriod.Start)} is {nameof(UnitOfTimeGranularity.Unbounded)} and provided end has the same {nameof(UnitOfTimeKind)} as {nameof(ReportingPeriod.Start)}"), WithPropertyName = nameof(ReportingPeriod.End), SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <ReportingPeriod>().Whose(_ => _.Start.UnitOfTimeGranularity == UnitOfTimeGranularity.Unbounded); var referenceObject = A.Dummy <ReportingPeriod>().Whose(_ => _.GetUnitOfTimeKind() == systemUnderTest.GetUnitOfTimeKind()); var result = new SystemUnderTestDeepCloneWithValue <ReportingPeriod> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.End, }; return(result); }, }) .AddScenario(() => new DeepCloneWithTestScenario <ReportingPeriod> { Name = Invariant($"{nameof(ReportingPeriod.DeepCloneWithEnd)} should deep clone object and replace {nameof(ReportingPeriod.End)} with the provided end when {nameof(ReportingPeriod.Start)} is bounded and provided end is {nameof(UnitOfTimeGranularity.Unbounded)} having the same {nameof(UnitOfTimeKind)}"), WithPropertyName = nameof(ReportingPeriod.End), SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <ReportingPeriod>().Whose(_ => _.Start.UnitOfTimeGranularity != UnitOfTimeGranularity.Unbounded); var referenceObject = A.Dummy <ReportingPeriod>().Whose(_ => (_.End.UnitOfTimeGranularity == UnitOfTimeGranularity.Unbounded) && (_.End.UnitOfTimeKind == systemUnderTest.Start.UnitOfTimeKind)); var result = new SystemUnderTestDeepCloneWithValue <ReportingPeriod> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.End, }; return(result); }, }) .AddScenario(() => new DeepCloneWithTestScenario <ReportingPeriod> { Name = Invariant($"{nameof(ReportingPeriod.DeepCloneWithEnd)} should deep clone object and replace {nameof(ReportingPeriod.End)} with the provided end when {nameof(ReportingPeriod.Start)} is bounded and provided end is of the same type as and >= {nameof(ReportingPeriod.Start)}"), WithPropertyName = nameof(ReportingPeriod.End), SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <ReportingPeriod>().Whose(_ => _.Start.UnitOfTimeGranularity != UnitOfTimeGranularity.Unbounded); var referenceObject = A.Dummy <ReportingPeriod>().Whose(_ => (_.End.GetType() == systemUnderTest.Start.GetType()) && (_.End >= systemUnderTest.Start)); var result = new SystemUnderTestDeepCloneWithValue <ReportingPeriod> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.End, }; return(result); }, }); var unboundedStartReportingPeriod = A.Dummy <ReportingPeriod>().Whose(_ => _.Start.UnitOfTimeGranularity == UnitOfTimeGranularity.Unbounded); var boundedStartReportingPeriod = A.Dummy <ReportingPeriod>().Whose(_ => _.Start.UnitOfTimeGranularity != UnitOfTimeGranularity.Unbounded); var unboundedEndReportingPeriod = A.Dummy <ReportingPeriod>().Whose(_ => _.End.UnitOfTimeGranularity == UnitOfTimeGranularity.Unbounded); var boundedEndReportingPeriod = A.Dummy <ReportingPeriod>().Whose(_ => _.End.UnitOfTimeGranularity != UnitOfTimeGranularity.Unbounded); EquatableTestScenarios .RemoveAllScenarios() .AddScenario(() => new EquatableTestScenario <ReportingPeriod> { Name = "Reference object has unbounded Start. Create an End of the same UnitOfTimeKind that != reference object's End", ReferenceObject = unboundedStartReportingPeriod, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { unboundedStartReportingPeriod.DeepClone(), }, ObjectsThatAreNotEqualToReferenceObject = new[] { new ReportingPeriod(unboundedStartReportingPeriod.Start, A.Dummy <UnitOfTime>().Whose(_ => (_.UnitOfTimeKind == unboundedStartReportingPeriod.GetUnitOfTimeKind()) && (_ != unboundedStartReportingPeriod.End))), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), } .Concat(TestCommon.GetDummyOfEachUnitOfTimeKind()) .ToArray(), }) .AddScenario(() => new EquatableTestScenario <ReportingPeriod> { Name = "Reference object has bounded Start. Create an End that is of the same type as reference object's Start (so it will be bounded), that is > but != reference object's Start", ReferenceObject = boundedStartReportingPeriod, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { boundedStartReportingPeriod.DeepClone(), }, ObjectsThatAreNotEqualToReferenceObject = new[] { new ReportingPeriod(boundedStartReportingPeriod.Start, A.Dummy <UnitOfTime>().Whose(_ => (_.GetType() == boundedStartReportingPeriod.Start.GetType()) && (_ > boundedStartReportingPeriod.Start) && (_ != boundedStartReportingPeriod.End))), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), } .Concat(TestCommon.GetDummyOfEachUnitOfTimeKind()) .ToArray(), }) .AddScenario(() => new EquatableTestScenario <ReportingPeriod> { Name = "Reference object has unbounded End. Create an Start of the same UnitOfTimeKind that != reference object's Start", ReferenceObject = unboundedEndReportingPeriod, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { unboundedEndReportingPeriod.DeepClone(), }, ObjectsThatAreNotEqualToReferenceObject = new[] { new ReportingPeriod(A.Dummy <UnitOfTime>().Whose(_ => (_.UnitOfTimeKind == unboundedEndReportingPeriod.GetUnitOfTimeKind()) && (_ != unboundedEndReportingPeriod.Start)), unboundedEndReportingPeriod.End), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), } .Concat(TestCommon.GetDummyOfEachUnitOfTimeKind()) .ToArray(), }) .AddScenario(() => new EquatableTestScenario <ReportingPeriod> { Name = "Reference object has bounded End. Create a Start that is of the same type as reference object's End (so it will be bounded), that is < but != reference object's End", ReferenceObject = boundedEndReportingPeriod, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { boundedEndReportingPeriod.DeepClone(), }, ObjectsThatAreNotEqualToReferenceObject = new[] { new ReportingPeriod(A.Dummy <UnitOfTime>().Whose(_ => (_.GetType() == boundedEndReportingPeriod.End.GetType()) && (_ < boundedEndReportingPeriod.End) && (_ != boundedEndReportingPeriod.Start)), boundedEndReportingPeriod.End), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), } .Concat(TestCommon.GetDummyOfEachUnitOfTimeKind()) .ToArray(), }); StringRepresentationTestScenarios .RemoveAllScenarios() .AddScenario(() => new StringRepresentationTestScenario <ReportingPeriod> { Name = "String Representation - case 1", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <ReportingPeriod> { SystemUnderTest = new ReportingPeriod( new CalendarDay(2017, MonthOfYear.November, DayOfMonth.Thirty), new CalendarDay(2018, MonthOfYear.March, DayOfMonth.TwentyFour)), ExpectedStringRepresentation = "2017-11-30 to 2018-03-24", }, }); }
static ModelStringRepresentationPrivateSetReadOnlyListChild2Test() { StringRepresentationTestScenarios.AddScenario(StringRepresentationTestScenario <ModelStringRepresentationPrivateSetReadOnlyListChild2> .ForceGeneratedTestsToPassAndWriteMyOwnScenario); }
static UtcDateTimeRangeInclusiveTest() { ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario( new ConstructorArgumentValidationTestScenario <UtcDateTimeRangeInclusive> { Name = "constructor should throw ArgumentException when 'startDateTimeInUtc' is DateTimeKind.Local", ConstructionFunc = () => { var startDateTime = new DateTime(1, DateTimeKind.Local); return(new UtcDateTimeRangeInclusive(startDateTime, DateTime.UtcNow)); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "startDateTimeInUtc DateTimeKind is not Utc" }, }) .AddScenario( new ConstructorArgumentValidationTestScenario <UtcDateTimeRangeInclusive> { Name = "constructor should throw ArgumentException when 'startDateTimeInUtc' is DateTimeKind.Unspecified", ConstructionFunc = () => { var startDateTime = new DateTime(1, DateTimeKind.Unspecified); return(new UtcDateTimeRangeInclusive(startDateTime, DateTime.UtcNow)); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "startDateTimeInUtc DateTimeKind is not Utc" }, }) .AddScenario( new ConstructorArgumentValidationTestScenario <UtcDateTimeRangeInclusive> { Name = "constructor should throw ArgumentException when 'endDateTimeInUtc' is DateTimeKind.Local", ConstructionFunc = () => { var endDateTime = new DateTime(1, DateTimeKind.Local); return(new UtcDateTimeRangeInclusive(DateTime.UtcNow, endDateTime)); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "endDateTimeInUtc DateTimeKind is not Utc" }, }) .AddScenario( new ConstructorArgumentValidationTestScenario <UtcDateTimeRangeInclusive> { Name = "constructor should throw ArgumentException when 'endDateTimeInUtc' is DateTimeKind.Unspecified", ConstructionFunc = () => { var endDateTime = new DateTime(1, DateTimeKind.Unspecified); return(new UtcDateTimeRangeInclusive(DateTime.UtcNow, endDateTime)); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "endDateTimeInUtc DateTimeKind is not Utc" }, }) .AddScenario( new ConstructorArgumentValidationTestScenario <UtcDateTimeRangeInclusive> { Name = "constructor should throw ArgumentOutOfRangeException when 'startDateTimeInUtc' > 'endDateTimeInUtc'", ConstructionFunc = () => { var startDateTimeInUtc = DateTime.UtcNow; var endDateTimeInUtc = startDateTimeInUtc.AddMilliseconds(-1); return(new UtcDateTimeRangeInclusive(startDateTimeInUtc, endDateTimeInUtc)); }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), ExpectedExceptionMessageContains = new[] { "startDateTimeInUtc is > endDateTimeInUtc" }, }); StringRepresentationTestScenarios .RemoveAllScenarios() .AddScenario( new StringRepresentationTestScenario <UtcDateTimeRangeInclusive> { Name = "ToString() should return string representation of date time range", SystemUnderTestExpectedStringRepresentationFunc = () => { var startDateTime = new DateTime(2019, 3, 10, 14, 4, 59, DateTimeKind.Utc); var endDateTime = new DateTime(2020, 11, 22, 9, 43, 4, DateTimeKind.Utc); return(new SystemUnderTestExpectedStringRepresentation <UtcDateTimeRangeInclusive> { SystemUnderTest = new UtcDateTimeRangeInclusive(startDateTime, endDateTime), ExpectedStringRepresentation = "03/10/2019 14:04:59 to 11/22/2020 09:43:04", }); }, }); EquatableTestScenarios .RemoveAllScenarios() .AddScenario( new EquatableTestScenario <UtcDateTimeRangeInclusive> { ReferenceObject = ReferenceObjectForEquatableTestScenarios, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new UtcDateTimeRangeInclusive[] { new UtcDateTimeRangeInclusive( ReferenceObjectForEquatableTestScenarios.StartDateTimeInUtc, ReferenceObjectForEquatableTestScenarios.EndDateTimeInUtc), }, ObjectsThatAreNotEqualToReferenceObject = new UtcDateTimeRangeInclusive[] { new UtcDateTimeRangeInclusive( A.Dummy <UtcDateTimeRangeInclusive>().Whose(_ => (!_.StartDateTimeInUtc.IsEqualTo(ReferenceObjectForEquatableTestScenarios.StartDateTimeInUtc)) && (_.StartDateTimeInUtc <= ReferenceObjectForEquatableTestScenarios.EndDateTimeInUtc)).StartDateTimeInUtc, ReferenceObjectForEquatableTestScenarios.EndDateTimeInUtc), new UtcDateTimeRangeInclusive( ReferenceObjectForEquatableTestScenarios.StartDateTimeInUtc, A.Dummy <UtcDateTimeRangeInclusive>().Whose(_ => (!_.EndDateTimeInUtc.IsEqualTo(ReferenceObjectForEquatableTestScenarios.EndDateTimeInUtc)) && (_.EndDateTimeInUtc >= ReferenceObjectForEquatableTestScenarios.StartDateTimeInUtc)).EndDateTimeInUtc), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new object[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), }, }); DeepCloneWithTestScenarios .RemoveAllScenarios() .AddScenario(() => new DeepCloneWithTestScenario <UtcDateTimeRangeInclusive> { Name = "DeepCloneWithStartDateTimeInUtc should deep clone object and replace ParentBoolProperty with the provided parentBoolProperty", WithPropertyName = "StartDateTimeInUtc", SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <UtcDateTimeRangeInclusive>(); var referenceObject = A.Dummy <UtcDateTimeRangeInclusive>().ThatIs(_ => (!systemUnderTest.StartDateTimeInUtc.IsEqualTo(_.StartDateTimeInUtc)) && (_.StartDateTimeInUtc <= systemUnderTest.StartDateTimeInUtc)); var result = new SystemUnderTestDeepCloneWithValue <UtcDateTimeRangeInclusive> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.StartDateTimeInUtc, }; return(result); }, }) .AddScenario(() => new DeepCloneWithTestScenario <UtcDateTimeRangeInclusive> { Name = "DeepCloneWithEndDateTimeInUtc should deep clone object and replace ParentBoolProperty with the provided parentBoolProperty", WithPropertyName = "EndDateTimeInUtc", SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <UtcDateTimeRangeInclusive>(); var referenceObject = A.Dummy <UtcDateTimeRangeInclusive>().ThatIs(_ => (!systemUnderTest.EndDateTimeInUtc.IsEqualTo(_.EndDateTimeInUtc)) && (_.EndDateTimeInUtc >= systemUnderTest.EndDateTimeInUtc)); var result = new SystemUnderTestDeepCloneWithValue <UtcDateTimeRangeInclusive> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.EndDateTimeInUtc, }; return(result); }, }); }
static SqlServerLocatorTest() { StringRepresentationTestScenarios .RemoveAllScenarios() .AddScenario(() => new StringRepresentationTestScenario <SqlServerLocator> { Name = "Override ToString scenario", SystemUnderTestExpectedStringRepresentationFunc = () => { var systemUnderTest = A.Dummy <SqlServerLocator>(); var result = new SystemUnderTestExpectedStringRepresentation <SqlServerLocator> { SystemUnderTest = systemUnderTest, ExpectedStringRepresentation = Invariant($"Naos.SqlServer.Domain.SqlServerLocator: ServerName = {systemUnderTest.ServerName?.ToString(CultureInfo.InvariantCulture) ?? "<null>"}, DatabaseName = {systemUnderTest.DatabaseName?.ToString(CultureInfo.InvariantCulture) ?? "<null>"}, UserName = {systemUnderTest.UserName?.ToString(CultureInfo.InvariantCulture) ?? "<null>"}, Password = ***, InstanceName = {systemUnderTest.InstanceName?.ToString(CultureInfo.InvariantCulture) ?? "<null>"}, Port = {systemUnderTest.Port?.ToString(CultureInfo.InvariantCulture) ?? "<null>"}."), }; return(result); }, }); ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario( () => new ConstructorArgumentValidationTestScenario <SqlServerLocator> { Name = "constructor should throw ArgumentNullException when parameter 'serverName' is null scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <SqlServerLocator>(); var result = new SqlServerLocator( null, referenceObject.DatabaseName, referenceObject.UserName, referenceObject.Password, referenceObject.InstanceName, referenceObject.Port); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "serverName", }, }) .AddScenario( () => new ConstructorArgumentValidationTestScenario <SqlServerLocator> { Name = "constructor should throw ArgumentException when parameter 'serverName' is white space scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <SqlServerLocator>(); var result = new SqlServerLocator( Invariant($" {Environment.NewLine} "), referenceObject.DatabaseName, referenceObject.UserName, referenceObject.Password, referenceObject.InstanceName, referenceObject.Port); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "serverName", "white space", }, }) .AddScenario( () => new ConstructorArgumentValidationTestScenario <SqlServerLocator> { Name = "constructor should throw ArgumentNullException when parameter 'databaseName' is null scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <SqlServerLocator>(); var result = new SqlServerLocator( referenceObject.ServerName, null, referenceObject.UserName, referenceObject.Password, referenceObject.InstanceName, referenceObject.Port); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "databaseName", }, }) .AddScenario( () => new ConstructorArgumentValidationTestScenario <SqlServerLocator> { Name = "constructor should throw ArgumentException when parameter 'databaseName' is white space scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <SqlServerLocator>(); var result = new SqlServerLocator( referenceObject.ServerName, Invariant($" {Environment.NewLine} "), referenceObject.UserName, referenceObject.Password, referenceObject.InstanceName, referenceObject.Port); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "databaseName", "white space", }, }); }
static ModelStringRepresentationPublicSetReadOnlyCollectionTest() { StringRepresentationTestScenarios.AddScenario(StringRepresentationTestScenario <ModelStringRepresentationPublicSetReadOnlyCollection> .ForceGeneratedTestsToPassAndWriteMyOwnScenario); }
static TypeRepresentationTest() { ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario(() => new ConstructorArgumentValidationTestScenario <TypeRepresentation> { Name = "constructor should throw ArgumentNullException when parameter 'namespace' is null scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <TypeRepresentation>(); var result = new TypeRepresentation( null, referenceObject.Name, referenceObject.AssemblyName, referenceObject.AssemblyVersion, referenceObject.GenericArguments); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "namespace" }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TypeRepresentation> { Name = "constructor should throw ArgumentException when parameter 'namespace' is white space scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <TypeRepresentation>(); var result = new TypeRepresentation( Invariant($" {Environment.NewLine} "), referenceObject.Name, referenceObject.AssemblyName, referenceObject.AssemblyVersion, referenceObject.GenericArguments); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "namespace", "white space" }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TypeRepresentation> { Name = "constructor should throw ArgumentNullException when parameter 'name' is null scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <TypeRepresentation>(); var result = new TypeRepresentation( referenceObject.Namespace, null, referenceObject.AssemblyName, referenceObject.AssemblyVersion, referenceObject.GenericArguments); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "name" }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TypeRepresentation> { Name = "constructor should throw ArgumentException when parameter 'name' is white space scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <TypeRepresentation>(); var result = new TypeRepresentation( referenceObject.Namespace, Invariant($" {Environment.NewLine} "), referenceObject.AssemblyName, referenceObject.AssemblyVersion, referenceObject.GenericArguments); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "name", "white space" }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TypeRepresentation> { Name = "constructor should throw ArgumentNullException when parameter 'assemblyName' is null scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <TypeRepresentation>(); var result = new TypeRepresentation( referenceObject.Namespace, referenceObject.Name, null, referenceObject.AssemblyVersion, referenceObject.GenericArguments); return(result); }, ExpectedExceptionType = typeof(ArgumentNullException), ExpectedExceptionMessageContains = new[] { "assemblyName" }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TypeRepresentation> { Name = "constructor should throw ArgumentException when parameter 'assemblyName' is white space scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <TypeRepresentation>(); var result = new TypeRepresentation( referenceObject.Namespace, referenceObject.Name, Invariant($" {Environment.NewLine} "), referenceObject.AssemblyVersion, referenceObject.GenericArguments); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "assemblyName", "white space" }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TypeRepresentation> { Name = "constructor should throw ArgumentException when parameter 'assemblyVersion' is white space scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <TypeRepresentation>(); var result = new TypeRepresentation( referenceObject.Namespace, referenceObject.Name, referenceObject.AssemblyName, Invariant($" {Environment.NewLine} "), referenceObject.GenericArguments); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "assemblyVersion", "white space" }, }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <TypeRepresentation> { Name = "constructor should throw ArgumentException when parameter 'genericArguments' contains a null element scenario", ConstructionFunc = () => { var referenceObject = A.Dummy <TypeRepresentation>().ThatIs(_ => _.IsClosedGenericType()); var result = new TypeRepresentation( referenceObject.Namespace, referenceObject.Name, referenceObject.AssemblyName, referenceObject.AssemblyVersion, new TypeRepresentation[0].Concat(referenceObject.GenericArguments).Concat(new TypeRepresentation[] { null }).Concat(referenceObject.GenericArguments).ToList()); return(result); }, ExpectedExceptionType = typeof(ArgumentException), ExpectedExceptionMessageContains = new[] { "genericArguments", "contains at least one null element" }, }); ConstructorPropertyAssignmentTestScenarios .AddScenario(() => new ConstructorPropertyAssignmentTestScenario <TypeRepresentation> { Name = "GenericArguments should return null, when 'genericArguments' parameter passed to constructor is null, when getting", SystemUnderTestExpectedPropertyValueFunc = () => { var referenceObject = A.Dummy <TypeRepresentation>(); var result = new SystemUnderTestExpectedPropertyValue <TypeRepresentation> { SystemUnderTest = new TypeRepresentation( referenceObject.Namespace, referenceObject.Name, referenceObject.AssemblyName, referenceObject.AssemblyVersion, null), ExpectedPropertyValue = null, }; return(result); }, PropertyName = "GenericArguments", }); StringRepresentationTestScenarios .AddScenario(() => new StringRepresentationTestScenario <TypeRepresentation> { Name = "ToString should return the same string as BuildAssemblyQualifiedName() when called", SystemUnderTestExpectedStringRepresentationFunc = () => { var systemUnderTest = A.Dummy <TypeRepresentation>(); var result = new SystemUnderTestExpectedStringRepresentation <TypeRepresentation> { SystemUnderTest = systemUnderTest, ExpectedStringRepresentation = systemUnderTest.BuildAssemblyQualifiedName(), }; return(result); }, }) .AddScenario(() => new StringRepresentationTestScenario <TypeRepresentation> { Name = "ToString should return the Assembly Qualified Name when called", SystemUnderTestExpectedStringRepresentationFunc = () => { var systemUnderTest = typeof(IReadOnlyCollection <string> [, ]).ToRepresentation(); var result = new SystemUnderTestExpectedStringRepresentation <TypeRepresentation> { SystemUnderTest = systemUnderTest, ExpectedStringRepresentation = "System.Collections.Generic.IReadOnlyCollection`1[[System.String, mscorlib, Version=4.0.0.0]][,], mscorlib, Version=4.0.0.0", }; return(result); }, }); }
static CalendarMonthTest() { var referenceCalendarMonth = A.Dummy <CalendarMonth>(); ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarMonth> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' is < 0", ConstructionFunc = () => new CalendarMonth(A.Dummy <NegativeInteger>(), referenceCalendarMonth.MonthOfYear), ExpectedExceptionMessageContains = new[] { "'year' < '1'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarMonth> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' = 0", ConstructionFunc = () => new CalendarMonth(0, referenceCalendarMonth.MonthOfYear), ExpectedExceptionMessageContains = new[] { "'year' < '1'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarMonth> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' = 10000", ConstructionFunc = () => new CalendarMonth(10000, referenceCalendarMonth.MonthOfYear), ExpectedExceptionMessageContains = new[] { "'year' > '9999'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarMonth> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' > 9999", ConstructionFunc = () => new CalendarMonth(A.Dummy <PositiveInteger>().ThatIs(_ => _ > 9999, -1), referenceCalendarMonth.MonthOfYear), ExpectedExceptionMessageContains = new[] { "'year' > '9999'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarMonth> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'monthOfYear' is MonthOfYear.Invalid", ConstructionFunc = () => new CalendarMonth(referenceCalendarMonth.Year, MonthOfYear.Invalid), ExpectedExceptionMessageContains = new[] { "monthOfYear", "Invalid" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }); ComparableTestScenarios .RemoveAllScenarios() .AddScenario(() => new ComparableTestScenario <CalendarMonth> { Name = "Comparable Test Scenario", ReferenceObject = referenceCalendarMonth, ObjectsThatAreLessThanReferenceObject = new[] { referenceCalendarMonth.TweakBy(-1, CalendarMonthComponent.Month), referenceCalendarMonth.TweakBy(-1, CalendarMonthComponent.Year), }, ObjectsThatAreGreaterThanReferenceObject = new[] { referenceCalendarMonth.TweakBy(1, CalendarMonthComponent.Month), referenceCalendarMonth.TweakBy(1, CalendarMonthComponent.Year), }, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { referenceCalendarMonth.DeepClone(), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), } .Concat(TestCommon.GetDummyOfEachUnitOfTimeKind().Where(_ => _.GetType() != typeof(CalendarMonth))) .ToList(), ObjectsThatDeriveFromScenarioTypeButAreNotOfTheSameTypeAsReferenceObject = new CalendarMonth[] { }, }); StringRepresentationTestScenarios .RemoveAllScenarios() .AddScenario(() => new StringRepresentationTestScenario <CalendarMonth> { Name = "String Representation - case 1", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <CalendarMonth> { SystemUnderTest = new CalendarMonth(2017, MonthOfYear.November), ExpectedStringRepresentation = "2017-11", }, }) .AddScenario(() => new StringRepresentationTestScenario <CalendarMonth> { Name = "String Representation - case 2", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <CalendarMonth> { SystemUnderTest = new CalendarMonth(2017, MonthOfYear.February), ExpectedStringRepresentation = "2017-02", }, }); }
static ModelStringRepresentationPrivateSetMiscTest() { StringRepresentationTestScenarios.AddScenario(StringRepresentationTestScenario <ModelStringRepresentationPrivateSetMisc> .ForceGeneratedTestsToPassAndWriteMyOwnScenario); }
static FiscalMonthTest() { var referenceFiscalMonth = A.Dummy <FiscalMonth>(); ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario(() => new ConstructorArgumentValidationTestScenario <FiscalMonth> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' is < 0", ConstructionFunc = () => new FiscalMonth(A.Dummy <NegativeInteger>(), referenceFiscalMonth.MonthNumber), ExpectedExceptionMessageContains = new[] { "'year' < '1'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <FiscalMonth> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' = 0", ConstructionFunc = () => new FiscalMonth(0, referenceFiscalMonth.MonthNumber), ExpectedExceptionMessageContains = new[] { "'year' < '1'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <FiscalMonth> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' = 10000", ConstructionFunc = () => new FiscalMonth(10000, referenceFiscalMonth.MonthNumber), ExpectedExceptionMessageContains = new[] { "'year' > '9999'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <FiscalMonth> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' > 9999", ConstructionFunc = () => new FiscalMonth(A.Dummy <PositiveInteger>().ThatIs(_ => _ > 9999, -1), referenceFiscalMonth.MonthNumber), ExpectedExceptionMessageContains = new[] { "'year' > '9999'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <FiscalMonth> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'monthNumber' is MonthNumber.Invalid", ConstructionFunc = () => new FiscalMonth(referenceFiscalMonth.Year, MonthNumber.Invalid), ExpectedExceptionMessageContains = new[] { "monthNumber", "Invalid" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }); ComparableTestScenarios .RemoveAllScenarios() .AddScenario(() => new ComparableTestScenario <FiscalMonth> { Name = "Comparable Test Scenario", ReferenceObject = referenceFiscalMonth, ObjectsThatAreLessThanReferenceObject = new[] { referenceFiscalMonth.TweakBy(-1, FiscalMonthComponent.Month), referenceFiscalMonth.TweakBy(-1, FiscalMonthComponent.Year), }, ObjectsThatAreGreaterThanReferenceObject = new[] { referenceFiscalMonth.TweakBy(1, FiscalMonthComponent.Month), referenceFiscalMonth.TweakBy(1, FiscalMonthComponent.Year), }, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { referenceFiscalMonth.DeepClone(), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), } .Concat(TestCommon.GetDummyOfEachUnitOfTimeKind().Where(_ => _.GetType() != typeof(FiscalMonth))) .ToList(), ObjectsThatDeriveFromScenarioTypeButAreNotOfTheSameTypeAsReferenceObject = new FiscalMonth[] { }, }); StringRepresentationTestScenarios .RemoveAllScenarios() .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 1", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.One), ExpectedStringRepresentation = "1st month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 2", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Two), ExpectedStringRepresentation = "2nd month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 3", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Three), ExpectedStringRepresentation = "3rd month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 4", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Four), ExpectedStringRepresentation = "4th month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 5", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Five), ExpectedStringRepresentation = "5th month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 6", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Six), ExpectedStringRepresentation = "6th month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 7", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Seven), ExpectedStringRepresentation = "7th month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 8", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Eight), ExpectedStringRepresentation = "8th month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 9", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Nine), ExpectedStringRepresentation = "9th month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 10", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Ten), ExpectedStringRepresentation = "10th month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 11", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Eleven), ExpectedStringRepresentation = "11th month of FY2017", }, }) .AddScenario(() => new StringRepresentationTestScenario <FiscalMonth> { Name = "String Representation - case 12", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <FiscalMonth> { SystemUnderTest = new FiscalMonth(2017, MonthNumber.Twelve), ExpectedStringRepresentation = "12th month of FY2017", }, }); }
static ModelStringRepresentationPublicSetNullableTest() { StringRepresentationTestScenarios.AddScenario(StringRepresentationTestScenario <ModelStringRepresentationPublicSetNullable> .ForceGeneratedTestsToPassAndWriteMyOwnScenario); }
static ModelStringRepresentationPrivateSetReadOnlyCollectionOfNullableChild1Test() { StringRepresentationTestScenarios.AddScenario(StringRepresentationTestScenario <ModelStringRepresentationPrivateSetReadOnlyCollectionOfNullableChild1> .ForceGeneratedTestsToPassAndWriteMyOwnScenario); }
static CalendarDayTest() { var referenceCalendarDay = A.Dummy <CalendarDay>(); ConstructorArgumentValidationTestScenarios .RemoveAllScenarios() .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' is < 0", ConstructionFunc = () => new CalendarDay(A.Dummy <NegativeInteger>(), referenceCalendarDay.MonthOfYear, referenceCalendarDay.DayOfMonth), ExpectedExceptionMessageContains = new[] { "'year' < '1'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' = 0", ConstructionFunc = () => new CalendarDay(0, referenceCalendarDay.MonthOfYear, referenceCalendarDay.DayOfMonth), ExpectedExceptionMessageContains = new[] { "'year' < '1'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' = 10000", ConstructionFunc = () => new CalendarDay(10000, referenceCalendarDay.MonthOfYear, referenceCalendarDay.DayOfMonth), ExpectedExceptionMessageContains = new[] { "'year' > '9999'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' > 9999", ConstructionFunc = () => new CalendarDay(A.Dummy <PositiveInteger>().ThatIs(_ => _ > 9999, -1), referenceCalendarDay.MonthOfYear, referenceCalendarDay.DayOfMonth), ExpectedExceptionMessageContains = new[] { "'year' > '9999'" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'monthOfYear' is MonthOfYear.Invalid", ConstructionFunc = () => new CalendarDay(referenceCalendarDay.Year, MonthOfYear.Invalid, referenceCalendarDay.DayOfMonth), ExpectedExceptionMessageContains = new[] { "monthOfYear", "Invalid" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentOutOfRangeException when parameter 'dayOfMonth' is DayOfMonth.Invalid", ConstructionFunc = () => new CalendarDay(referenceCalendarDay.Year, referenceCalendarDay.MonthOfYear, DayOfMonth.Invalid), ExpectedExceptionMessageContains = new[] { "dayOfMonth", "Invalid" }, ExpectedExceptionType = typeof(ArgumentOutOfRangeException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentException when parameter 'dayOfMonth' is not a valid day in the specified 'year' and 'monthOfYear' - case 1", ConstructionFunc = () => new CalendarDay(2016, MonthOfYear.February, (DayOfMonth)30), ExpectedExceptionMessageContains = new[] { "day (Thirty) is not a valid day in the specified month (February) and year (2016)" }, ExpectedExceptionType = typeof(ArgumentException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentException when parameter 'dayOfMonth' is not a valid day in the specified 'year' and 'monthOfYear' - case 2", ConstructionFunc = () => new CalendarDay(2016, MonthOfYear.February, (DayOfMonth)31), ExpectedExceptionMessageContains = new[] { "day (ThirtyOne) is not a valid day in the specified month (February) and year (2016)" }, ExpectedExceptionType = typeof(ArgumentException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentException when parameter 'dayOfMonth' is not a valid day in the specified 'year' and 'monthOfYear' - case 3", ConstructionFunc = () => new CalendarDay(2015, MonthOfYear.February, (DayOfMonth)29), ExpectedExceptionMessageContains = new[] { "day (TwentyNine) is not a valid day in the specified month (February) and year (2015)" }, ExpectedExceptionType = typeof(ArgumentException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentException when parameter 'dayOfMonth' is not a valid day in the specified 'year' and 'monthOfYear' - case 4", ConstructionFunc = () => new CalendarDay(2015, MonthOfYear.February, (DayOfMonth)30), ExpectedExceptionMessageContains = new[] { "day (Thirty) is not a valid day in the specified month (February) and year (2015)" }, ExpectedExceptionType = typeof(ArgumentException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentException when parameter 'dayOfMonth' is not a valid day in the specified 'year' and 'monthOfYear' - case 5", ConstructionFunc = () => new CalendarDay(2015, MonthOfYear.February, (DayOfMonth)31), ExpectedExceptionMessageContains = new[] { "day (ThirtyOne) is not a valid day in the specified month (February) and year (2015)" }, ExpectedExceptionType = typeof(ArgumentException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentException when parameter 'dayOfMonth' is not a valid day in the specified 'year' and 'monthOfYear' - case 6", ConstructionFunc = () => new CalendarDay(2016, MonthOfYear.November, (DayOfMonth)31), ExpectedExceptionMessageContains = new[] { "day (ThirtyOne) is not a valid day in the specified month (November) and year (2016)" }, ExpectedExceptionType = typeof(ArgumentException), }) .AddScenario(() => new ConstructorArgumentValidationTestScenario <CalendarDay> { Name = "Constructor should throw ArgumentException when parameter 'dayOfMonth' is not a valid day in the specified 'year' and 'monthOfYear' - case 7", ConstructionFunc = () => new CalendarDay(2017, MonthOfYear.April, (DayOfMonth)31), ExpectedExceptionMessageContains = new[] { "day (ThirtyOne) is not a valid day in the specified month (April) and year (2017)" }, ExpectedExceptionType = typeof(ArgumentException), }); DeepCloneWithTestScenarios .RemoveAllScenarios() .AddScenario(() => new DeepCloneWithTestScenario <CalendarDay> { Name = Invariant($"{nameof(CalendarDay.DeepCloneWithYear)} should deep clone object and replace {nameof(CalendarDay.Year)} with the provided year"), WithPropertyName = nameof(CalendarDay.Year), SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <CalendarDay>(); var referenceObject = A.Dummy <CalendarDay>().ThatIs(_ => !systemUnderTest.Year.IsEqualTo(_.Year)); var result = new SystemUnderTestDeepCloneWithValue <CalendarDay> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.Year, }; return(result); }, }) .AddScenario(() => new DeepCloneWithTestScenario <CalendarDay> { Name = Invariant($"{nameof(CalendarDay.DeepCloneWithMonthOfYear)} should deep clone object and replace {nameof(CalendarDay.MonthOfYear)} with the provided monthOfYear"), WithPropertyName = nameof(CalendarDay.MonthOfYear), SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <CalendarDay>().ThatIs(_ => _.DayOfMonth <= DayOfMonth.TwentyEight); var referenceObject = A.Dummy <CalendarDay>().ThatIs(_ => !systemUnderTest.MonthOfYear.IsEqualTo(_.MonthOfYear)); var result = new SystemUnderTestDeepCloneWithValue <CalendarDay> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.MonthOfYear, }; return(result); }, }) .AddScenario(() => new DeepCloneWithTestScenario <CalendarDay> { Name = Invariant($"{nameof(CalendarDay.DeepCloneWithDayOfMonth)} should deep clone object and replace {nameof(CalendarDay.DayOfMonth)} with the provided dayOfMonth"), WithPropertyName = nameof(CalendarDay.DayOfMonth), SystemUnderTestDeepCloneWithValueFunc = () => { var systemUnderTest = A.Dummy <CalendarDay>().Whose(_ => new[] { MonthOfYear.January, MonthOfYear.March, MonthOfYear.March, MonthOfYear.July, MonthOfYear.August, MonthOfYear.October, MonthOfYear.December }.Contains(_.MonthOfYear)); var referenceObject = A.Dummy <CalendarDay>().ThatIs(_ => !systemUnderTest.DayOfMonth.IsEqualTo(_.DayOfMonth)); var result = new SystemUnderTestDeepCloneWithValue <CalendarDay> { SystemUnderTest = systemUnderTest, DeepCloneWithValue = referenceObject.DayOfMonth, }; return(result); }, }); EquatableTestScenarios .RemoveAllScenarios() .AddScenario(() => new EquatableTestScenario <CalendarDay> { Name = "Equatable Test Scenario", ReferenceObject = ReferenceObjectForEquatableTestScenarios, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { new CalendarDay( ReferenceObjectForEquatableTestScenarios.Year, ReferenceObjectForEquatableTestScenarios.MonthOfYear, ReferenceObjectForEquatableTestScenarios.DayOfMonth), }, ObjectsThatAreNotEqualToReferenceObject = new[] { ReferenceObjectForEquatableTestScenarios.Tweak(CalendarDayComponent.Day), ReferenceObjectForEquatableTestScenarios.Tweak(CalendarDayComponent.Month), ReferenceObjectForEquatableTestScenarios.Tweak(CalendarDayComponent.Year), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), } .Concat(TestCommon.GetDummyOfEachUnitOfTimeKind().Where(_ => _.GetType() != typeof(CalendarDay))) .ToList(), }); ComparableTestScenarios .RemoveAllScenarios() .AddScenario(() => new ComparableTestScenario <CalendarDay> { Name = "Comparable Test Scenario", ReferenceObject = referenceCalendarDay, ObjectsThatAreLessThanReferenceObject = new[] { referenceCalendarDay.TweakBy(-1, CalendarDayComponent.Day), referenceCalendarDay.TweakBy(-1, CalendarDayComponent.Month), referenceCalendarDay.TweakBy(-1, CalendarDayComponent.Year), }, ObjectsThatAreGreaterThanReferenceObject = new[] { referenceCalendarDay.TweakBy(1, CalendarDayComponent.Day), referenceCalendarDay.TweakBy(1, CalendarDayComponent.Month), referenceCalendarDay.TweakBy(1, CalendarDayComponent.Year), }, ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[] { referenceCalendarDay.DeepClone(), }, ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[] { A.Dummy <object>(), A.Dummy <string>(), A.Dummy <int>(), A.Dummy <int?>(), A.Dummy <Guid>(), A.Dummy <CalendarMonth>(), A.Dummy <CalendarQuarter>(), A.Dummy <CalendarUnbounded>(), A.Dummy <CalendarYear>(), A.Dummy <FiscalMonth>(), A.Dummy <FiscalQuarter>(), A.Dummy <FiscalUnbounded>(), A.Dummy <FiscalYear>(), A.Dummy <GenericMonth>(), A.Dummy <GenericQuarter>(), A.Dummy <GenericUnbounded>(), A.Dummy <GenericYear>(), }, ObjectsThatDeriveFromScenarioTypeButAreNotOfTheSameTypeAsReferenceObject = new CalendarDay[] { }, }); StringRepresentationTestScenarios .RemoveAllScenarios() .AddScenario(() => new StringRepresentationTestScenario <CalendarDay> { Name = "String Representation - case 1", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <CalendarDay> { SystemUnderTest = new CalendarDay(2017, MonthOfYear.November, DayOfMonth.Thirty), ExpectedStringRepresentation = "2017-11-30", }, }) .AddScenario(() => new StringRepresentationTestScenario <CalendarDay> { Name = "String Representation - case 2", SystemUnderTestExpectedStringRepresentationFunc = () => new SystemUnderTestExpectedStringRepresentation <CalendarDay> { SystemUnderTest = new CalendarDay(2017, MonthOfYear.February, DayOfMonth.Three), ExpectedStringRepresentation = "2017-02-03", }, }); }
static ModelStringRepresentationPublicSetReadOnlyDictionaryOfNullableChild2Test() { StringRepresentationTestScenarios.AddScenario(StringRepresentationTestScenario <ModelStringRepresentationPublicSetReadOnlyDictionaryOfNullableChild2> .ForceGeneratedTestsToPassAndWriteMyOwnScenario); }
static ModelStringRepresentationPrivateSetArrayOfNullableChild2Test() { StringRepresentationTestScenarios.AddScenario(StringRepresentationTestScenario <ModelStringRepresentationPrivateSetArrayOfNullableChild2> .ForceGeneratedTestsToPassAndWriteMyOwnScenario); }