Ejemplo n.º 1
0
        public void IntegerDateReadmeTest()
        {
            // Find date components
            IntegerDate fromString = new IntegerDate("20180710");

            Assert.AreEqual(2018, fromString.Year);
            Assert.AreEqual(7, fromString.Month);
            Assert.AreEqual(10, fromString.Day);

            IntegerDate fromInt = new IntegerDate(20180609);

            Assert.AreEqual(2018, fromInt.Year);
            Assert.AreEqual(6, fromInt.Month);
            Assert.AreEqual(9, fromInt.Day);

            // Convert
            Assert.AreEqual(20180710, fromString.ToInt);
            Assert.AreEqual("20180609", fromInt.ToString());

            Assert.AreEqual(2018, fromInt.ToDateTime.Year);
            Assert.AreEqual(6, fromInt.ToDateTime.Month);
            Assert.AreEqual(9, fromInt.ToDateTime.Day);

            IntegerDate fromDateTime = new IntegerDate(new DateTime(2018, 07, 10));

            Assert.AreEqual(2018, fromDateTime.Year);
            Assert.AreEqual(7, fromDateTime.Month);
            Assert.AreEqual(10, fromDateTime.Day);
            Assert.AreEqual(20180710, fromDateTime.ToInt);
            Assert.AreEqual("20180710", fromDateTime.ToString());
        }
Ejemplo n.º 2
0
        public void InvalidLengthInputThrows()
        {
            //Arrange
            string input = "111";
            IntegerDate testObj;

            //Act
            testObj = new IntegerDate(input);

            //Assert
            //Throws
        }
Ejemplo n.º 3
0
        public void StringCtor_GivesCorrectYear()
        {
            //Arrange
            string input = "20180427";
            int expected = 2018;
            IntegerDate testObj;

            //Act
            testObj = new IntegerDate(input);

            //Assert
            Assert.AreEqual(expected, testObj.Year);
        }
Ejemplo n.º 4
0
        public void DateTimeCtor_GivesCorrectDay()
        {
            //Arrange
            DateTime input = new DateTime(2018, 05, 16);
            int expected = 16;
            IntegerDate testObj;

            //Act
            testObj = new IntegerDate(input);

            //Assert
            Assert.AreEqual(expected, testObj.Day);
        }
Ejemplo n.º 5
0
        public void NonNumericThrows()
        {
            //Arrange
            string input = "aaa";

            IntegerDate testObj;

            //Act
            testObj = new IntegerDate(input);

            //Assert
            //Throws
        }
Ejemplo n.º 6
0
        public void ToString_Correct()
        {
            //Arrange
            string input = "20180427";
            string expected = "20180427";
            IntegerDate testObj;

            //Act
            testObj = new IntegerDate(input);

            //Assert
            Assert.AreEqual(expected, testObj.ToString());
        }
Ejemplo n.º 7
0
        public void ToDateTime()
        {
            //Arrange
            string input = "20180427";
            DateTime expected = new DateTime(2018, 04, 27);
            IntegerDate testObj;

            //Act
            testObj = new IntegerDate(input);

            //Assert
            Assert.AreEqual(expected, testObj.ToDateTime);
        }
Ejemplo n.º 8
0
        public void IntCtor_GivesCorrectDayMonthYear()
        {
            //Arrange
            int expectedDay = 16;
            int expectedMonth = 05;
            int expectedYear = 2018;
            int input = (expectedYear * 10000) + (expectedMonth * 100) + expectedDay;
            IntegerDate testObj;

            //Act
            testObj = new IntegerDate(input);

            //Assert
            Assert.AreEqual(expectedDay, testObj.Day);
            Assert.AreEqual(expectedMonth, testObj.Month);
            Assert.AreEqual(expectedYear, testObj.Year);
        }