Skip to content

Commit

Permalink
switch arguments for expected and actual in Assert.AreEquals in multi…
Browse files Browse the repository at this point in the history
…ple tests (#685)

* arrange Assert.AreEqual expected and actual arguments.

* Assert.AreEqual(false, to Assert.IsFalse(

* Assert.AreEqual(true, to Assert.IsTrue(

* Assert.AreEqual(null, to Assert.IsNull(

* fixed some asserts that require Assert.AreEqual

* fixed some others
  • Loading branch information
HeroMaxPower authored Feb 26, 2020
1 parent 088fcd9 commit 6815ba5
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void CompareToShouldReturnZeroIfTwoObjectHasSameDataValue()
{
TestFrameworkV2.GenericParameterHelper objectToCompare = new TestFrameworkV2.GenericParameterHelper(10);

TestFrameworkV1.Assert.AreEqual(this.sut.CompareTo(objectToCompare), 0);
TestFrameworkV1.Assert.AreEqual(0, this.sut.CompareTo(objectToCompare));
}

[TestFrameworkV1.TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void DebugTraceShouldReturnTraceOutput()
var logMessageListener = new LogMessageListener(true);
StringWriter writer = new StringWriter(new StringBuilder("DummyTrace"));
this.testablePlatformServiceProvider.MockTraceListener.Setup(tl => tl.GetWriter()).Returns(writer);
Assert.AreEqual(logMessageListener.DebugTrace, "DummyTrace");
Assert.AreEqual("DummyTrace", logMessageListener.DebugTrace);
}

#region Dispose Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void GetSettingsShouldSetCanParallelizeAssemblyToTrueByDefault()
var settings = this.testAssemblySettingProvider.GetSettings("Foo");

// Assert.
Assert.AreEqual(true, settings.CanParallelizeAssembly);
Assert.IsTrue(settings.CanParallelizeAssembly);
}

[TestMethod]
Expand All @@ -171,7 +171,7 @@ public void GetSettingsShouldSetCanParallelizeAssemblyToFalseIfDoNotParallelizeI
var settings = this.testAssemblySettingProvider.GetSettings("Foo");

// Assert.
Assert.AreEqual(false, settings.CanParallelizeAssembly);
Assert.IsFalse(settings.CanParallelizeAssembly);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void TestClassInfoClassCleanupMethodShouldNotInvokeWhenNoTestClassInitial

var ret = this.testClassInfo.RunClassCleanup(); // call cleanup without calling init

Assert.AreEqual(null, ret);
Assert.IsNull(ret);
Assert.AreEqual(0, classcleanupCallCount);
}

Expand All @@ -140,7 +140,7 @@ public void TestClassInfoClassCleanupMethodShouldNotInvokeBaseClassCleanupMethod

var ret = this.testClassInfo.RunClassCleanup(); // call cleanup without calling init

Assert.AreEqual(null, ret);
Assert.IsNull(ret);
Assert.AreEqual(0, classcleanupCallCount);
}

Expand All @@ -156,7 +156,7 @@ public void TestClassInfoClassCleanupMethodShouldInvokeWhenTestClassInitializedI
this.testClassInfo.RunClassInitialize(this.testContext);
var ret = this.testClassInfo.RunClassCleanup(); // call cleanup without calling init

Assert.AreEqual(null, ret);
Assert.IsNull(ret);
Assert.AreEqual(1, classcleanupCallCount);
}

Expand All @@ -174,7 +174,7 @@ public void TestClassInfoClassCleanupMethodShouldInvokeBaseClassCleanupMethodWhe
this.testClassInfo.RunClassInitialize(this.testContext);
var ret = this.testClassInfo.RunClassCleanup();

Assert.AreEqual(null, ret);
Assert.IsNull(ret);
Assert.AreEqual(1, classcleanupCallCount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public void RunTestsShouldClearSessionParametersAcrossRuns()
// Trigger another Run
this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken());

Assert.AreEqual(DummyTestClass.TestContextProperties["webAppUrl"], "http://updatedLocalHost");
Assert.AreEqual("http://updatedLocalHost", DummyTestClass.TestContextProperties["webAppUrl"]);
}

#endregion
Expand Down Expand Up @@ -426,7 +426,7 @@ public void RunTestsForMultipleSourcesShouldRunEachTestJustOnce()
};

testableTestExecutionmanager.RunTests(sources, this.runContext, this.frameworkHandle, this.cancellationToken);
Assert.AreEqual(testsCount, 4);
Assert.AreEqual(4, testsCount);
}

