Beispiel #1
0
        public void Should_MonthYear_Not_Be_Equals()
        {
            MonthYear monthYearOne    = new MonthYear(2021, 3);
            MonthYear monthYearSecond = new MonthYear(2021, 5);
            MonthYear monthYearThree  = null;

            Assert.False(monthYearOne.Equals(monthYearSecond));
            Assert.False(monthYearOne.Equals(monthYearThree));
        }
Beispiel #2
0
        public void Should_MonthYear_Be_Equals()
        {
            MonthYear monthYearOne    = new MonthYear(2021, 3);
            MonthYear monthYearSecond = new MonthYear(2021, 3);
            MonthYear monthYearThree  = monthYearOne;

            Assert.True(monthYearOne.Equals(monthYearSecond));
            Assert.True(monthYearOne.Equals(monthYearThree));
            Assert.True(monthYearOne.GetHashCode() == monthYearThree.GetHashCode());
        }
        public void ShouldCompareMonthYears(int year, int month, bool expectedResult)
        {
            // Arrange
            MonthYear monthYear        = MonthYear.Create(2018, 12);
            MonthYear anotherMonthYear = MonthYear.Create(year, month);

            // Act
            bool result1 = anotherMonthYear == monthYear;
            bool result2 = anotherMonthYear.Equals(monthYear);

            // Assert
            Assert.Equal(expectedResult, result1);
            Assert.Equal(expectedResult, result2);
        }
        public void EqualsTest()
        {
            var my1 = new MonthYear(1, 2000);
            var my2 = new MonthYear(2, 2000);
            var actual = my1.Equals(my2);
            Assert.False(actual);

            my1 = new MonthYear(1, 2000);
            my2 = new MonthYear(1, 2000);
            actual = my1.Equals(my2);
            Assert.True(actual);
        }
        public void EqualsReturnFalseIfIsNotAMonthYear()
        {
            var my1 = new MonthYear(1, 2000);
            var my2 = 0;
            var actual = my1.Equals(my2);

            Assert.False(actual);
        }
        public void DateComparisonTests()
        {
            var my1 = new MonthYear(12, 1999);
            var my2 = new MonthYear(1, 2000);

            var dt1 = new DateTime(1999, 12, 1);
            var dt2 = new DateTime(2000, 1, 1);
            var dt3 = new DateTime(2000, 2, 1);

            MonthYear my3 = dt3;

            Assert.True(my1.Equals(dt1));
            Assert.False(my1.Equals(dt2));
            Assert.True(my1.CompareTo(dt1) == 0);
            Assert.True(my2.CompareTo(dt1) > 0);
            Assert.True(my1.Equals(dt1));
            Assert.True(my1.Equals((object)my1));

            Assert.True(my1.Equals(dt1));
            Assert.False(my1.Equals(dt2));
            my1++;
            Assert.True(my1.Equals(dt2));
            Assert.False(my1.Equals(dt1));
            my1--;
            Assert.False(my1.Equals(dt2));
            Assert.True(my1.Equals(dt1));
        }