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"); }
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()); }
public void Equals_Object_ReturnsExpected(RepeatBehavior repeatBehaviour, object other, bool expected) { Assert.Equal(expected, repeatBehaviour.Equals(other)); if (other is RepeatBehavior otherRepeatBehaviour) { Assert.Equal(expected, RepeatBehavior.Equals(repeatBehaviour, otherRepeatBehaviour)); Assert.Equal(expected, repeatBehaviour.Equals(otherRepeatBehaviour)); Assert.Equal(expected, repeatBehaviour == otherRepeatBehaviour); Assert.Equal(!expected, repeatBehaviour != otherRepeatBehaviour); if (repeatBehaviour.Type >= RepeatBehaviorType.Count && repeatBehaviour.Type <= RepeatBehaviorType.Forever) { Assert.Equal(expected, repeatBehaviour.GetHashCode().Equals(otherRepeatBehaviour.GetHashCode())); } else if (repeatBehaviour.Type == otherRepeatBehaviour.Type) { Assert.Equal(repeatBehaviour.GetHashCode(), otherRepeatBehaviour.GetHashCode()); } } }
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()); }
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"); }
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"); }
/// <summary> /// Indicates whether the two specified <see cref="RepeatBehavior"/> /// values are equal. /// </summary> /// <param name="repeatBehavior1">The first value to compare.</param> /// <param name="repeatBehavior2">The second value to compare.</param> /// <returns> /// true if both the type and repeat behavior of repeatBehavior1 are equal to that /// of repeatBehavior2; otherwise, false. /// </returns> public static bool Equals(RepeatBehavior repeatBehavior1, RepeatBehavior repeatBehavior2) { return(repeatBehavior1.Equals(repeatBehavior2)); }