#endregion
Expand All @@ -440,8 +440,8 @@ public void SendTestResultsShouldFillInDataRowIndexIfTestIsDataDriven()
UnitTestResult unitTestResult1 = new UnitTestResult() { DatarowIndex = 0, DisplayName = "DummyTest" };
UnitTestResult unitTestResult2 = new UnitTestResult() { DatarowIndex = 1, DisplayName = "DummyTest" };
this.TestExecutionManager.SendTestResults(testCase, new UnitTestResult[] { unitTestResult1, unitTestResult2 }, default(DateTimeOffset), default(DateTimeOffset), this.frameworkHandle);
Assert.AreEqual(this.frameworkHandle.TestDisplayNameList[0], "DummyTest (Data Row 0)");
Assert.AreEqual(this.frameworkHandle.TestDisplayNameList[1], "DummyTest (Data Row 1)");
Assert.AreEqual("DummyTest (Data Row 0)", this.frameworkHandle.TestDisplayNameList[0]);
Assert.AreEqual("DummyTest (Data Row 1)", this.frameworkHandle.TestDisplayNameList[1]);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void PropertyProviderForPriorityPropertyReturnPriorityTestProperty()
public void PropertyProviderValueForInvalidTestCaseReturnsNull()
{
var result = this.TestMethodFilter.PropertyValueProvider(null, "Hello");
Assert.AreEqual(null, result);
Assert.IsNull(result);
}

[TestMethod]
Expand All @@ -82,7 +82,7 @@ public void PropertyProviderValueForInvalidPropertyNameReturnsNull()
TestCase testCase = new TestCase(fullName, MSTest.TestAdapter.Constants.ExecutorUri, Assembly.GetExecutingAssembly().FullName);

var result = this.TestMethodFilter.PropertyValueProvider(testCase, null);
Assert.AreEqual(null, result);
Assert.IsNull(result);
}

[TestMethod]
Expand All @@ -93,7 +93,7 @@ public void PropertyProviderValueForSupportedPropertyNameWhichIsNotSetReturnsNul

TestCase testCase = new TestCase(fullName, MSTest.TestAdapter.Constants.ExecutorUri, Assembly.GetExecutingAssembly().FullName);
var result = this.TestMethodFilter.PropertyValueProvider(testCase, "Priority");
Assert.AreEqual(null, result);
Assert.IsNull(result);
}

[TestMethod]
Expand All @@ -115,8 +115,8 @@ public void GetFilterExpressionForNullRunContextReturnsNull()
bool filterHasError;
var filterExpression = this.TestMethodFilter.GetFilterExpression(null, recorder, out filterHasError);

Assert.AreEqual(null, filterExpression);
Assert.AreEqual(false, filterHasError);
Assert.IsNull(filterExpression);
Assert.IsFalse(filterHasError);
}

[TestMethod]
Expand All @@ -129,7 +129,7 @@ public void GetFilterExpressionForValidRunContextReturnsValidTestCaseFilterExpre
var filterExpression = this.TestMethodFilter.GetFilterExpression(runContext, recorder, out filterHasError);

Assert.AreEqual(dummyFilterExpression, filterExpression);
Assert.AreEqual(false, filterHasError);
Assert.IsFalse(filterHasError);
}

/// <summary>
Expand All @@ -145,7 +145,7 @@ public void GetFilterExpressionForDiscoveryContextWithGetTestCaseFilterReturnsVa
var filterExpression = this.TestMethodFilter.GetFilterExpression(discoveryContext, recorder, out filterHasError);

Assert.AreEqual(dummyFilterExpression, filterExpression);
Assert.AreEqual(false, filterHasError);
Assert.IsFalse(filterHasError);
}

/// <summary>
Expand All @@ -159,8 +159,8 @@ public void GetFilterExpressionForDiscoveryContextWithoutGetTestCaseFilterReturn
bool filterHasError;
var filterExpression = this.TestMethodFilter.GetFilterExpression(discoveryContext, recorder, out filterHasError);

