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 GenericYearTest()
        {
            var referenceGenericYear = A.Dummy <GenericYear>();

            ConstructorArgumentValidationTestScenarios
            .RemoveAllScenarios()
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <GenericYear>
            {
                Name             = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' is < 0",
                ConstructionFunc = () => new GenericYear(A.Dummy <NegativeInteger>()),
                ExpectedExceptionMessageContains = new[] { "'year' < '1'" },
                ExpectedExceptionType            = typeof(ArgumentOutOfRangeException),
            })
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <GenericYear>
            {
                Name             = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' = 0",
                ConstructionFunc = () => new GenericYear(0),
                ExpectedExceptionMessageContains = new[] { "'year' < '1'" },
                ExpectedExceptionType            = typeof(ArgumentOutOfRangeException),
            })
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <GenericYear>
            {
                Name             = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' = 10000",
                ConstructionFunc = () => new GenericYear(10000),
                ExpectedExceptionMessageContains = new[] { "'year' > '9999'" },
                ExpectedExceptionType            = typeof(ArgumentOutOfRangeException),
            })
            .AddScenario(() =>
                         new ConstructorArgumentValidationTestScenario <GenericYear>
            {
                Name             = "Constructor should throw ArgumentOutOfRangeException when parameter 'year' > 9999",
                ConstructionFunc = () => new GenericYear(A.Dummy <PositiveInteger>().ThatIs(_ => _ > 9999, -1)),
                ExpectedExceptionMessageContains = new[] { "'year' > '9999'" },
                ExpectedExceptionType            = typeof(ArgumentOutOfRangeException),
            });

            ComparableTestScenarios
            .RemoveAllScenarios()
            .AddScenario(() =>
                         new ComparableTestScenario <GenericYear>
            {
                Name            = "Comparable Test Scenario",
                ReferenceObject = referenceGenericYear,
                ObjectsThatAreLessThanReferenceObject = new[]
                {
                    referenceGenericYear.TweakBy(-1),
                },
                ObjectsThatAreGreaterThanReferenceObject = new[]
                {
                    referenceGenericYear.TweakBy(1),
                },
                ObjectsThatAreEqualToButNotTheSameAsReferenceObject = new[]
                {
                    referenceGenericYear.DeepClone(),
                },
                ObjectsThatAreNotOfTheSameTypeAsReferenceObject = new[]
                {
                    A.Dummy <object>(),
                    A.Dummy <string>(),
                    A.Dummy <int>(),
                    A.Dummy <int?>(),
                    A.Dummy <Guid>(),
                }
                .Concat(TestCommon.GetDummyOfEachUnitOfTimeKind().Where(_ => _.GetType() != typeof(GenericYear)))
                .ToList(),
                ObjectsThatDeriveFromScenarioTypeButAreNotOfTheSameTypeAsReferenceObject = new GenericYear[]
                {
                },
            });

            StringRepresentationTestScenarios
            .RemoveAllScenarios()
            .AddScenario(() =>
                         new StringRepresentationTestScenario <GenericYear>
            {
                Name = "String Representation - case 1",
                SystemUnderTestExpectedStringRepresentationFunc = () =>
                                                                  new SystemUnderTestExpectedStringRepresentation <GenericYear>
                {
                    SystemUnderTest = new GenericYear(2017),
                    ExpectedStringRepresentation = "2017",
                },
            })
            .AddScenario(() =>
                         new StringRepresentationTestScenario <GenericYear>
            {
                Name = "String Representation - case 2",
                SystemUnderTestExpectedStringRepresentationFunc = () =>
                                                                  new SystemUnderTestExpectedStringRepresentation <GenericYear>
                {
                    SystemUnderTest = new GenericYear(2020),
                    ExpectedStringRepresentation = "2020",
                },
            });
        }
예제 #3
0
        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",
                },
            });
        }
예제 #4
0
        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",
                },
            });
        }