private static FiscalMonth TweakBy(
            this FiscalMonth fiscalMonth,
            int amount,
            FiscalMonthComponent componentToTweak)
        {
            if (componentToTweak == FiscalMonthComponent.Month)
            {
                var referenceMonth = new DateTime(fiscalMonth.Year, (int)fiscalMonth.MonthNumber, 1);

                var updatedMonth = referenceMonth.AddMonths(amount);

                var result = new FiscalMonth(updatedMonth.Year, (MonthNumber)updatedMonth.Month);

                return(result);
            }

            if (componentToTweak == FiscalMonthComponent.Year)
            {
                var result = new FiscalMonth(fiscalMonth.Year + amount, fiscalMonth.MonthNumber);

                return(result);
            }

            throw new NotSupportedException("this fiscal month component is not supported: " + componentToTweak);
        }
        public static void GetUnitsToDate___Should_return_all_months_from_month_1_to_lastUnitOfTimeInYear___When_lastUnitOfTimeInYear_is_of_type_FiscalMonth()
        {
            // Arrange
            var lastUnitOfTimeInYear1 = new FiscalMonth(2016, MonthNumber.One);
            var lastUnitOfTimeInYear2 = new FiscalMonth(2016, MonthNumber.Three);
            var lastUnitOfTimeInYear3 = new FiscalMonth(2016, MonthNumber.Twelve);

            var expectedUnitsToDate1 = new List <FiscalMonth> {
                lastUnitOfTimeInYear1
            };
            var expectedUnitsToDate2 = new List <FiscalMonth> {
                new FiscalMonth(2016, MonthNumber.One), new FiscalMonth(2016, MonthNumber.Two), new FiscalMonth(2016, MonthNumber.Three)
            };
            var expectedUnitsToDate3 = new List <FiscalMonth> {
                new FiscalMonth(2016, MonthNumber.One), new FiscalMonth(2016, MonthNumber.Two), new FiscalMonth(2016, MonthNumber.Three), new FiscalMonth(2016, MonthNumber.Four), new FiscalMonth(2016, MonthNumber.Five), new FiscalMonth(2016, MonthNumber.Six), new FiscalMonth(2016, MonthNumber.Seven), new FiscalMonth(2016, MonthNumber.Eight), new FiscalMonth(2016, MonthNumber.Nine), new FiscalMonth(2016, MonthNumber.Ten), new FiscalMonth(2016, MonthNumber.Eleven), new FiscalMonth(2016, MonthNumber.Twelve)
            };

            // Act
            var actualUnitsToDate1 = lastUnitOfTimeInYear1.GetUnitsToDate();
            var actualUnitsToDate2 = lastUnitOfTimeInYear2.GetUnitsToDate();
            var actualUnitsToDate3 = lastUnitOfTimeInYear3.GetUnitsToDate();

            // Assert
            actualUnitsToDate1.Should().Equal(expectedUnitsToDate1);
            actualUnitsToDate2.Should().Equal(expectedUnitsToDate2);
            actualUnitsToDate3.Should().Equal(expectedUnitsToDate3);
        }
Example #3
0
        public static void GreaterThanOrEqualToOperator___Should_return_true___When_left_side_of_operator_is_not_null_and_right_side_is_null()
        {
            // Arrange
            var         systemUnderTest1 = A.Dummy <FiscalMonth>();
            FiscalMonth systemUnderTest2 = null;

            // Act
            var result = systemUnderTest1 >= systemUnderTest2;

            // Assert
            result.Should().BeTrue();
        }
Example #4
0
        public static void CompareTo___Should_return_0___When_calling_non_typed_overload_and_test_object_is_equal_to_other_object()
        {
            // Arrange
            var systemUnderTest1 = A.Dummy <FiscalMonth>();
            var systemUnderTest2 = new FiscalMonth(systemUnderTest1.Year, systemUnderTest1.MonthNumber);

            // Act
            var result = systemUnderTest1.CompareTo((object)systemUnderTest2);

            // Assert
            result.Should().Be(0);
        }