Assert.AreEqual(null, filterExpression);
Assert.AreEqual(false, filterHasError);
Assert.IsNull(filterExpression);
Assert.IsFalse(filterHasError);
}

[TestMethod]
Expand All @@ -171,8 +171,8 @@ public void GetFilterExpressionForRunContextGetTestCaseFilterThrowingExceptionRe
bool filterHasError;
var filterExpression = this.TestMethodFilter.GetFilterExpression(runContext, recorder, out filterHasError);

Assert.AreEqual(null, filterExpression);
Assert.AreEqual(true, filterHasError);
Assert.IsNull(filterExpression);
Assert.IsTrue(filterHasError);
Assert.AreEqual("DummyException", recorder.Message);
Assert.AreEqual(TestMessageLevel.Error, recorder.TestMessageLevel);
}
Expand All @@ -188,8 +188,8 @@ public void GetFilterExpressionForDiscoveryContextWithGetTestCaseFilterThrowingE
bool filterHasError;
var filterExpression = this.TestMethodFilter.GetFilterExpression(discoveryContext, recorder, out filterHasError);

Assert.AreEqual(null, filterExpression);
Assert.AreEqual(true, filterHasError);
Assert.IsNull(filterExpression);
Assert.IsTrue(filterHasError);
Assert.AreEqual("DummyException", recorder.Message);
Assert.AreEqual(TestMessageLevel.Error, recorder.TestMessageLevel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ public void HandleMethodExceptionShouldInvokeVerifyOfCustomExpectedException()

DummyTestClass.TestMethodBody = o => { throw new DivideByZeroException(); };
var result = method.Invoke(null);
Assert.AreEqual(true, customExpectedException.IsVerifyInvoked);
Assert.IsTrue(customExpectedException.IsVerifyInvoked);
Assert.AreEqual(UTF.UnitTestOutcome.Passed, result.Outcome);
}

Expand All @@ -1027,7 +1027,7 @@ public void HandleMethodExceptionShouldSetOutcomeAsFailedIfVerifyOfExpectedExcep

DummyTestClass.TestMethodBody = o => { throw new DivideByZeroException(); };
var result = method.Invoke(null);
Assert.AreEqual(result.TestFailureException.Message, "The exception message doesn't contain the string defined in the exception attribute");
Assert.AreEqual("The exception message doesn't contain the string defined in the exception attribute", result.TestFailureException.Message);
Assert.AreEqual(UTF.UnitTestOutcome.Failed, result.Outcome);
}

Expand Down Expand Up @@ -1062,7 +1062,7 @@ public void HandleMethodExceptionShouldInvokeVerifyOfDerivedCustomExpectedExcept

DummyTestClass.TestMethodBody = o => { throw new DivideByZeroException(); };
var result = method.Invoke(null);
Assert.AreEqual(true, derivedCustomExpectedException.IsVerifyInvoked);
Assert.IsTrue(derivedCustomExpectedException.IsVerifyInvoked);
Assert.AreEqual(UTF.UnitTestOutcome.Passed, result.Outcome);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsP
this.mockReflectHelper.Setup(rh => rh.GetIgnoreMessage(typeof(DummyTestClass).GetTypeInfo())).Returns("IgnoreTestClassMessage");

var results = testMethodRunner.Execute();
Assert.AreEqual(results[0].Outcome, AdapterTestOutcome.Ignored);
Assert.AreEqual(results[0].ErrorMessage, "IgnoreTestClassMessage");
Assert.AreEqual(AdapterTestOutcome.Ignored, results[0].Outcome);
Assert.AreEqual("IgnoreTestClassMessage", results[0].ErrorMessage);
}

[TestMethodV1]
Expand All @@ -148,8 +148,8 @@ public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsP
this.mockReflectHelper.Setup(rh => rh.GetIgnoreMessage(typeof(DummyTestClass).GetTypeInfo())).Returns(string.Empty);

