Exemplo n.º 1
0
        public void MinCalendarYear_EqualsYear1()
        {
            var minCalYear = CalendarYear.MinCalendarYear;
            var year1      = new CalendarYear(1);

            Assert.AreEqual(year1, minCalYear);
        }
Exemplo n.º 2
0
        public void End_ShouldEqualDateTimeForStartOfNextYear(int yearNum)
        {
            var calendarYear = new CalendarYear(yearNum);
            var expectedEnd  = new DateTime(yearNum + 1, 1, 1);

            Assert.AreEqual(expectedEnd, calendarYear.End);
        }
        private static CalendarYear TweakYear(this CalendarYear calendarYear)
        {
            var tweakedYear = A.Dummy <PositiveInteger>().ThatIs(y => y != calendarYear.Year && y <= 9999);
            var result      = new CalendarYear(tweakedYear);

            return(result);
        }
Exemplo n.º 4
0
        private static void OffsetOperators()
        {
            #region offset_operators
            var calYear19 = new CalendarYear(2019);

            CalendarYear calYear22 = calYear19 + 3;
            Console.WriteLine(calYear22);

            int yearsDifference = calYear22 - calYear19;
            Console.WriteLine(yearsDifference);

            // The increment ++, and decrement --, operators can also be used
            var halfHour = new HalfHour(2019, 8, 30, 22, 0);

            Console.WriteLine();
            Console.WriteLine("Incrementing Half Hour");
            Console.WriteLine(halfHour);
            halfHour++;
            Console.WriteLine(halfHour);
            halfHour++;
            Console.WriteLine(halfHour);

            Console.WriteLine();
            Console.WriteLine("Decrementing Half Hour");
            halfHour--;
            Console.WriteLine(halfHour);
            halfHour--;
            Console.WriteLine(halfHour);
            halfHour--;
            Console.WriteLine(halfHour);
            Console.WriteLine();
            #endregion offset_operators
        }
Exemplo n.º 5
0
        public void MaxCalendarYear_EqualsYear9998()
        {
            var maxCalYear = CalendarYear.MaxCalendarYear;
            var year9998   = new CalendarYear(9998);

            Assert.AreEqual(year9998, maxCalYear);
        }
Exemplo n.º 6
0
        public void GetHashCode_OnTwoDifferentInstances_ReturnDifferentValue(int yearNum1, int yearNum2)
        {
            var calYear1 = new CalendarYear(yearNum1);
            var calYear2 = new CalendarYear(yearNum2);

            Assert.AreNotEqual(calYear1.GetHashCode(), calYear2.GetHashCode());
        }
Exemplo n.º 7
0
        public void IComparableCompareTo_WithParameterEqualToNull_Returns1(int yearNum)
        {
            IComparable calYear = new CalendarYear(yearNum);
            var         comp    = calYear.CompareTo(null);

            Assert.AreEqual(1, comp);
        }
Exemplo n.º 8
0
        public void LessThanOrEqualToOperator_WithLeftLaterThanRight_ReturnsFalse(int leftYearNum, int rightYearNum)
        {
            var calYear1 = new CalendarYear(leftYearNum);
            var calYear2 = new CalendarYear(rightYearNum);

            Assert.IsFalse(calYear1 <= calYear2);
        }
Exemplo n.º 9
0
        public void Start_ShouldEqualDateTimeForStartOfYear(int yearNum)
        {
            var calendarYear  = new CalendarYear(yearNum);
            var expectedStart = new DateTime(yearNum, 1, 1);

            Assert.AreEqual(expectedStart, calendarYear.Start);
        }
Exemplo n.º 10
0
        public void LessThanOperator_WithLeftEarlierThanRight_ReturnsTrue(int leftYearNum, int rightYearNum)
        {
            var calYear1 = new CalendarYear(leftYearNum);
            var calYear2 = new CalendarYear(rightYearNum);

            Assert.IsTrue(calYear1 < calYear2);
        }
Exemplo n.º 11
0
        public void GreaterThanOrEqualToOperator_WithLeftLaterThanOrEqualToRight_ReturnsTrue(int leftYearNum, int rightYearNum)
        {
            var calYear1 = new CalendarYear(leftYearNum);
            var calYear2 = new CalendarYear(rightYearNum);

            Assert.IsTrue(calYear1 >= calYear2);
        }
Exemplo n.º 12
0
        public void InequalityOperator_WithTwoIdenticalInstances_ReturnsFalse(int yearNum)
        {
            var calYear1 = new CalendarYear(yearNum);
            var calYear2 = new CalendarYear(yearNum);

            Assert.IsFalse(calYear1 != calYear2);
        }
Exemplo n.º 13
0
        public void InequalityOperator_WithTwoDifferentInstances_ReturnsTrue(int leftYearNum, int rightYearNum)
        {
            var calYear1 = new CalendarYear(leftYearNum);
            var calYear2 = new CalendarYear(rightYearNum);

            Assert.IsTrue(calYear1 != calYear2);
        }
Exemplo n.º 14
0
        public void DefaultConstructor_ReturnsInstanceEqualToYear1()
        {
            var calYear = new CalendarYear();
            var year1   = new CalendarYear(1);

            Assert.AreEqual(year1, calYear);
        }
