Skip to content

Commit

Permalink
Added AreEqual and AreNotEqual tests (microsoft#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroMaxPower committed Apr 6, 2021
1 parent 712986b commit f579469
Showing 1 changed file with 242 additions and 0 deletions.
242 changes: 242 additions & 0 deletions test/UnitTests/MSTest.Core.Unit.Tests/Assertions/AssertTests.cs
Expand Up @@ -322,5 +322,247 @@ public void IsTrueNullableBooleansShouldFailWithNull()
StringAssert.Contains(ex.Message, "Assert.IsTrue failed");
}
#endregion

#region AreNotEqual tests.

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualType()
{
Action action = () => TestFrameworkV2.Assert.AreNotEqual(null, null);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualTypeWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual(null, null, "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualString()
{
Action action = () => TestFrameworkV2.Assert.AreNotEqual("A", "A");
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualStringWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual("A", "A", "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualStringAndCaseIgnored()
{
Action action = () => TestFrameworkV2.Assert.AreNotEqual("A", "a", true);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualInt()
{
Action action = () => TestFrameworkV2.Assert.AreNotEqual(1, 1);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualIntWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual(1, 1, "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualLong()
{
Action action = () => TestFrameworkV2.Assert.AreNotEqual(1L, 1L);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualLongWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual(1L, 1L, "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualLongWithDelta()
{
Action action = () => TestFrameworkV2.Assert.AreNotEqual(1L, 2L, 1L);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualDouble()
{
Action action = () => TestFrameworkV2.Assert.AreNotEqual(0.1, 0.1);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualDoubleWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual(0.1, 0.1, "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualDoubleWithDelta()
{
Action action = () => TestFrameworkV2.Assert.AreNotEqual(0.1, 0.2, 0.1);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreNotEqualShouldFailWhenFloatDouble()
{
Action action = () => TestFrameworkV2.Assert.AreNotEqual(100E-2, 100E-2);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreNotEqualShouldFailWhenFloatDoubleWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual(100E-2, 100E-2, "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreNotEqualShouldFailWhenNotEqualFloatWithDelta()
{
Action action = () => TestFrameworkV2.Assert.AreNotEqual(100E-2, 200E-2, 100E-2);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}
#endregion

#region AreEqual tests.
[TestMethod]
public void AreEqualShouldFailWhenNotEqualType()
{
Action action = () => TestFrameworkV2.Assert.AreEqual(null, "string");
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualTypeWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(null, "string", "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualString()
{
Action action = () => TestFrameworkV2.Assert.AreEqual("A", "a");
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualStringWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual("A", "a", "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualStringAndCaseIgnored()
{
Action action = () => TestFrameworkV2.Assert.AreEqual("A", "a", false);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualInt()
{
Action action = () => TestFrameworkV2.Assert.AreEqual(1, 2);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualIntWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(1, 2, "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualLong()
{
Action action = () => TestFrameworkV2.Assert.AreEqual(1L, 2L);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualLongWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(1L, 2L, "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualLongWithDelta()
{
Action action = () => TestFrameworkV2.Assert.AreEqual(10L, 20L, 5L);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualDouble()
{
Action action = () => TestFrameworkV2.Assert.AreEqual(0.1, 0.2);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualDoubleWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(0.1, 0.2, "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualDoubleWithDelta()
{
Action action = () => TestFrameworkV2.Assert.AreEqual(0.1, 0.2, 0.05);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreEqualShouldFailWhenFloatDouble()
{
Action action = () => TestFrameworkV2.Assert.AreEqual(100E-2, 200E-2);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
public void AreEqualShouldFailWhenFloatDoubleWithMessage()
{
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(100E-2, 200E-2, "A Message"));
Assert.IsNotNull(ex);
StringAssert.Contains(ex.Message, "A Message");
}

[TestMethod]
public void AreEqualShouldFailWhenNotEqualFloatWithDelta()
{
Action action = () => TestFrameworkV2.Assert.AreEqual(100E-2, 200E-2, 50E-2);
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

#endregion
}
}

0 comments on commit f579469

Please sign in to comment.