var results = testMethodRunner.Execute();
Assert.AreEqual(results[0].Outcome, AdapterTestOutcome.Ignored);
Assert.AreEqual(results[0].ErrorMessage, string.Empty);
Assert.AreEqual(AdapterTestOutcome.Ignored, results[0].Outcome);
Assert.AreEqual(string.Empty, results[0].ErrorMessage);
}

[TestMethodV1]
Expand All @@ -164,8 +164,8 @@ public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIs
this.mockReflectHelper.Setup(rh => rh.GetIgnoreMessage(this.methodInfo)).Returns("IgnoreMethodMessage");

var results = testMethodRunner.Execute();
Assert.AreEqual(results[0].Outcome, AdapterTestOutcome.Ignored);
Assert.AreEqual(results[0].ErrorMessage, "IgnoreMethodMessage");
Assert.AreEqual(AdapterTestOutcome.Ignored, results[0].Outcome);
Assert.AreEqual("IgnoreMethodMessage", results[0].ErrorMessage);
}

[TestMethodV1]
Expand All @@ -180,8 +180,8 @@ public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsP
this.mockReflectHelper.Setup(rh => rh.GetIgnoreMessage(this.methodInfo)).Returns(string.Empty);

var results = testMethodRunner.Execute();
Assert.AreEqual(results[0].Outcome, AdapterTestOutcome.Ignored);
Assert.AreEqual(results[0].ErrorMessage, string.Empty);
Assert.AreEqual(AdapterTestOutcome.Ignored, results[0].Outcome);
Assert.AreEqual(string.Empty, results[0].ErrorMessage);
}

[TestMethodV1]
Expand All @@ -198,8 +198,8 @@ public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsP
this.mockReflectHelper.Setup(rh => rh.GetIgnoreMessage(this.methodInfo)).Returns("IgnoreMethodMessage");

var results = testMethodRunner.Execute();
Assert.AreEqual(results[0].Outcome, AdapterTestOutcome.Ignored);
Assert.AreEqual(results[0].ErrorMessage, "IgnoreTestClassMessage");
Assert.AreEqual(AdapterTestOutcome.Ignored, results[0].Outcome);
Assert.AreEqual("IgnoreTestClassMessage", results[0].ErrorMessage);
}

[TestMethodV1]
Expand All @@ -216,8 +216,8 @@ public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIs
this.mockReflectHelper.Setup(rh => rh.GetIgnoreMessage(this.methodInfo)).Returns("IgnoreMethodMessage");

var results = testMethodRunner.Execute();
Assert.AreEqual(results[0].Outcome, AdapterTestOutcome.Ignored);
Assert.AreEqual(results[0].ErrorMessage, "IgnoreMethodMessage");
Assert.AreEqual(AdapterTestOutcome.Ignored, results[0].Outcome);
Assert.AreEqual("IgnoreMethodMessage", results[0].ErrorMessage);
}

[TestMethodV1]
Expand Down Expand Up @@ -552,10 +552,10 @@ public void RunTestMethodShouldSetDataRowIndexForDataDrivenTestsWhenDataIsProvid

// check for datarowIndex
// 1st is parent result.
Assert.AreEqual(results[0].DatarowIndex, -1);
Assert.AreEqual(results[1].DatarowIndex, 0);
Assert.AreEqual(results[2].DatarowIndex, 1);
Assert.AreEqual(results[3].DatarowIndex, 2);
Assert.AreEqual(-1, results[0].DatarowIndex);
Assert.AreEqual(0, results[1].DatarowIndex);
Assert.AreEqual(1, results[2].DatarowIndex);
Assert.AreEqual(2, results[3].DatarowIndex);
}

[TestMethodV1]
Expand All @@ -581,10 +581,10 @@ public void RunTestMethodShoudlRunOnlyDataSourceTestsWhenBothDataSourceAndDataRo

// check for datarowIndex as only DataSource Tests are Run
// 1st is parent result.
Assert.AreEqual(results[0].DatarowIndex, -1);
Assert.AreEqual(results[1].DatarowIndex, 0);
Assert.AreEqual(results[2].DatarowIndex, 1);
Assert.AreEqual(results[3].DatarowIndex, 2);
Assert.AreEqual(-1, results[0].DatarowIndex);
Assert.AreEqual(0, results[1].DatarowIndex);
Assert.AreEqual(1, results[2].DatarowIndex);
Assert.AreEqual(2, results[3].DatarowIndex);
}

