Skip to content

Commit f579469

Browse files
authored
Added AreEqual and AreNotEqual tests (microsoft#809)
1 parent 712986b commit f579469

File tree

1 file changed

+242
-0
lines changed

1 file changed

+242
-0
lines changed

test/UnitTests/MSTest.Core.Unit.Tests/Assertions/AssertTests.cs

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,5 +322,247 @@ public void IsTrueNullableBooleansShouldFailWithNull()
322322
StringAssert.Contains(ex.Message, "Assert.IsTrue failed");
323323
}
324324
#endregion
325+
326+
#region AreNotEqual tests.
327+
328+
[TestMethod]
329+
public void AreNotEqualShouldFailWhenNotEqualType()
330+
{
331+
Action action = () => TestFrameworkV2.Assert.AreNotEqual(null, null);
332+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
333+
}
334+
335+
[TestMethod]
336+
public void AreNotEqualShouldFailWhenNotEqualTypeWithMessage()
337+
{
338+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual(null, null, "A Message"));
339+
Assert.IsNotNull(ex);
340+
StringAssert.Contains(ex.Message, "A Message");
341+
}
342+
343+
[TestMethod]
344+
public void AreNotEqualShouldFailWhenNotEqualString()
345+
{
346+
Action action = () => TestFrameworkV2.Assert.AreNotEqual("A", "A");
347+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
348+
}
349+
350+
[TestMethod]
351+
public void AreNotEqualShouldFailWhenNotEqualStringWithMessage()
352+
{
353+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual("A", "A", "A Message"));
354+
Assert.IsNotNull(ex);
355+
StringAssert.Contains(ex.Message, "A Message");
356+
}
357+
358+
[TestMethod]
359+
public void AreNotEqualShouldFailWhenNotEqualStringAndCaseIgnored()
360+
{
361+
Action action = () => TestFrameworkV2.Assert.AreNotEqual("A", "a", true);
362+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
363+
}
364+
365+
[TestMethod]
366+
public void AreNotEqualShouldFailWhenNotEqualInt()
367+
{
368+
Action action = () => TestFrameworkV2.Assert.AreNotEqual(1, 1);
369+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
370+
}
371+
372+
[TestMethod]
373+
public void AreNotEqualShouldFailWhenNotEqualIntWithMessage()
374+
{
375+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual(1, 1, "A Message"));
376+
Assert.IsNotNull(ex);
377+
StringAssert.Contains(ex.Message, "A Message");
378+
}
379+
380+
[TestMethod]
381+
public void AreNotEqualShouldFailWhenNotEqualLong()
382+
{
383+
Action action = () => TestFrameworkV2.Assert.AreNotEqual(1L, 1L);
384+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
385+
}
386+
387+
[TestMethod]
388+
public void AreNotEqualShouldFailWhenNotEqualLongWithMessage()
389+
{
390+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual(1L, 1L, "A Message"));
391+
Assert.IsNotNull(ex);
392+
StringAssert.Contains(ex.Message, "A Message");
393+
}
394+
395+
[TestMethod]
396+
public void AreNotEqualShouldFailWhenNotEqualLongWithDelta()
397+
{
398+
Action action = () => TestFrameworkV2.Assert.AreNotEqual(1L, 2L, 1L);
399+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
400+
}
401+
402+
[TestMethod]
403+
public void AreNotEqualShouldFailWhenNotEqualDouble()
404+
{
405+
Action action = () => TestFrameworkV2.Assert.AreNotEqual(0.1, 0.1);
406+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
407+
}
408+
409+
[TestMethod]
410+
public void AreNotEqualShouldFailWhenNotEqualDoubleWithMessage()
411+
{
412+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual(0.1, 0.1, "A Message"));
413+
Assert.IsNotNull(ex);
414+
StringAssert.Contains(ex.Message, "A Message");
415+
}
416+
417+
[TestMethod]
418+
public void AreNotEqualShouldFailWhenNotEqualDoubleWithDelta()
419+
{
420+
Action action = () => TestFrameworkV2.Assert.AreNotEqual(0.1, 0.2, 0.1);
421+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
422+
}
423+
424+
[TestMethod]
425+
public void AreNotEqualShouldFailWhenFloatDouble()
426+
{
427+
Action action = () => TestFrameworkV2.Assert.AreNotEqual(100E-2, 100E-2);
428+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
429+
}
430+
431+
[TestMethod]
432+
public void AreNotEqualShouldFailWhenFloatDoubleWithMessage()
433+
{
434+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreNotEqual(100E-2, 100E-2, "A Message"));
435+
Assert.IsNotNull(ex);
436+
StringAssert.Contains(ex.Message, "A Message");
437+
}
438+
439+
[TestMethod]
440+
public void AreNotEqualShouldFailWhenNotEqualFloatWithDelta()
441+
{
442+
Action action = () => TestFrameworkV2.Assert.AreNotEqual(100E-2, 200E-2, 100E-2);
443+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
444+
}
445+
#endregion
446+
447+
#region AreEqual tests.
448+
[TestMethod]
449+
public void AreEqualShouldFailWhenNotEqualType()
450+
{
451+
Action action = () => TestFrameworkV2.Assert.AreEqual(null, "string");
452+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
453+
}
454+
455+
[TestMethod]
456+
public void AreEqualShouldFailWhenNotEqualTypeWithMessage()
457+
{
458+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(null, "string", "A Message"));
459+
Assert.IsNotNull(ex);
460+
StringAssert.Contains(ex.Message, "A Message");
461+
}
462+
463+
[TestMethod]
464+
public void AreEqualShouldFailWhenNotEqualString()
465+
{
466+
Action action = () => TestFrameworkV2.Assert.AreEqual("A", "a");
467+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
468+
}
469+
470+
[TestMethod]
471+
public void AreEqualShouldFailWhenNotEqualStringWithMessage()
472+
{
473+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual("A", "a", "A Message"));
474+
Assert.IsNotNull(ex);
475+
StringAssert.Contains(ex.Message, "A Message");
476+
}
477+
478+
[TestMethod]
479+
public void AreEqualShouldFailWhenNotEqualStringAndCaseIgnored()
480+
{
481+
Action action = () => TestFrameworkV2.Assert.AreEqual("A", "a", false);
482+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
483+
}
484+
485+
[TestMethod]
486+
public void AreEqualShouldFailWhenNotEqualInt()
487+
{
488+
Action action = () => TestFrameworkV2.Assert.AreEqual(1, 2);
489+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
490+
}
491+
492+
[TestMethod]
493+
public void AreEqualShouldFailWhenNotEqualIntWithMessage()
494+
{
495+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(1, 2, "A Message"));
496+
Assert.IsNotNull(ex);
497+
StringAssert.Contains(ex.Message, "A Message");
498+
}
499+
500+
[TestMethod]
501+
public void AreEqualShouldFailWhenNotEqualLong()
502+
{
503+
Action action = () => TestFrameworkV2.Assert.AreEqual(1L, 2L);
504+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
505+
}
506+
507+
[TestMethod]
508+
public void AreEqualShouldFailWhenNotEqualLongWithMessage()
509+
{
510+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(1L, 2L, "A Message"));
511+
Assert.IsNotNull(ex);
512+
StringAssert.Contains(ex.Message, "A Message");
513+
}
514+
515+
[TestMethod]
516+
public void AreEqualShouldFailWhenNotEqualLongWithDelta()
517+
{
518+
Action action = () => TestFrameworkV2.Assert.AreEqual(10L, 20L, 5L);
519+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
520+
}
521+
522+
[TestMethod]
523+
public void AreEqualShouldFailWhenNotEqualDouble()
524+
{
525+
Action action = () => TestFrameworkV2.Assert.AreEqual(0.1, 0.2);
526+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
527+
}
528+
529+
[TestMethod]
530+
public void AreEqualShouldFailWhenNotEqualDoubleWithMessage()
531+
{
532+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(0.1, 0.2, "A Message"));
533+
Assert.IsNotNull(ex);
534+
StringAssert.Contains(ex.Message, "A Message");
535+
}
536+
537+
[TestMethod]
538+
public void AreEqualShouldFailWhenNotEqualDoubleWithDelta()
539+
{
540+
Action action = () => TestFrameworkV2.Assert.AreEqual(0.1, 0.2, 0.05);
541+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
542+
}
543+
544+
[TestMethod]
545+
public void AreEqualShouldFailWhenFloatDouble()
546+
{
547+
Action action = () => TestFrameworkV2.Assert.AreEqual(100E-2, 200E-2);
548+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
549+
}
550+
551+
[TestMethod]
552+
public void AreEqualShouldFailWhenFloatDoubleWithMessage()
553+
{
554+
var ex = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.Assert.AreEqual(100E-2, 200E-2, "A Message"));
555+
Assert.IsNotNull(ex);
556+
StringAssert.Contains(ex.Message, "A Message");
557+
}
558+
559+
[TestMethod]
560+
public void AreEqualShouldFailWhenNotEqualFloatWithDelta()
561+
{
562+
Action action = () => TestFrameworkV2.Assert.AreEqual(100E-2, 200E-2, 50E-2);
563+
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
564+
}
565+
566+
#endregion
325567
}
326568
}

0 commit comments

Comments
 (0)