Esempio n. 1
0
        public void RepeatBehaviorForeverToStringIFormatProvider()
        {
            RepeatBehavior rb = RepeatBehavior.Forever;

            RepeatBehaviorFormatter.CallCount = 0;
            Assert.AreEqual("Forever", rb.ToString(null), "null");
            Assert.AreEqual(0, RepeatBehaviorFormatter.CallCount, "CallCount-a");
            Assert.AreEqual("Forever", rb.ToString(new RepeatBehaviorFormatter()), "RepeatBehaviorFormatter");
            // unused
            Assert.AreEqual(0, RepeatBehaviorFormatter.CallCount, "CallCount");
        }
Esempio n. 2
0
        public void RepeatBehaviorDurationToStringIFormatProvider()
        {
            RepeatBehavior rb = new RepeatBehavior(TimeSpan.MaxValue);

            RepeatBehaviorFormatter.CallCount = 0;
            Assert.AreEqual("10675199.02:48:05.4775807", rb.ToString(null), "null");
            Assert.AreEqual(0, RepeatBehaviorFormatter.CallCount, "CallCount-a");
            Assert.AreEqual("10675199.02:48:05.4775807", rb.ToString(new RepeatBehaviorFormatter()), "RepeatBehaviorFormatter");
            // unused
            Assert.AreEqual(0, RepeatBehaviorFormatter.CallCount, "CallCount");
        }
Esempio n. 3
0
        public void RepeatBehaviorCountToStringIFormatProvider()
        {
            RepeatBehavior rb = new RepeatBehavior(2);

            RepeatBehaviorFormatter.CallCount = 0;
            Assert.AreEqual("2x", rb.ToString(null), "null");
            Assert.AreEqual(0, RepeatBehaviorFormatter.CallCount, "CallCount-a");
            Assert.AreEqual("[2]x", rb.ToString(new RepeatBehaviorFormatter()), "RepeatBehaviorFormatter");
            // 1 time: one per double (1), no call for 'x'
            Assert.AreEqual(1, RepeatBehaviorFormatter.CallCount, "CallCount");
        }
Esempio n. 4
0
        public void ToString_Invoke_ReturnsExpected(RepeatBehavior keyTime, string format, IFormatProvider formatProvider, string expected)
        {
            if (format == null)
            {
                if (formatProvider == null)
                {
                    Assert.Equal(expected, keyTime.ToString());
                }

                Assert.Equal(expected, keyTime.ToString(formatProvider));
            }

            Assert.Equal(expected, ((IFormattable)keyTime).ToString(format, formatProvider));
        }
Esempio n. 5
0
        public void TimeSpanConstructor()
        {
            RepeatBehavior rb = new RepeatBehavior(TimeSpan.Zero);

            Assert.IsFalse(rb.HasCount, "HasCount");
            Assert.IsTrue(rb.HasDuration, "HasDuration");

            Assert.Throws <InvalidOperationException> (delegate {
                Assert.AreEqual(0, rb.Count, "Count");
            }, "Count");
            Assert.AreEqual(TimeSpan.Zero, rb.Duration, "Duration");

            Assert.AreEqual(TimeSpan.Zero.ToString(), rb.ToString(), "ToString");

            Assert.Throws <ArgumentOutOfRangeException> (delegate {
                rb = new RepeatBehavior(new TimeSpan(-1));
            }, "Negative");
            Assert.Throws <ArgumentOutOfRangeException> (delegate {
                rb = new RepeatBehavior(TimeSpan.MinValue);
            }, "MinValue");

            rb = new RepeatBehavior(TimeSpan.MaxValue);
            Assert.IsFalse(rb.HasCount, "HasCount-Max");
            Assert.IsTrue(rb.HasDuration, "HasDuration-Max");
            Assert.AreEqual(TimeSpan.MaxValue, rb.Duration, "Duration");
            Assert.AreEqual("10675199.02:48:05.4775807", rb.ToString(), "ToString");
            Assert.IsFalse(rb.Equals(RepeatBehavior.Forever), "Max!=Forever");
        }
Esempio n. 6
0
        public void Defaults()
        {
            RepeatBehavior rb = new RepeatBehavior();

            Assert.IsTrue(rb.HasCount, "HasCount");
            Assert.IsFalse(rb.HasDuration, "HasCount");

            Assert.AreEqual(0.0, rb.Count, "Count");
            Assert.Throws <InvalidOperationException> (delegate {
                Assert.AreEqual(TimeSpan.Zero, rb.Duration, "Duration");
            }, "Duration");

            Assert.AreEqual("0x", rb.ToString(), "ToString");
        }