Example #5
0
        public static void NotEqualsOperator___Should_return_false___When_objects_being_compared_have_same_property_values()
        {
            // Arrange
            var systemUnderTest1 = A.Dummy <FiscalMonth>();
            var systemUnderTest2 = new FiscalMonth(systemUnderTest1.Year, systemUnderTest1.MonthNumber);

            // Act
            var result = systemUnderTest1 != systemUnderTest2;

            // Assert
            result.Should().BeFalse();
        }
Example #6
0
        public static void CompareTo___Should_throw_ArgumentException___When_calling_non_typed_overload_and_other_object_is_null()
        {
            // Arrange
            var         systemUnderTest1 = A.Dummy <FiscalMonth>();
            FiscalMonth systemUnderTest2 = null;

            // Act
            var ex = Record.Exception(() => systemUnderTest1.CompareTo((object)systemUnderTest2));

            // Assert
            ex.Should().BeOfType <ArgumentException>();
        }
        public static void EqualsOperator___Should_return_true___When_objects_being_compared_have_same_property_values()
        {
            // Arrange
            var systemUnderTest1 = (FiscalUnitOfTime)A.Dummy <FiscalMonth>();
            var systemUnderTest2 = new FiscalMonth(((FiscalMonth)systemUnderTest1).Year, ((FiscalMonth)systemUnderTest1).MonthNumber);

            // Act
            var result = systemUnderTest1 == systemUnderTest2;

            // Assert
            result.Should().BeTrue();
        }
Example #8
0
        public static void GreaterThanOrEqualToOperator___Should_return_true___When_left_side_of_operator_is_equal_to_right_side()
        {
            // Arrange
            var systemUnderTest1 = A.Dummy <FiscalMonth>();
            var systemUnderTest2 = new FiscalMonth(systemUnderTest1.Year, systemUnderTest1.MonthNumber);

            // Act
            var result = systemUnderTest1 >= systemUnderTest2;

            // Assert
            result.Should().BeTrue();
        }
Example #9
0
        public static void GreaterThanOperator___Should_return_false___When_left_side_of_operator_is_null_and_right_side_is_not_null()
        {
            // Arrange
            FiscalMonth systemUnderTest1 = null;
            var         systemUnderTest2 = A.Dummy <FiscalMonth>();

            // Act
            var result = systemUnderTest1 > systemUnderTest2;

            // Assert
            result.Should().BeFalse();
        }
Example #10
0
        public static void GreaterThanOrEqualToOperator___Should_return_true___When_both_sides_of_operator_are_null()
        {
            // Arrange
            FiscalMonth systemUnderTest1 = null;
            FiscalMonth systemUnderTest2 = null;

            // Act
            var result = systemUnderTest1 >= systemUnderTest2;

            // Assert
            result.Should().BeTrue();
        }
Example #11
0
        public static void LessThanOperator___Should_return_false___When_both_sides_of_operator_are_null()
        {
            // Arrange
            FiscalMonth systemUnderTest1 = null;
            FiscalMonth systemUnderTest2 = null;

            // Act
            var result = systemUnderTest1 < systemUnderTest2;

            // Assert
            result.Should().BeFalse();
        }
