public void NegateOrCondition(bool?first, bool?other, bool?third, bool?expected) { var fake1 = new Fake { IsTrueOrNull = first }; using (var condition1 = new Condition(fake1.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake1.IsTrueOrNull)) { var fake2 = new Fake { IsTrueOrNull = other }; using (var condition2 = new Condition(fake2.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake2.IsTrueOrNull)) { var fake3 = new Fake { IsTrueOrNull = third }; using (var condition3 = new Condition(fake3.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake3.IsTrueOrNull)) { using (var orCondition = new OrCondition(condition1, condition2, condition3)) { using (var negated = new Negated <Condition>(orCondition)) { Assert.AreEqual(expected, negated.IsSatisfied); } } } } } }
public void History() { var fake = new Fake { IsTrueOrNull = false }; using (var condition = new Condition(fake.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake.IsTrueOrNull) { Name = "IsTrueOrNull" }) { using (var negatedCondition = new Negated <Condition>(condition)) { var expected = new List <bool?> { true }; CollectionAssert.AreEqual(expected, negatedCondition.History.Select(x => x.State)); fake.IsTrueOrNull = true; expected.Add(false); CollectionAssert.AreEqual(expected, negatedCondition.History.Select(x => x.State)); fake.IsTrueOrNull = null; expected.Add(null); CollectionAssert.AreEqual(expected, negatedCondition.History.Select(x => x.State)); } } }
public void Notifies() { var argses = new List <PropertyChangedEventArgs>(); var negArgses = new List <PropertyChangedEventArgs>(); var fake = new Fake { IsTrueOrNull = false }; using (var condition = new Condition(fake.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake.IsTrueOrNull == true)) { using (var negatedCondition = new Negated <Condition>(condition)) { condition.PropertyChanged += (_, e) => argses.Add(e); negatedCondition.PropertyChanged += (_, e) => negArgses.Add(e); Assert.AreEqual(0, argses.Count); Assert.AreEqual(0, negArgses.Count); fake.IsTrueOrNull = true; Assert.AreEqual(1, argses.Count); Assert.AreEqual(1, negArgses.Count); fake.IsTrueOrNull = null; Assert.AreEqual(2, argses.Count); Assert.AreEqual(2, negArgses.Count); } } }
/// <summary> /// Gets a unique interger value that describes this object that is garenteed not to change. /// </summary> /// <returns></returns> public override int GetHashCode() { if (InnerValue != null) { return(base.GetHashCode()); } return(Negated.GetHashCode()); }
public void SatisfiedByHandlesNull(string value, bool expected) { var isNull = new TestSpecification <string>(val => val == null); var result = new Negated <string>(isNull).IsSatisfiedBy(value); result.Should() .Be(expected); }
public void SatisfiedByYieldCorrectResult(int value, bool expected) { var isPositive = new TestSpecification <int>(val => val > 0); var result = new Negated <int>(isPositive).IsSatisfiedBy(value); result.Should() .Be(expected); }
public static void NegateCondition(bool?value, bool?expected) { var fake = new Fake { IsTrueOrNull = value }; using var condition = new Condition(fake.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake.IsTrueOrNull); using var negatedCondition = new Negated <Condition>(condition); Assert.AreEqual(expected, negatedCondition.IsSatisfied); }
public static void NegateTwiceReturnsOriginal() { var fake = new Fake { IsTrueOrNull = false }; using var condition = new Condition(fake.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake.IsTrueOrNull); using var negatedCondition = new Negated <Condition>(condition); #pragma warning disable CS0618 // Type or member is obsolete using var negatedTwice = negatedCondition.Negate(); #pragma warning restore CS0618 // Type or member is obsolete Assert.AreSame(condition, negatedTwice); }
public static void Name() { var fake = new Fake { IsTrueOrNull = false }; using var condition = new Condition(fake.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake.IsTrueOrNull) { Name = "IsTrueOrNull" }; using var negatedCondition = new Negated <Condition>(condition); Assert.AreEqual("Not_" + condition.Name, negatedCondition.Name); }
public void NegateTwiceReturnsOriginal() { var fake = new Fake { IsTrueOrNull = false }; using (var condition = new Condition(fake.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake.IsTrueOrNull)) { using (var negatedCondition = new Negated <Condition>(condition)) { #pragma warning disable 618 using (var negatedTwice = negatedCondition.Negate()) #pragma warning restore 618 { Assert.AreSame(condition, negatedTwice); } } } }
public override bool EvaluateAsBoolean(EvaluationContext context) { return(!Negated.EvaluateAsBoolean(context)); }
public override string EvaluateAsString(EvaluationContext context) { // no negation for string return("!" + Negated.EvaluateAsString(context)); }
public int GetHashCode(VariableRelation obj) { return (obj.A.GetHashCode() ^ obj.Rel.GetHashCode() ^ obj.B.GetHashCode() ^ Negated.GetHashCode()); }
/// <summary> /// Gets a unique hash code describing this object that is guarenteed to not change over the lifetime /// of this object. /// </summary> /// <returns></returns> public override int GetHashCode() { return(Name.GetHashCode() ^ Negated.GetHashCode()); }