Ejemplo n.º 1
0
        public void Should_not_throw_exception_on_division_by_zero(double value, double expectedValue)
        {
            var instance = new Millisecond(value);
            var actual   = instance / 0d;

            Assert.AreEqual(expectedValue, actual.Value);
        }
Ejemplo n.º 2
0
        public void Should_initialize_instance(double value)
        {
            var actual = new Millisecond(value);

            Assert.IsAssignableFrom <Millisecond>(actual);
            Assert.AreEqual(value, actual.Value, nameof(actual.Value));
        }
Ejemplo n.º 3
0
        public void Should_compare_with_null_instance(double value)
        {
            var instance = new Millisecond(value);

            Assert.IsFalse(instance.Equals(null), "Equals");
            Assert.AreEqual(1, instance.CompareTo(null), "CompareTo");
        }
Ejemplo n.º 4
0
        public void Should_compare_with_another_type_of_instance(double value)
        {
            var    instance1 = new Millisecond(value);
            object instance2 = value;

            Assert.IsFalse(instance1.Equals(instance2), "Equals");
            Assert.Throws <ArgumentException>(() => instance1.CompareTo(instance2), "CompareTo");
        }
Ejemplo n.º 5
0
        public void Should_cast_to_double(double value)
        {
            var instance = new Millisecond(value);

            var actual = (double)instance;

            Assert.AreEqual(value, actual);
        }