Esempio n. 7
0
        public void When_RepeatBehavior_Is_TimeSpan()
        {
            var behavior = new RepeatBehavior(TimeSpan.FromSeconds(24));

            Assert.IsFalse(behavior.HasCount);
            Assert.IsTrue(behavior.HasDuration);

            Assert.IsTrue(behavior.Equals((object)new RepeatBehavior(TimeSpan.FromSeconds(24))));
            Assert.IsTrue(behavior.Equals(new RepeatBehavior(TimeSpan.FromSeconds(24))));
            Assert.IsTrue(RepeatBehavior.Equals(behavior, new RepeatBehavior(TimeSpan.FromSeconds(24))));

            Assert.IsFalse(behavior.Equals(null));
            Assert.IsFalse(behavior.Equals((object)RepeatBehavior.Forever));
            Assert.IsFalse(behavior.Equals(new RepeatBehavior(TimeSpan.FromSeconds(30))));
            Assert.IsFalse(RepeatBehavior.Equals(behavior, new RepeatBehavior(8)));

            Assert.AreEqual("00:00:24", behavior.ToString());
        }
Esempio n. 8
0
        public void When_RepeatBehavior_Is_Forever()
        {
            var behavior = new RepeatBehavior()
            {
                Type = RepeatBehaviorType.Forever
            };

            Assert.IsFalse(behavior.HasCount);
            Assert.IsFalse(behavior.HasDuration);

            Assert.IsTrue(behavior.Equals((object)RepeatBehavior.Forever));
            Assert.IsTrue(behavior.Equals(RepeatBehavior.Forever));
            Assert.IsTrue(RepeatBehavior.Equals(behavior, RepeatBehavior.Forever));

            Assert.IsFalse(behavior.Equals(null));
            Assert.IsFalse(behavior.Equals((object)new RepeatBehavior(3)));
            Assert.IsFalse(behavior.Equals(new RepeatBehavior(TimeSpan.FromSeconds(30))));
            Assert.IsFalse(RepeatBehavior.Equals(behavior, new RepeatBehavior(8)));

            Assert.AreEqual("Forever", behavior.ToString());
        }
Esempio n. 9
0
        public void Forever()
        {
            RepeatBehavior rb = RepeatBehavior.Forever;

            Assert.IsFalse(rb.HasCount, "HasCount");
            Assert.IsFalse(rb.HasDuration, "HasCount");

            Assert.Throws <InvalidOperationException> (delegate {
                Assert.AreEqual(0, rb.Count, "Count");
            }, "Count");
            Assert.Throws <InvalidOperationException> (delegate {
                Assert.AreEqual(TimeSpan.Zero, rb.Duration, "Duration");
            }, "Duration");

            Assert.AreEqual("Forever", rb.ToString(), "ToString");

            Assert.AreEqual(rb, RepeatBehavior.Forever, "AreEqual");
            Assert.IsTrue(rb.Equals(RepeatBehavior.Forever), "Equals(RepeatBehavior)");
            Assert.IsTrue(RepeatBehavior.Forever.Equals((object)rb), "Equals(object)");
            Assert.IsTrue(RepeatBehavior.Equals(rb, RepeatBehavior.Forever), "RepeatBehavior.Equals");
            Assert.IsFalse(Object.ReferenceEquals(rb, RepeatBehavior.Forever), "Same");
        }
Esempio n. 10
0
        public void DoubleConstructor()
        {
            RepeatBehavior rb = new RepeatBehavior(1.0);

            Assert.IsTrue(rb.HasCount, "HasCount");
            Assert.IsFalse(rb.HasDuration, "HasCount");

            Assert.AreEqual(1.0, rb.Count, "Count");
            Assert.Throws <InvalidOperationException> (delegate {
                Assert.AreEqual(TimeSpan.Zero, rb.Duration, "Duration");
            }, "Duration");

            Assert.AreEqual("1x", rb.ToString(), "ToString");

            Assert.Throws <ArgumentOutOfRangeException> (delegate {
                rb = new RepeatBehavior(-0.1);
            }, "Negative");
            Assert.Throws <ArgumentOutOfRangeException> (delegate {
                rb = new RepeatBehavior(Double.MinValue);
            }, "MinValue");
            Assert.Throws <ArgumentOutOfRangeException> (delegate {
                rb = new RepeatBehavior(Double.NegativeInfinity);
            }, "NegativeInfinity");

            Assert.Throws <ArgumentOutOfRangeException> (delegate {
                rb = new RepeatBehavior(Double.PositiveInfinity);
            }, "PositiveInfinity");
            Assert.Throws <ArgumentOutOfRangeException> (delegate {
                rb = new RepeatBehavior(Double.NaN);
            }, "NaN");

            rb = new RepeatBehavior(Double.MaxValue);
            Assert.IsTrue(rb.HasCount, "HasCount-Max");
            Assert.IsFalse(rb.HasDuration, "HasDuration-Max");
            Assert.AreEqual(Double.MaxValue, rb.Count, "Count-Max");
            Assert.AreEqual("1.79769313486232E+308x", rb.ToString(), "ToString");
            Assert.IsFalse(rb.Equals(RepeatBehavior.Forever), "Max!=Forever");
        }