Exemplo n.º 15
0
        public void GetHashCode_OnTwoIdenticalInstances_ReturnSameValue(int yearNum)
        {
            var calYear1 = new CalendarYear(yearNum);
            var calYear2 = new CalendarYear(yearNum);

            Assert.AreEqual(calYear1.GetHashCode(), calYear2.GetHashCode());
        }
Exemplo n.º 16
0
        public void IComparableCompareTo_WithParameterLaterThanInstance_ReturnsNegativeNumber(int yearNumInstance, int yearNumParameter)
        {
            IComparable calYear1 = new CalendarYear(yearNumInstance);
            object      calYear2 = new CalendarYear(yearNumParameter);
            var         comp     = calYear1.CompareTo(calYear2);

            Assert.That(comp, Is.LessThan(0));
        }
Exemplo n.º 17
0
        public void IComparableCompareTo_WithParameterNotOfCalendarYearType_ThrowsArgumentException(int yearNum)
        {
            IComparable calYear = new CalendarYear(yearNum);
            object      obj     = new object();

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.Throws <ArgumentException>(() => calYear.CompareTo(obj));
        }
Exemplo n.º 18
0
        public void IComparableCompareTo_WithParameterIdenticalToInstance_ReturnsZero(int yearNum)
        {
            IComparable calYear1 = new CalendarYear(yearNum);
            object      calYear2 = new CalendarYear(yearNum);
            var         comp     = calYear1.CompareTo(calYear2);

            Assert.AreEqual(0, comp);
        }
Exemplo n.º 19
0
        public void CompareTo_WithParameterEarlierThanInstance_ReturnsPositiveNumber(int yearNumInstance, int yearNumParameter)
        {
            var calYear1 = new CalendarYear(yearNumInstance);
            var calYear2 = new CalendarYear(yearNumParameter);
            var comp     = calYear1.CompareTo(calYear2);

            Assert.That(comp, Is.GreaterThan(0));
        }
Exemplo n.º 20
0
        public void ObjectEquals_WithParameterNotOfTypeCalendarYear_ReturnsFalse(int yearNum)
        {
            object calYear = new CalendarYear(yearNum);
            object obj     = new object();
            var    equals  = calYear.Equals(obj);

            Assert.IsFalse(equals);
        }
Exemplo n.º 21
0
        public void ObjectEquals_WithTwoDifferentInstances_ReturnsFalse(int yearNum1, int yearNum2)
        {
            object calYear1 = new CalendarYear(yearNum1);
            object calYear2 = new CalendarYear(yearNum2);
            var    equals   = calYear1.Equals(calYear2);

            Assert.IsFalse(equals);
        }
Exemplo n.º 22
0
        public void ObjectEquals_WithTwoIdenticalInstances_ReturnsTrue(int yearNum)
        {
            object calYear1 = new CalendarYear(yearNum);
            object calYear2 = new CalendarYear(yearNum);
            var    equals   = calYear1.Equals(calYear2);

            Assert.IsTrue(equals);
        }
        private static CalendarYear TweakBy(
            this CalendarYear calendarYear,
            int amount)
        {
            var result = new CalendarYear(calendarYear.Year + amount);

            return(result);
        }
Exemplo n.º 24
0
        public void MinusMinusOperator_EqualsPreviousCalendarYear(int yearNum)
        {
            var calYear         = new CalendarYear(yearNum);
            var previousCalYear = new CalendarYear(yearNum - 1);

            calYear--;
            Assert.AreEqual(previousCalYear, calYear);
        }
Exemplo n.º 25
0
        public void FromDateTime_ReturnsCalendarYearForYearOfParameterYear(
            [ValueSource(nameof(DateTimesForFromDateTimeTest))] DateTime dateTime)
        {
            var calYear         = CalendarYear.FromDateTime(dateTime);
            var expectedCalYear = new CalendarYear(dateTime.Year);

            Assert.AreEqual(expectedCalYear, calYear);
        }
Exemplo n.º 26
0
        public void PlusPlusOperator_EqualsNextCalendarYear(int yearNum)
        {
            var calYear     = new CalendarYear(yearNum);
            var nextCalYear = new CalendarYear(yearNum + 1);

            calYear++;
            Assert.AreEqual(nextCalYear, calYear);
        }
Exemplo n.º 27
0
        public void MinusOperatorIntParameter_ReturnsYearMinusYearsSubtracted(int yearNum, int numTimePeriods)
        {
            var calYear = new CalendarYear(yearNum);
            var calYearAfterSubtraction      = calYear - numTimePeriods;
            var expectedYearAfterSubtraction = new CalendarYear(yearNum - numTimePeriods);

            Assert.AreEqual(expectedYearAfterSubtraction, calYearAfterSubtraction);
        }
Exemplo n.º 28
0
        public void MinusOperatorCalYearParameter_ReturnsDifferenceInYearNumbers(int yearNum1, int yearNum2)
        {
            var calYear1               = new CalendarYear(yearNum1);
            var calYear2               = new CalendarYear(yearNum2);
            var yearDifference         = calYear1 - calYear2;
            var expectedYearDifference = yearNum1 - yearNum2;

            Assert.AreEqual(expectedYearDifference, yearDifference);
        }