Example #12
0
        public static void Equals___Should_return_true___When_calling_non_typed_overload_and_objects_being_compared_have_same_property_values()
        {
            // Arrange
            var systemUnderTest1 = A.Dummy <FiscalMonth>();
            var systemUnderTest2 = new FiscalMonth(systemUnderTest1.Year, systemUnderTest1.MonthNumber);

            // Act
            var result = systemUnderTest1.Equals((object)systemUnderTest2);

            // Assert
            result.Should().BeTrue();
        }
        public static void GetHashCode___Should_not_be_equal_for_two_UnitOfKind_objects___When_they_are_of_different_kinds_but_have_the_same_granularity_and_same_property_values()
        {
            // Arrange
            var calendarUnbounded = A.Dummy <CalendarUnbounded>();
            var fiscalUnbounded   = new FiscalUnbounded();
            var genericUnbounded  = new GenericUnbounded();

            var calendarYear = A.Dummy <CalendarYear>();
            var fiscalYear   = new FiscalYear(calendarYear.Year);
            var genericYear  = new GenericYear(calendarYear.Year);

            var calendarQuarter = A.Dummy <CalendarQuarter>();
            var fiscalQuarter   = new FiscalQuarter(calendarQuarter.Year, calendarQuarter.QuarterNumber);
            var genericQuarter  = new GenericQuarter(calendarQuarter.Year, calendarQuarter.QuarterNumber);

            var calendarMonth = A.Dummy <CalendarMonth>();
            var fiscalMonth   = new FiscalMonth(calendarMonth.Year, calendarMonth.MonthNumber);
            var genericMonth  = new GenericMonth(calendarMonth.Year, calendarMonth.MonthNumber);

            // Act
            var calendarUnboundedHashCode = calendarUnbounded.GetHashCode();
            var fiscalUnboundedHashCode   = fiscalUnbounded.GetHashCode();
            var genericUnboundedHashCode  = genericUnbounded.GetHashCode();

            var calendarYearHashCode = calendarYear.GetHashCode();
            var fiscalYearHashCode   = fiscalYear.GetHashCode();
            var genericYearHashCode  = genericYear.GetHashCode();

            var calendarQuarterHashCode = calendarQuarter.GetHashCode();
            var fiscalQuarterHashCode   = fiscalQuarter.GetHashCode();
            var genericQuarterHashCode  = genericQuarter.GetHashCode();

            var calendarMonthHashCode = calendarMonth.GetHashCode();
            var fiscalMonthHashCode   = fiscalMonth.GetHashCode();
            var genericMonthHashCode  = genericMonth.GetHashCode();

            // Assert
            calendarUnboundedHashCode.Should().NotBe(fiscalUnboundedHashCode);
            calendarUnboundedHashCode.Should().NotBe(genericUnboundedHashCode);
            fiscalUnboundedHashCode.Should().NotBe(genericUnboundedHashCode);

            calendarYearHashCode.Should().NotBe(fiscalYearHashCode);
            calendarYearHashCode.Should().NotBe(genericYearHashCode);
            fiscalYearHashCode.Should().NotBe(genericYearHashCode);

            calendarQuarterHashCode.Should().NotBe(fiscalQuarterHashCode);
            calendarQuarterHashCode.Should().NotBe(genericQuarterHashCode);
            fiscalQuarterHashCode.Should().NotBe(genericQuarterHashCode);

            calendarMonthHashCode.Should().NotBe(fiscalMonthHashCode);
            calendarMonthHashCode.Should().NotBe(genericMonthHashCode);
            fiscalMonthHashCode.Should().NotBe(genericMonthHashCode);
        }
Example #14
0
        public static void GetHashCode___Should_be_equal_for_two_FiscalMonths___When_both_objects_have_the_same_property_values()
        {
            // Arrange
            var systemUnderTest1 = A.Dummy <FiscalMonth>();
            var systemUnderTest2 = new FiscalMonth(systemUnderTest1.Year, systemUnderTest1.MonthNumber);

            // Act
            var hash1 = systemUnderTest1.GetHashCode();
            var hash2 = systemUnderTest2.GetHashCode();

            // Assert
            hash1.Should().Be(hash2);
        }
Example #15
0
        public static void NotEqualsOperator___Should_return_true___When_one_side_of_operator_is_null_and_the_other_side_is_not_null()
        {
            // Arrange
            FiscalMonth systemUnderTest1 = null;
            var         systemUnderTest2 = A.Dummy <FiscalMonth>();

            // Act
            var result1 = systemUnderTest1 != systemUnderTest2;
            var result2 = systemUnderTest2 != systemUnderTest1;

            // Assert
            result1.Should().BeTrue();
            result2.Should().BeTrue();
        }
Example #16
0
        public static void MonthNumber___Should_return_same_monthNumber_passed_to_constructor___When_getting()
        {
            // Arrange
            var validMonth = A.Dummy <FiscalMonth>();

            var year        = validMonth.Year;
            var monthNumber = validMonth.MonthNumber;

            var systemUnderTest = new FiscalMonth(year, monthNumber);

            // Act
            var actualMonthNumber = systemUnderTest.MonthNumber;

            // Assert
            actualMonthNumber.Should().Be(monthNumber);
        }
Example #17
0
        private static FiscalMonth TweakComponentOfFiscalMonth(this FiscalMonth fiscalMonth, FiscalMonthComponent componentToTweak)
        {
            if (componentToTweak == FiscalMonthComponent.Month)
            {
                var tweakedMonth = A.Dummy <MonthNumber>().ThatIsNot(fiscalMonth.MonthNumber);
                var result       = new FiscalMonth(fiscalMonth.Year, tweakedMonth);
                return(result);
            }

            if (componentToTweak == FiscalMonthComponent.Year)
            {
                var tweakedYear = A.Dummy <PositiveInteger>().ThatIs(y => y != fiscalMonth.Year && y <= 9999);
                var result      = new FiscalMonth(tweakedYear, fiscalMonth.MonthNumber);
                return(result);
            }

            throw new NotSupportedException("this fiscal month component is not supported: " + componentToTweak);
        }
Example #18
0
        public static void ToString___Should_return_friendly_string_representation_of_object___When_called()
        {
            // Arrange
            var systemUnderTest1  = new FiscalMonth(2017, MonthNumber.One);
            var systemUnderTest2  = new FiscalMonth(2017, MonthNumber.Two);
            var systemUnderTest3  = new FiscalMonth(2017, MonthNumber.Three);
            var systemUnderTest4  = new FiscalMonth(2017, MonthNumber.Four);
            var systemUnderTest5  = new FiscalMonth(2017, MonthNumber.Five);
            var systemUnderTest6  = new FiscalMonth(2017, MonthNumber.Six);
            var systemUnderTest7  = new FiscalMonth(2017, MonthNumber.Seven);
            var systemUnderTest8  = new FiscalMonth(2017, MonthNumber.Eight);
            var systemUnderTest9  = new FiscalMonth(2017, MonthNumber.Nine);
            var systemUnderTest10 = new FiscalMonth(2017, MonthNumber.Ten);
            var systemUnderTest11 = new FiscalMonth(2017, MonthNumber.Eleven);
            var systemUnderTest12 = new FiscalMonth(2017, MonthNumber.Twelve);

            // Act
            var toString1  = systemUnderTest1.ToString();
            var toString2  = systemUnderTest2.ToString();
            var toString3  = systemUnderTest3.ToString();
            var toString4  = systemUnderTest4.ToString();
            var toString5  = systemUnderTest5.ToString();
            var toString6  = systemUnderTest6.ToString();
            var toString7  = systemUnderTest7.ToString();
            var toString8  = systemUnderTest8.ToString();
            var toString9  = systemUnderTest9.ToString();
            var toString10 = systemUnderTest10.ToString();
            var toString11 = systemUnderTest11.ToString();
            var toString12 = systemUnderTest12.ToString();

            // Assert
            toString1.Should().Be("1st month of FY2017");
            toString2.Should().Be("2nd month of FY2017");
            toString3.Should().Be("3rd month of FY2017");
            toString4.Should().Be("4th month of FY2017");
            toString5.Should().Be("5th month of FY2017");
            toString6.Should().Be("6th month of FY2017");
            toString7.Should().Be("7th month of FY2017");
            toString8.Should().Be("8th month of FY2017");
            toString9.Should().Be("9th month of FY2017");
            toString10.Should().Be("10th month of FY2017");
            toString11.Should().Be("11th month of FY2017");
            toString12.Should().Be("12th month of FY2017");
        }
