public void TestIntersect()
        {
            var constraint = new Constraint {NotBefore = new ImplementationVersion("1"), Before = new ImplementationVersion("2")};
            Assert.AreEqual(new VersionRange("1..!2"), new VersionRange().Intersect(constraint));
            Assert.AreEqual(new VersionRange("1..!2"), new VersionRange("..!3").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("2..!3").Intersect(constraint));
            Assert.AreEqual(new VersionRange("1"), new VersionRange("1").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("3").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("2").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("0").Intersect(constraint));
            Assert.AreEqual(new VersionRange("1..!2"), new VersionRange("!3").Intersect(constraint));
            Assert.AreEqual(new VersionRange("1..!2"), new VersionRange("!2").Intersect(constraint));
            Assert.AreEqual(new VersionRange("1..!2"), new VersionRange("!0").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("!1").Intersect(constraint));

            constraint = new Constraint {Before = new ImplementationVersion("2")};
            Assert.AreEqual(new VersionRange("..!2"), new VersionRange().Intersect(constraint));
            Assert.AreEqual(new VersionRange("..!2"), new VersionRange("..!3").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("2..!3").Intersect(constraint));
            Assert.AreEqual(new VersionRange("1"), new VersionRange("1").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("3").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("2").Intersect(constraint));
            Assert.AreEqual(new VersionRange("..!2"), new VersionRange("!3").Intersect(constraint));
            Assert.AreEqual(new VersionRange("..!2"), new VersionRange("!2").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("!1").Intersect(constraint));

            constraint = new Constraint {NotBefore = new ImplementationVersion("1")};
            Assert.AreEqual(new VersionRange("1.."), new VersionRange().Intersect(constraint));
            Assert.AreEqual(new VersionRange("1..!3"), new VersionRange("..!3").Intersect(constraint));
            Assert.AreEqual(new VersionRange("2..!3"), new VersionRange("2..!3").Intersect(constraint));
            Assert.AreEqual(new VersionRange("1"), new VersionRange("1").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("0").Intersect(constraint));
            Assert.AreEqual(new VersionRange("1.."), new VersionRange("!0").Intersect(constraint));
            Assert.AreEqual(VersionRange.None, new VersionRange("!1").Intersect(constraint));
        }
Example #2
0
 /// <summary>
 /// Display Expected and Actual lines for a constraint. This
 /// is called by MessageWriter's default implementation of 
 /// WriteMessageTo and provides the generic two-line display. 
 /// </summary>
 /// <param name="constraint">The constraint that failed</param>
 public abstract void DisplayDifferences(Constraint constraint);
Example #3
0
 /// <summary>
 /// Apply a constraint to an actual value, succeedingt if the constraint
 /// is satisfied and throwing an assertion exception on failure.
 /// </summary>
 /// <param name="constraint">A Constraint to be applied</param>
 /// <param name="actual">The actual value to test</param>
 /// <param name="message">The message that will be displayed on failure</param>
 /// <param name="args">Arguments to be used in formatting the message</param>
 static public void That(object actual, Constraint constraint, string message, params object[] args)
 {
     Assert.IncrementAssertCount();
     if (!constraint.Matches(actual))
     {
         MessageWriter writer = new TextMessageWriter(message, args);
         constraint.WriteMessageTo(writer);
         throw new AssertionException(writer.ToString());
     }
 }
Example #4
0
 /// <summary>
 /// Apply a constraint to an actual value, succeeding if the constraint
 /// is satisfied and throwing an assertion exception on failure.
 /// </summary>
 /// <param name="constraint">A Constraint to be applied</param>
 /// <param name="actual">The actual value to test</param>
 static public void That(object actual, Constraint constraint)
 {
     Assert.That(actual, constraint, null, null);
 }
Example #5
0
 /// <summary>
 /// Apply a constraint to an actual value, succeedingt if the constraint
 /// is satisfied and throwing an assertion exception on failure.
 /// </summary>
 /// <param name="constraint">A Constraint to be applied</param>
 /// <param name="actual">The actual value to test</param>
 /// <param name="message">The message that will be displayed on failure</param>
 static public void That(object actual, Constraint constraint, string message)
 {
     Assert.That(actual, constraint, message, null);
 }