[TestMethodV1]
Expand All @@ -610,7 +610,7 @@ public void RunTestMethodShouldFillInDisplayNameWithDataRowDisplayNameIfProvided

// 1st results should be parent result.
Assert.AreEqual(2, results.Length);
Assert.AreEqual(results[1].DisplayName, "DataRowTestDisplayName");
Assert.AreEqual("DataRowTestDisplayName", results[1].DisplayName);
}

[TestMethodV1]
Expand All @@ -635,7 +635,7 @@ public void RunTestMethodShouldFillInDisplayNameWithDataRowArgumentsIfNoDisplayN

// 1st results should be parent result.
Assert.AreEqual(2, results.Length);
Assert.AreEqual(results[1].DisplayName, "DummyTestMethod (2,DummyString)");
Assert.AreEqual("DummyTestMethod (2,DummyString)", results[1].DisplayName);
}

[TestMethodV1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ public void ResolveExpectedExceptionHelperShouldReturnNullIfExpectedExceptionAtt

UTF.ExpectedExceptionAttribute expectedException = new UTF.ExpectedExceptionAttribute(typeof(DivideByZeroException));

Assert.AreEqual(null, testMethodInfo.TestMethodOptions.ExpectedException);
Assert.IsNull(testMethodInfo.TestMethodOptions.ExpectedException);
}

[TestMethodV1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ public void IsUnitTestAssertExceptionSetsOutcomeAsInconclusiveIfAssertInconclusi

exception.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out stackTraceInfo);

Assert.AreEqual(outcome, UTF.UnitTestOutcome.Inconclusive);
Assert.AreEqual(exceptionMessage, "Dummy Message");
Assert.AreEqual(UTF.UnitTestOutcome.Inconclusive, outcome);
Assert.AreEqual("Dummy Message", exceptionMessage);
}

[TestMethod]
Expand All @@ -218,8 +218,8 @@ public void IsUnitTestAssertExceptionSetsOutcomeAsFailedIfAssertFailedException(

exception.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out stackTraceInfo);

Assert.AreEqual(outcome, UTF.UnitTestOutcome.Failed);
Assert.AreEqual(exceptionMessage, "Dummy Message");
Assert.AreEqual(UTF.UnitTestOutcome.Failed, outcome);
Assert.AreEqual("Dummy Message", exceptionMessage);
}
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public void ToUnitTestElementShouldReturnUnitTestElementWithFieldsSet()

var resultUnitTestElement = testCase.ToUnitTestElement(testCase.Source);

Assert.AreEqual(true, resultUnitTestElement.IsAsync);
Assert.IsTrue(resultUnitTestElement.IsAsync);
Assert.AreEqual(2, resultUnitTestElement.Priority);
Assert.AreEqual(testCategories, resultUnitTestElement.TestCategory);
Assert.AreEqual("DummyDisplayName", resultUnitTestElement.DisplayName);
Assert.AreEqual("DummyMethod", resultUnitTestElement.TestMethod.Name);
Assert.AreEqual("DummyClassName", resultUnitTestElement.TestMethod.FullClassName);
Assert.AreEqual(true, resultUnitTestElement.TestMethod.IsAsync);
Assert.IsTrue(resultUnitTestElement.TestMethod.IsAsync);
Assert.IsNull(resultUnitTestElement.TestMethod.DeclaringClassFullName);
}

Expand All @@ -50,9 +50,9 @@ public void ToUnitTestElementForTestCaseWithNoPropertiesShouldReturnUnitTestElem
var resultUnitTestElement = testCase.ToUnitTestElement(testCase.Source);

// These are set for testCase by default by ObjectModel.
Assert.AreEqual(false, resultUnitTestElement.IsAsync);
Assert.IsFalse(resultUnitTestElement.IsAsync);
Assert.AreEqual(0, resultUnitTestElement.Priority);
Assert.AreEqual(null, resultUnitTestElement.TestCategory);
Assert.IsNull(resultUnitTestElement.TestCategory);
}

[TestMethod]
Expand Down
Loading

0 comments on commit 6815ba5

Please sign in to comment.