Exemplo n.º 29
0
        public void OffsetFrom_ReturnsDifferenceInYears(int yearNum1, int yearNum2)
        {
            var calYear1     = new CalendarYear(yearNum1);
            var calYear2     = new CalendarYear(yearNum2);
            var diff         = calYear1.OffsetFrom(calYear2);
            var expectedDiff = yearNum1 - yearNum2;

            Assert.AreEqual(expectedDiff, diff);
        }
Exemplo n.º 30
0
        public void AdditionOperator_ReturnsYearPlusNumYearsAdded(int yearNum, int numTimePeriods)
        {
            var calYear = new CalendarYear(yearNum);
            var calYearAfterAddition         = calYear + numTimePeriods;
            int expectedYearNumAfterAddition = yearNum + numTimePeriods;
            var expectedYearAfterAddition    = new CalendarYear(expectedYearNumAfterAddition);

            Assert.AreEqual(expectedYearAfterAddition, calYearAfterAddition);
        }
Exemplo n.º 31
0
 public static CalendarYear CreateCalendarYear()
 {
     var today = DateTime.Today;
       var yearStart = new DateTime(today.Year, 1, 1);
       var year = new CalendarYear(today.Year);
       for (int i = 0; i < 12; i++) {
     year.Blocks.Add(CreateBlock(yearStart.AddMonths(i), yearStart.AddMonths(i + 1).AddDays(-1)));
       }
       AssignBaseObjectProperties(year);
       return year;
 }
Exemplo n.º 32
0
        public void Schedule()
        {
            var assigner = MockRepository.GenerateMock<ICalendarAssigner>();

              var assignmentResult = new CalendarAssignmentResult();
              var calendar = new CalendarYear(2013){Id = 1};
              var residents = new List<Resident>();

              assigner.Stub(a => a.Assign(calendar, residents)).Return(assignmentResult);

              var result = new Scheduler(assigner).Schedule(calendar, residents);

              Assert.AreEqual(assignmentResult, result.AssignmentResult);
        }
Exemplo n.º 33
0
        public void CalendarYear_Set_When_BlockAdded()
        {
            var calendarYear = new CalendarYear(DateTime.Today.Year);
            var block1 = new Block();

            calendarYear.Blocks.Add(block1);
            Assert.AreEqual(calendarYear, block1.CalendarYear);

            var block2 = new Block();
            var block3 = new Block();
            calendarYear.Blocks.AddRange(new List<Block>{block2,block3});
            Assert.AreEqual(calendarYear, block2.CalendarYear);
            Assert.AreEqual(calendarYear, block3.CalendarYear);
        }
Exemplo n.º 34
0
        public void All_Blocks_InValid()
        {
            var mockery = new MockRepository();
            var block = mockery.PartialMock<Block>();

            using (mockery.Record()) {
                Expect.Call(block.IsValid).Return(false);
            }
            using (mockery.Playback()) {
                var year = new CalendarYear(2011);
                year.Blocks.Add(block);

                Assert.IsFalse(year.IsValid);
            }
        }
Exemplo n.º 35
0
        public void All_Blocks_Valid()
        {
            var mockery = new MockRepository();
            var block = mockery.PartialMock<Block>();
            var validator = mockery.DynamicMock<ICollectionValidator<Block>>();

            using (mockery.Record()) {
                Expect.Call(block.IsValid).Return(true);
                SetupResult.For(validator.Validate(null)).IgnoreArguments().Return(true);
            }
            using (mockery.Playback()) {
                var year = new CalendarYear(2011, validator);
                year.Blocks.Add(block);

                Assert.IsTrue(year.IsValid);
            }
        }
        public void Assign()
        {
            var assigner = MockRepository.GenerateMock<IBlockAssigner>();
              var calendar = new CalendarYear(2013) { Id = 1 };

              var blocks = new List<Block> {new Block(), new Block()};
              blocks.ForEach(calendar.Blocks.Add);

              var residents = new List<Resident> { new Resident() };
              var residents2 = new List<Resident> { new Resident(), new Resident() };
              var assignmentResult = new BlockAssignmentResult(residents2);
              assigner.Stub(a => a.Assign(blocks, residents)).Return(assignmentResult);

              var result = new CalendarAssigner(assigner).Assign(calendar, residents);

              Assert.AreEqual(residents2, result.Residents);
        }
Exemplo n.º 37
0
 static CalendarYear CreateCalendar()
 {
     var calendar = new CalendarYear(2013);
       calendar.Blocks.Add(CreateBlock(new DateTime(calendar.Year, 1, 1), new DateTime(calendar.Year, 1, 15)));
       return calendar;
 }
Exemplo n.º 38
0
 public CalendarAssignmentResult Assign(CalendarYear calendar, IEnumerable<Resident> residents)
 {
     return new CalendarAssignmentResult(assigner.Assign(calendar.Blocks, residents).Residents);
 }