Example #6
0
		public NotConstraint (Constraint constraint)
		{
			this.constraint = constraint;
		}
 /// <summary>
 /// Write the generic 'Actual' line for a constraint
 /// </summary>
 /// <param name="constraint">The constraint for which the actual value is to be written</param>
 private void WriteActualLine(Constraint constraint)
 {
     Write(Pfx_Actual);
     constraint.WriteActualValueTo(this);
     WriteLine();
 }
 /// <summary>
 /// Write the generic 'Expected' line for a constraint
 /// </summary>
 /// <param name="constraint">The constraint that failed</param>
 private void WriteExpectedLine(Constraint constraint)
 {
     Write(Pfx_Expected);
     constraint.WriteDescriptionTo(this);
     WriteLine();
 }
 /// <summary>
 /// Display Expected and Actual lines for a constraint. This
 /// is called by MessageWriter's default implementation of 
 /// WriteMessageTo and provides the generic two-line display. 
 /// </summary>
 /// <param name="constraint">The constraint that failed</param>
 public override void DisplayDifferences(Constraint constraint)
 {
     WriteExpectedLine(constraint);
     WriteActualLine(constraint);
 }
Example #10
0
        public void TestIntersect()
        {
            var constraint = new Constraint {NotBefore = new ImplementationVersion("1"), Before = new ImplementationVersion("2")};
            new VersionRange().Intersect(constraint).Should().Be(new VersionRange("1..!2"));
            new VersionRange("..!3").Intersect(constraint).Should().Be(new VersionRange("1..!2"));
            new VersionRange("2..!3").Intersect(constraint).Should().Be(VersionRange.None);
            new VersionRange("1").Intersect(constraint).Should().Be(new VersionRange("1"));
            new VersionRange("3").Intersect(constraint).Should().Be(VersionRange.None);
            new VersionRange("2").Intersect(constraint).Should().Be(VersionRange.None);
            new VersionRange("0").Intersect(constraint).Should().Be(VersionRange.None);
            new VersionRange("!3").Intersect(constraint).Should().Be(new VersionRange("1..!2"));
            new VersionRange("!2").Intersect(constraint).Should().Be(new VersionRange("1..!2"));
            new VersionRange("!0").Intersect(constraint).Should().Be(new VersionRange("1..!2"));
            new VersionRange("!1").Intersect(constraint).Should().Be(VersionRange.None);

            constraint = new Constraint {Before = new ImplementationVersion("2")};
            new VersionRange().Intersect(constraint).Should().Be(new VersionRange("..!2"));
            new VersionRange("..!3").Intersect(constraint).Should().Be(new VersionRange("..!2"));
            new VersionRange("2..!3").Intersect(constraint).Should().Be(VersionRange.None);
            new VersionRange("1").Intersect(constraint).Should().Be(new VersionRange("1"));
            new VersionRange("3").Intersect(constraint).Should().Be(VersionRange.None);
            new VersionRange("2").Intersect(constraint).Should().Be(VersionRange.None);
            new VersionRange("!3").Intersect(constraint).Should().Be(new VersionRange("..!2"));
            new VersionRange("!2").Intersect(constraint).Should().Be(new VersionRange("..!2"));
            new VersionRange("!1").Intersect(constraint).Should().Be(VersionRange.None);

            constraint = new Constraint {NotBefore = new ImplementationVersion("1")};
            new VersionRange().Intersect(constraint).Should().Be(new VersionRange("1.."));
            new VersionRange("..!3").Intersect(constraint).Should().Be(new VersionRange("1..!3"));
            new VersionRange("2..!3").Intersect(constraint).Should().Be(new VersionRange("2..!3"));
            new VersionRange("1").Intersect(constraint).Should().Be(new VersionRange("1"));
            new VersionRange("0").Intersect(constraint).Should().Be(VersionRange.None);
            new VersionRange("!0").Intersect(constraint).Should().Be(new VersionRange("1.."));
            new VersionRange("!1").Intersect(constraint).Should().Be(VersionRange.None);
        }