Exemplo n.º 1
0
        public void AddAddHoursAndMinutes()
        {
            DateTime baseDateTime = DateTime.Now; // :-)

            NhsTime time = new NhsTime(baseDateTime);

            string addInstruction = string.Format(CultureInfo.CurrentCulture, "+1{0}+5{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.MinutesUnit);

            Assert.IsTrue(NhsTime.IsAddValid(addInstruction), string.Format(CultureInfo.CurrentCulture, "{0} was not recognised as an Time Add Instruction", addInstruction));

            time.Add(addInstruction);

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1).AddMinutes(5), string.Format(CultureInfo.CurrentCulture, "Failed using {0}", addInstruction));

            // Now try without +

            // Reset
            baseDateTime = DateTime.Now;
            time         = new NhsTime(baseDateTime);

            // reinitialise add instructionstring as instruction without operands

            addInstruction = string.Format(CultureInfo.CurrentCulture, "1{0}5{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.MinutesUnit);

            Assert.IsTrue(NhsTime.IsAddValid(addInstruction), string.Format(CultureInfo.CurrentCulture, "{0} was not recognised as an Time Add Instruction", addInstruction));

            time.Add(addInstruction);

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1).AddMinutes(5), string.Format(CultureInfo.CurrentCulture, "Failed using {0}", addInstruction));
        }
Exemplo n.º 2
0
        public void AddSubtract2HoursAdd25Minutes()
        {
            DateTime nowAsItWasAtTheStartofTheTest = DateTime.Now; // :-)

            NhsTime time = new NhsTime(nowAsItWasAtTheStartofTheTest);

            string addInstruction = string.Format(CultureInfo.CurrentCulture, "-2{0}+25{1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit, NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.MinutesUnit);

            Assert.IsTrue(NhsTime.IsAddValid(addInstruction), string.Format(CultureInfo.CurrentCulture, "{0} was not recognised as a Time Add Instruction", addInstruction));

            time.Add(addInstruction);

            Assert.AreEqual(nowAsItWasAtTheStartofTheTest.AddHours(-2).AddMinutes(25), time.TimeValue);
        }
Exemplo n.º 3
0
        public void AddAddHour()
        {
            DateTime baseDateTime = DateTime.Now; // :-)

            NhsTime time = new NhsTime(baseDateTime);

            Assert.IsTrue(NhsTime.IsAddValid(string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit)));

            time.Add(string.Format(CultureInfo.CurrentCulture, "+1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit));

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1));

            // Now try it without the "+", this will check that + is the default
            // Reset
            baseDateTime = DateTime.Now;
            time         = new NhsTime(baseDateTime);

            Assert.IsTrue(NhsTime.IsAddValid(string.Format(CultureInfo.CurrentCulture, "1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit)), "1h was not recognised as a Time Add Instruction");

            time.Add(string.Format(CultureInfo.CurrentCulture, "1{0}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.HoursUnit));

            Assert.AreEqual(time.TimeValue, baseDateTime.AddHours(1));
        }
Exemplo n.º 4
0
 public void NullInstructionTimeIsAddInstructionTest()
 {
     NhsTime.IsAddValid(null);
 }