Example #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AccountingTimeDummyFactory"/> class.
        /// </summary>
        public AccountingTimeDummyFactory()
        {
            // ------------------------------------------------------------------------------------
            // ---------------------------  accounting period system ------------------------------
            // ------------------------------------------------------------------------------------
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(FiftyTwoFiftyThreeWeekMethodology.Unknown);

            AutoFixtureBackedDummyFactory.UseRandomConcreteSubclassForDummy <AccountingPeriodSystem>();

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var result = new FiscalYearAccountingPeriodSystem(A.Dummy <MonthOfYear>().ThatIsNot(MonthOfYear.December));

                return(result);
            });

            // ------------------------------------------------------------------------------------
            // -------------------------------------  time ----------------------------------------
            // ------------------------------------------------------------------------------------
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(DayOfMonth.Invalid);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(MonthNumber.Invalid);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(MonthOfYear.Invalid);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(QuarterNumber.Invalid);

            AutoFixtureBackedDummyFactory.UseRandomConcreteSubclassForDummy <UnitOfTime>();
            AutoFixtureBackedDummyFactory.UseRandomConcreteSubclassForDummy <CalendarUnitOfTime>();
            AutoFixtureBackedDummyFactory.UseRandomConcreteSubclassForDummy <FiscalUnitOfTime>();
            AutoFixtureBackedDummyFactory.UseRandomConcreteSubclassForDummy <GenericUnitOfTime>();

            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IHaveAMonth>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IHaveAQuarter>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IHaveAYear>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IAmBoundedTime>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IAmUnboundedTime>();

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year = ThreadSafeRandom.Next(MinYear, MaxYear + 1);

                var result = new GenericMonth(year, A.Dummy <MonthNumber>());

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year = ThreadSafeRandom.Next(MinYear, MaxYear + 1);

                var result = new GenericQuarter(year, A.Dummy <QuarterNumber>());

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year = ThreadSafeRandom.Next(MinYear, MaxYear + 1);

                var result = new GenericYear(year);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year = ThreadSafeRandom.Next(MinYear, MaxYear + 1);

                var result = new FiscalMonth(year, A.Dummy <MonthNumber>());

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year = ThreadSafeRandom.Next(MinYear, MaxYear + 1);

                var result = new FiscalQuarter(year, A.Dummy <QuarterNumber>());

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year = ThreadSafeRandom.Next(MinYear, MaxYear + 1);

                var result = new FiscalYear(year);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                while (true)
                {
                    try
                    {
                        var date = A.Dummy <DateTime>();

                        var year = ThreadSafeRandom.Next(MinYear, MaxYear + 1);

                        var result = new CalendarDay(year, (MonthOfYear)date.Month, (DayOfMonth)date.Day);

                        return(result);
                    }
                    catch (ArgumentException)
                    {
                    }
                }
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year = ThreadSafeRandom.Next(MinYear, MaxYear + 1);

                var result = new CalendarMonth(year, A.Dummy <MonthOfYear>());

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year = ThreadSafeRandom.Next(MinYear, MaxYear + 1);

                var result = new CalendarQuarter(year, A.Dummy <QuarterNumber>());

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year = ThreadSafeRandom.Next(MinYear, MaxYear + 1);

                var result = new CalendarYear(year);

                return(result);
            });

            // ------------------------------------------------------------------------------------
            // ------------------------------  reporting period -----------------------------------
            // ------------------------------------------------------------------------------------
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(ReportingPeriodComponent.Invalid);

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var potentialTypes = new[] { typeof(GenericReportingPeriod), typeof(FiscalReportingPeriod), typeof(CalendarReportingPeriod) };

                var result = GetRandomReportingPeriodWrapper(potentialTypes).ReportingPeriod;

                return(result);
            });

            // ------------------------------------------------------------------------------------
            // -------------------------------------  unit ----------------------------------------
            // ------------------------------------------------------------------------------------
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(UnitOfTimeKind.Invalid);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(UnitOfTimeGranularity.Invalid);

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var unitOfTime = A.Dummy <UnitOfTime>().ThatIs(_ => !(_ is IAmUnboundedTime));

                var result = new Unit(unitOfTime.UnitOfTimeKind, unitOfTime.UnitOfTimeGranularity);

                return(result);
            });

            // ------------------------------------------------------------------------------------
            // --------------------------  reporting period wrappers ------------------------------
            // ------------------------------------------------------------------------------------
            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var start = A.Dummy <GenericMonth>();

                var end = A.Dummy <GenericMonth>();

                var result = end >= start
                        ? new GenericMonthReportingPeriod(start, end)
                        : new GenericMonthReportingPeriod(end, start);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var start = A.Dummy <GenericQuarter>();

                var end = A.Dummy <GenericQuarter>();

                var result = end >= start
                        ? new GenericQuarterReportingPeriod(start, end)
                        : new GenericQuarterReportingPeriod(end, start);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var start = A.Dummy <GenericYear>();

                var end = A.Dummy <GenericYear>();

                var result = end >= start
                        ? new GenericYearReportingPeriod(start, end)
                        : new GenericYearReportingPeriod(end, start);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var start = A.Dummy <FiscalMonth>();

                var end = A.Dummy <FiscalMonth>();

                var result = end >= start
                        ? new FiscalMonthReportingPeriod(start, end)
                        : new FiscalMonthReportingPeriod(end, start);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var start = A.Dummy <FiscalQuarter>();

                var end = A.Dummy <FiscalQuarter>();

                var result = end >= start
                        ? new FiscalQuarterReportingPeriod(start, end)
                        : new FiscalQuarterReportingPeriod(end, start);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var start = A.Dummy <FiscalYear>();

                var end = A.Dummy <FiscalYear>();

                var result = end >= start
                        ? new FiscalYearReportingPeriod(start, end)
                        : new FiscalYearReportingPeriod(end, start);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var start = A.Dummy <CalendarDay>();

                var end = A.Dummy <CalendarDay>();

                var result = end >= start
                        ? new CalendarDayReportingPeriod(start, end)
                        : new CalendarDayReportingPeriod(end, start);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var start = A.Dummy <CalendarMonth>();

                var end = A.Dummy <CalendarMonth>();

                var result = end >= start
                        ? new CalendarMonthReportingPeriod(start, end)
                        : new CalendarMonthReportingPeriod(end, start);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var start = A.Dummy <CalendarQuarter>();

                var end = A.Dummy <CalendarQuarter>();

                var result = end >= start
                        ? new CalendarQuarterReportingPeriod(start, end)
                        : new CalendarQuarterReportingPeriod(end, start);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var start = A.Dummy <CalendarYear>();

                var end = A.Dummy <CalendarYear>();

                var result = end >= start
                        ? new CalendarYearReportingPeriod(start, end)
                        : new CalendarYearReportingPeriod(end, start);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var potentialTypes = new[] { typeof(BoundedGenericReportingPeriod), typeof(BoundedFiscalReportingPeriod), typeof(BoundedCalendarReportingPeriod) };

                var reportingPeriod = GetRandomReportingPeriodWrapper(potentialTypes).ReportingPeriod;

                var result = new BoundedReportingPeriod(reportingPeriod.Start, reportingPeriod.End);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var potentialTypes = new[] { typeof(GenericMonthReportingPeriod), typeof(GenericQuarterReportingPeriod), typeof(GenericYearReportingPeriod) };

                var reportingPeriod = GetRandomReportingPeriodWrapper(potentialTypes).ReportingPeriod;

                var result = new BoundedGenericReportingPeriod((GenericUnitOfTime)reportingPeriod.Start, (GenericUnitOfTime)reportingPeriod.End);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var potentialTypes = new[] { typeof(FiscalMonthReportingPeriod), typeof(FiscalQuarterReportingPeriod), typeof(FiscalYearReportingPeriod) };

                var reportingPeriod = GetRandomReportingPeriodWrapper(potentialTypes).ReportingPeriod;

                var result = new BoundedFiscalReportingPeriod((FiscalUnitOfTime)reportingPeriod.Start, (FiscalUnitOfTime)reportingPeriod.End);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var potentialTypes = new[] { typeof(CalendarDayReportingPeriod), typeof(CalendarMonthReportingPeriod), typeof(CalendarQuarterReportingPeriod), typeof(CalendarYearReportingPeriod) };

                var reportingPeriod = GetRandomReportingPeriodWrapper(potentialTypes).ReportingPeriod;

                var result = new BoundedCalendarReportingPeriod((CalendarUnitOfTime)reportingPeriod.Start, (CalendarUnitOfTime)reportingPeriod.End);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var boundedReportingPeriod = A.Dummy <BoundedGenericReportingPeriod>().ReportingPeriod;

                var result = ThreadSafeRandom.Next(0, 2) == 0
                        ? new SemiBoundedGenericReportingPeriod((GenericUnitOfTime)boundedReportingPeriod.Start, new GenericUnbounded())
                        : new SemiBoundedGenericReportingPeriod(new GenericUnbounded(), (GenericUnitOfTime)boundedReportingPeriod.End);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var boundedReportingPeriod = A.Dummy <BoundedFiscalReportingPeriod>().ReportingPeriod;

                var result = ThreadSafeRandom.Next(0, 2) == 0
                        ? new SemiBoundedFiscalReportingPeriod((FiscalUnitOfTime)boundedReportingPeriod.Start, new FiscalUnbounded())
                        : new SemiBoundedFiscalReportingPeriod(new FiscalUnbounded(), (FiscalUnitOfTime)boundedReportingPeriod.End);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var boundedReportingPeriod = A.Dummy <BoundedCalendarReportingPeriod>().ReportingPeriod;

                var result = ThreadSafeRandom.Next(0, 2) == 0
                        ? new SemiBoundedCalendarReportingPeriod((CalendarUnitOfTime)boundedReportingPeriod.Start, new CalendarUnbounded())
                        : new SemiBoundedCalendarReportingPeriod(new CalendarUnbounded(), (CalendarUnitOfTime)boundedReportingPeriod.End);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var potentialTypes = new[] { typeof(GenericUnboundedReportingPeriod), typeof(SemiBoundedGenericReportingPeriod), typeof(BoundedGenericReportingPeriod) };

                var reportingPeriod = GetRandomReportingPeriodWrapper(potentialTypes).ReportingPeriod;

                var result = new GenericReportingPeriod((GenericUnitOfTime)reportingPeriod.Start, (GenericUnitOfTime)reportingPeriod.End);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var potentialTypes = new[] { typeof(FiscalUnboundedReportingPeriod), typeof(SemiBoundedFiscalReportingPeriod), typeof(BoundedFiscalReportingPeriod) };

                var reportingPeriod = GetRandomReportingPeriodWrapper(potentialTypes).ReportingPeriod;

                var result = new FiscalReportingPeriod((FiscalUnitOfTime)reportingPeriod.Start, (FiscalUnitOfTime)reportingPeriod.End);

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var potentialTypes = new[] { typeof(CalendarUnboundedReportingPeriod), typeof(SemiBoundedCalendarReportingPeriod), typeof(BoundedCalendarReportingPeriod) };

                var reportingPeriod = GetRandomReportingPeriodWrapper(potentialTypes).ReportingPeriod;

                var result = new CalendarReportingPeriod((CalendarUnitOfTime)reportingPeriod.Start, (CalendarUnitOfTime)reportingPeriod.End);

                return(result);
            });

            // ------------------------------------------------------------------------------------
            // ------------------------------------  cutoff ---------------------------------------
            // ------------------------------------------------------------------------------------
            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var result = new RelativeCutoff(A.Dummy <Duration>(), A.Dummy <ReportingPeriodComponent>().ThatIsIn(new[] { ReportingPeriodComponent.Start, ReportingPeriodComponent.End }));

                return(result);
            });

            // ------------------------------------------------------------------------------------
            // ----------------------------------  timeseries -------------------------------------
            // ------------------------------------------------------------------------------------
            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var result = (IDatapoint)A.Dummy <Datapoint <Version> >();

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var result = (ITimeseries)A.Dummy <Timeseries <Version> >();

                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var result = GetDummyTimeseries <Version>();

                return(result);
            });
        }
        public AccountingTimeDummyFactory()
        {
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(DayOfMonth.Invalid);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(MonthNumber.Invalid);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(MonthOfYear.Invalid);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(QuarterNumber.Invalid);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(UnitOfTimeKind.Invalid);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(UnitOfTimeGranularity.Invalid);
            AutoFixtureBackedDummyFactory.ConstrainDummyToExclude(ReportingPeriodComponent.Invalid);

            AutoFixtureBackedDummyFactory.UseRandomConcreteSubclassForDummy <UnitOfTime>();
            AutoFixtureBackedDummyFactory.UseRandomConcreteSubclassForDummy <CalendarUnitOfTime>();
            AutoFixtureBackedDummyFactory.UseRandomConcreteSubclassForDummy <FiscalUnitOfTime>();
            AutoFixtureBackedDummyFactory.UseRandomConcreteSubclassForDummy <GenericUnitOfTime>();

            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IHaveAMonth>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IHaveAQuarter>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IHaveAYear>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IAmBoundedTime>();
            AutoFixtureBackedDummyFactory.UseRandomInterfaceImplementationForDummy <IAmUnboundedTime>();

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year   = ThreadSafeRandom.Next(MinYear, MaxYear + 1);
                var result = new GenericMonth(year, A.Dummy <MonthNumber>());
                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year   = ThreadSafeRandom.Next(MinYear, MaxYear + 1);
                var result = new GenericQuarter(year, A.Dummy <QuarterNumber>());
                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year   = ThreadSafeRandom.Next(MinYear, MaxYear + 1);
                var result = new GenericYear(year);
                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year   = ThreadSafeRandom.Next(MinYear, MaxYear + 1);
                var result = new FiscalMonth(year, A.Dummy <MonthNumber>());
                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year   = ThreadSafeRandom.Next(MinYear, MaxYear + 1);
                var result = new FiscalQuarter(year, A.Dummy <QuarterNumber>());
                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year   = ThreadSafeRandom.Next(MinYear, MaxYear + 1);
                var result = new FiscalYear(year);
                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                while (true)
                {
                    try
                    {
                        var date   = A.Dummy <DateTime>();
                        var year   = ThreadSafeRandom.Next(MinYear, MaxYear + 1);
                        var result = new CalendarDay(year, (MonthOfYear)date.Month, (DayOfMonth)date.Day);
                        return(result);
                    }
                    catch (ArgumentException)
                    {
                    }
                }
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year   = ThreadSafeRandom.Next(MinYear, MaxYear + 1);
                var result = new CalendarMonth(year, A.Dummy <MonthOfYear>());
                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year   = ThreadSafeRandom.Next(MinYear, MaxYear + 1);
                var result = new CalendarQuarter(year, A.Dummy <QuarterNumber>());
                return(result);
            });

            AutoFixtureBackedDummyFactory.AddDummyCreator(
                () =>
            {
                var year   = ThreadSafeRandom.Next(MinYear, MaxYear + 1);
                var result = new CalendarYear(year);
                return(result);
            });

            AddDummyCreatorForAbstractReportingPeriod <UnitOfTime>();
            AddDummyCreatorForAbstractReportingPeriod <CalendarUnitOfTime>();
            AddDummyCreatorForAbstractReportingPeriod <FiscalUnitOfTime>();
            AddDummyCreatorForAbstractReportingPeriod <GenericUnitOfTime>();
            AddDummyCreatorForConcreteReportingPeriod <CalendarDay>();
            AddDummyCreatorForConcreteReportingPeriod <CalendarQuarter>();
            AddDummyCreatorForConcreteReportingPeriod <CalendarMonth>();
            AddDummyCreatorForConcreteReportingPeriod <CalendarYear>();
            AddDummyCreatorForConcreteReportingPeriod <CalendarUnbounded>();
            AddDummyCreatorForConcreteReportingPeriod <FiscalMonth>();
            AddDummyCreatorForConcreteReportingPeriod <FiscalQuarter>();
            AddDummyCreatorForConcreteReportingPeriod <FiscalYear>();
            AddDummyCreatorForConcreteReportingPeriod <FiscalUnbounded>();
            AddDummyCreatorForConcreteReportingPeriod <GenericMonth>();
            AddDummyCreatorForConcreteReportingPeriod <GenericQuarter>();
            AddDummyCreatorForConcreteReportingPeriod <GenericYear>();
            AddDummyCreatorForConcreteReportingPeriod <GenericUnbounded>();
        }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FiscalMonthReportingPeriod"/> class.
 /// </summary>
 /// <param name="start">The start of the reporting period.</param>
 /// <param name="end">The end of the reporting period.</param>
 public FiscalMonthReportingPeriod(
     FiscalMonth start,
     FiscalMonth end)
     : base(start, end)
 {
 }