Ejemplo n.º 6
0
        public void Should_cast_from_double(double value)
        {
            var expected = new Millisecond(value);

            var actual = (Millisecond)value;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public void Should_roundvalue_withMode(MidpointRounding mode, double value, double expectedValue)
        {
            var expected = new Millisecond(expectedValue);

            var instance = new Millisecond(value);
            var actual   = instance.Round(mode);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public void Should_convert_to_string(double value)
        {
            var expected = $"{value:e} milliseconds";

            var instance = new Millisecond(value);
            var actual   = instance.ToString();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
        public void Should_divide_instance_by_double(double leftValue, double rightValue, double expectedValue)
        {
            var expected = new Millisecond(expectedValue);

            var instance = new Millisecond(leftValue);
            var actual   = instance / rightValue;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        public void Should_own_a_HashCode(double value)
        {
            var expected = value.GetHashCode();

            var instance = new Millisecond(value);
            var actual   = instance.GetHashCode();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
        public void Should_round_value_withDigit(double value, double expectedValue)
        {
            var expected = new Millisecond(expectedValue);

            var instance = new Millisecond(value);
            var actual   = instance.Round(1);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public void Should_convert_to_TimeSpan(double value)
        {
            var expected = TimeSpan.FromMilliseconds(value);

            var      instance = new Millisecond(value);
            TimeSpan actual   = instance;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        public void Should_format_string(string format, string mask)
        {
            var expected = string.Format(Consts.CultureEnUS, mask, 1.757899e2);

            var instance = new Millisecond(1.757899e2);
            var actual   = instance.ToString(format, Consts.CultureEnUS);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
        public void Should_floor_value(double value, double expectedValue)
        {
            var expected = new Millisecond(expectedValue);

            var instance = new Millisecond(value);
            var actual   = instance.Floor();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 15
0
        public void Should_multiply_double_by_instance(double leftValue, double rightValue, double expectedValue)
        {
            var expected = new Millisecond(expectedValue);

            var instance = new Millisecond(rightValue);

            var actual = leftValue * instance;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 16
0
        public void Should_subtract_two_instances(double leftValue, double rightValue, double expectedValue)
        {
            var expected = new Millisecond(expectedValue);

            var leftInstance  = new Millisecond(leftValue);
            var rightInstance = new Millisecond(rightValue);
            var actual        = leftInstance - rightInstance;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 17
0
        public override string ToString()
        {
            string overall = "";

            overall += Hour.ToString().PadLeft(2, '0') + ':';
            overall += Minute.ToString().PadLeft(2, '0') + ':';
            overall += Second.ToString().PadLeft(2, '0') + ',';
            overall += Millisecond.ToString().PadLeft(3, '0');
            return(overall);
        }
        public void Should_cast_from_Minute(double minuteValue, double expectedValue)
        {
            var minuteInstance = new SystemOfUnits.Time.Minute(minuteValue);

            Millisecond actual = minuteInstance;

            Assert.IsAssignableFrom <Millisecond>(actual);

            var actualValue = actual.Value;

            Assert.AreEqual(expectedValue, actualValue, Consts.DeltaAssert);
        }
        public void Should_cast_from_Year(double yearValue, double expectedValue)
        {
            var yearInstance = new SystemOfUnits.Time.Year(yearValue);

            Millisecond actual = yearInstance;

            Assert.IsAssignableFrom <Millisecond>(actual);

            var actualValue = actual.Value;

            Assert.AreEqual(expectedValue, actualValue, Consts.DeltaAssert);
        }
Ejemplo n.º 20
0
 /// <inheritdoc />
 protected override void Execute(Context context)
 {
     Result.Set(context, new DateTime(
                    Year.Get(context),
                    Month.Get(context),
                    Day.Get(context),
                    Hour.Get(context),
                    Minute.Get(context),
                    Second.Get(context),
                    Millisecond.Get(context)
                    ));
 }
Ejemplo n.º 21
0
        public override int GetHashCode()
        {
            const int k = 16777619;

            unchecked
            {
                int h = (int)2166136261;
                h = (h * k) ^ Year.GetHashCode();
                h = (h * k) ^ Month.GetHashCode();
                h = (h * k) ^ Day.GetHashCode();
                h = (h * k) ^ Hour.GetHashCode();
                h = (h * k) ^ Minute.GetHashCode();
                h = (h * k) ^ Second.GetHashCode();
                h = (h * k) ^ Millisecond.GetHashCode();
                h = (h * k) ^ IsSubstitued.GetHashCode();
                h = (h * k) ^ IsSummerTime.GetHashCode();
                return(h);
            }
        }
 public Time(int hour, int minute, int second, int milliseconds)
 {
     if (hour >= 0)
     {
         Hour = new Hour(hour);
     }
     if (minute >= 0)
     {
         Minute = new Minute(minute);
     }
     if (second >= 0)
     {
         Second = new Second(second);
     }
     if (milliseconds >= 0)
     {
         Millisecond = new Millisecond(milliseconds);
     }
 }
Ejemplo n.º 23
0
        public void Should_compare_with_same_value(double value)
        {
            var baseInstance  = new Millisecond(value);
            var otherInstance = new Millisecond(value);

            Assert.IsTrue(baseInstance.Equals(otherInstance), "Equals");
            Assert.IsTrue(baseInstance.Equals((object)otherInstance), "Equals object");

            Assert.IsTrue(baseInstance == otherInstance, "==");
            Assert.IsFalse(baseInstance != otherInstance, "!=");

            Assert.AreEqual(0, baseInstance.CompareTo(otherInstance), "CompareTo");
            Assert.AreEqual(0, baseInstance.CompareTo((object)otherInstance), "CompareTo object");

            Assert.IsFalse(baseInstance < otherInstance, "<");
            Assert.IsFalse(baseInstance > otherInstance, ">");

            Assert.IsTrue(baseInstance <= otherInstance, "<=");
            Assert.IsTrue(baseInstance >= otherInstance, ">=");
        }
Ejemplo n.º 24
0
        public void Should_compare_with_smaller_value(double baseValue, double smallerValue)
        {
            var baseInstance    = new Millisecond(baseValue);
            var smallerInstance = new Millisecond(smallerValue);

            Assert.IsFalse(baseInstance.Equals(smallerInstance), "Equals");
            Assert.IsFalse(baseInstance.Equals((object)smallerInstance), "Equals object");

            Assert.IsFalse(baseInstance == smallerInstance, "==");
            Assert.IsTrue(baseInstance != smallerInstance, "!=");

            Assert.AreEqual(+1, baseInstance.CompareTo(smallerInstance), "CompareTo");
            Assert.AreEqual(+1, baseInstance.CompareTo((object)smallerInstance), "CompareTo object");

            Assert.IsFalse(baseInstance < smallerInstance, "<");
            Assert.IsTrue(baseInstance > smallerInstance, ">");

            Assert.IsFalse(baseInstance <= smallerInstance, "<=");
            Assert.IsTrue(baseInstance >= smallerInstance, ">=");
        }
Ejemplo n.º 25
0
        public void Should_compare_with_bigger_value(double baseValue, double biggerValue)
        {
            var baseInstance   = new Millisecond(baseValue);
            var biggerInstance = new Millisecond(biggerValue);

            Assert.IsFalse(baseInstance.Equals(biggerInstance), "Equals");
            Assert.IsFalse(baseInstance.Equals((object)biggerInstance), "Equals object");

            Assert.IsFalse(baseInstance == biggerInstance, "==");
            Assert.IsTrue(baseInstance != biggerInstance, "!=");

            Assert.AreEqual(-1, baseInstance.CompareTo(biggerInstance), "CompareTo");
            Assert.AreEqual(-1, baseInstance.CompareTo((object)biggerInstance), "CompareTo object");

            Assert.IsTrue(baseInstance < biggerInstance, "<");
            Assert.IsFalse(baseInstance > biggerInstance, ">");

            Assert.IsTrue(baseInstance <= biggerInstance, "<=");
            Assert.IsFalse(baseInstance >= biggerInstance, ">=");
        }
Ejemplo n.º 26
0
        public override int GetHashCode()
        {
            var hashCode = 844321305;

            hashCode = hashCode * -1521134295 + Ticks.GetHashCode();
            hashCode = hashCode * -1521134295 + Second.GetHashCode();
            hashCode = hashCode * -1521134295 + Date.GetHashCode();
            hashCode = hashCode * -1521134295 + Month.GetHashCode();
            hashCode = hashCode * -1521134295 + Minute.GetHashCode();
            hashCode = hashCode * -1521134295 + Millisecond.GetHashCode();
            hashCode = hashCode * -1521134295 + Hour.GetHashCode();
            hashCode = hashCode * -1521134295 + DayOfYear.GetHashCode();
            hashCode = hashCode * -1521134295 + DayOfWeek.GetHashCode();
            hashCode = hashCode * -1521134295 + Day.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <TimeSpan> .Default.GetHashCode(TimeOfDay);

            hashCode = hashCode * -1521134295 + Year.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer <TimeSpan> .Default.GetHashCode(Offset);

            hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Value);

            return(hashCode);
        }
Ejemplo n.º 27
0
        public AlaskaDateTime(TimeSpan timeOfDay)
        {
            var alaskaNow = DateTime.UtcNow.ToAlaska();

            Year  = alaskaNow.Year;
            Month = alaskaNow.Month;
            Day   = alaskaNow.Day;

            Hour        = timeOfDay.Hours;
            Minute      = timeOfDay.Minutes;
            Second      = timeOfDay.Seconds;
            Millisecond = timeOfDay.Milliseconds;

            var dateTimeParse =
                DateTime.Parse(string.Concat(Year, "-", Month.ToString("00"), "-", Day.ToString("00"), "T", Hour.ToString("00"), ":", Minute.ToString("00"), ":", Second.ToString("00"), ".", Millisecond.ToString("00"), "Z"))
                .ToUniversalTime()
                .ToAlaska();

            Offset = dateTimeParse.IsInDaylightSavingsTime() ? DaylightOffset : StandardOffset;

            Date      = new AlaskaDateTime(Year, Month, Day);
            DayOfYear = Date.DayOfYear;
            DayOfWeek = Date.DayOfWeek;
        }
Ejemplo n.º 28
0
 public override string ToString()
 {
     return(Year + "/" + Month.ToString().PadLeft(2, '0') + "/" + Day.ToString().PadLeft(2, '0') +
            " " + Hour.ToString().PadLeft(2, '0') + ":" + Minute.ToString().PadLeft(2, '0') + ":" + Second.ToString().PadLeft(2, '0') + "." + Millisecond.ToString().PadLeft(3, '0'));
 }
Ejemplo n.º 29
0
        public string ToString(string format)
        {
            var formattedText = "";

            if (format != null)
            {
                for (int i = 0, len = format.Length; i < len; i++)
                {
                    var wildcard = format[i];
                    var part     = wildcard.ToString();
                    i++;
                    while (i < len && format[i] == wildcard)
                    {
                        part += format[i];
                        i++;
                    }
                    i--;
                    switch (part)
                    {
                    case "y":
                    case "yy":
                    case "yyy":
                    case "yyyy":
                        formattedText += Year.ToString().PadLeft(part.Length, '0');
                        break;

                    case "MMMM":
                        formattedText += GetMonthName(Month);
                        break;

                    case "MMM":
                        formattedText += GetShortMonthName(Month);
                        break;

                    case "MM":
                    case "M":
                        formattedText += Month.ToString().PadLeft(part.Length, '0');
                        break;

                    case "dddd":
                        formattedText += DayName;
                        break;

                    case "ddd":
                        formattedText += ShortDayName;
                        break;

                    case "dd":
                    case "d":
                        formattedText += Day.ToString().PadLeft(part.Length, '0');
                        break;

                    case "HH":
                    case "H":
                        formattedText += Hour.ToString().PadLeft(part.Length, '0');
                        break;

                    case "hh":
                    case "h":
                        formattedText += (Hour % 12 == 0 ? 12 : Hour % 12).ToString().PadLeft(part.Length, '0');
                        break;

                    case "mm":
                    case "m":
                        formattedText += Minute.ToString().PadLeft(part.Length, '0');
                        break;

                    case "ss":
                    case "s":
                        formattedText += Second.ToString().PadLeft(part.Length, '0');
                        break;

                    case "fffffff":
                    case "ffffff":
                    case "fffff":
                    case "ffff":
                    case "fff":
                    case "ff":
                    case "f":
                        formattedText += Millisecond.ToString().PadLeft(part.Length, '0');
                        break;

                    case "tt":
                    case "t":
                        formattedText += (Hour < 12 ? "صبح" : "عصر").Substring(0, part.Length == 1 ? 1 : 3);
                        break;

                    default:
                        formattedText += part;
                        break;
                    }
                }
            }

            return(formattedText);
        }
Ejemplo n.º 30
0
        } // Equals

        // ----------------------------------------------------------------------
        public override string ToString()
        {
            return(((int)TotalHours).ToString("00") + ":" + Minute.ToString("00") +
                   ":" + Second.ToString("00") + "." + Millisecond.ToString("000"));
        } // ToString
Ejemplo n.º 31
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (Date.Expression != null)
            {
                targetCommand.AddParameter("Date", Date.Get(context));
            }

            if (Year.Expression != null)
            {
                targetCommand.AddParameter("Year", Year.Get(context));
            }

            if (Month.Expression != null)
            {
                targetCommand.AddParameter("Month", Month.Get(context));
            }

            if (Day.Expression != null)
            {
                targetCommand.AddParameter("Day", Day.Get(context));
            }

            if (Hour.Expression != null)
            {
                targetCommand.AddParameter("Hour", Hour.Get(context));
            }

            if (Minute.Expression != null)
            {
                targetCommand.AddParameter("Minute", Minute.Get(context));
            }

            if (Second.Expression != null)
            {
                targetCommand.AddParameter("Second", Second.Get(context));
            }

            if (Millisecond.Expression != null)
            {
                targetCommand.AddParameter("Millisecond", Millisecond.Get(context));
            }

            if (DisplayHint.Expression != null)
            {
                targetCommand.AddParameter("DisplayHint", DisplayHint.Get(context));
            }

            if (UFormat.Expression != null)
            {
                targetCommand.AddParameter("UFormat", UFormat.Get(context));
            }

            if (Format.Expression != null)
            {
                targetCommand.AddParameter("Format", Format.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }