public void AddMethodToDynamicCallGraph_CorrectState() { var testName = "MyTest"; var target = new TestStateRecorder(mockMethodDumper); target.StartTest(testName); Assert.IsNotNull(target.CurrentTest); Assert.AreEqual(testName, target.CurrentTest.Name); target.AddMethodToDynamicCallGraph("Bar"); target.AddMethodToDynamicCallGraph("Baz"); target.AddMethodToDynamicCallGraph("Biff"); target.RecordVoidInstanceMethodCall("Hello World", "Foo"); // Assert counter stats AssertRecorderListAndCounterStates( expectedMethodCounter: 1U, expectedTestCounter: 0U, numberOfTestExecutions: 0, target: target); // Should have three calls. Assert.AreEqual(3, target.CurrentMethodCall.DynamicCallGraph.Count); AssertSequencesAreCorrect(target); target.EndTest(); AssertRecorderListAndCounterStates( expectedMethodCounter: 0U, expectedTestCounter: 1U, numberOfTestExecutions: 1, target: target); }
public void StartTest_CorrectState() { var testName = "MyTest"; var target = new TestStateRecorder(mockMethodDumper); target.StartTest(testName); Assert.IsNotNull(target.CurrentTest); Assert.AreEqual(testName, target.CurrentTest.Name); Assert.IsNull(target.CurrentMethodCall); AssertRecorderListAndCounterStates( expectedMethodCounter: 0U, expectedTestCounter: 0U, numberOfTestExecutions: 0, target: target); }
public void RecordVoidInstanceMethodCall_EnsureMethodCounterIncrements() { var testName = "MyTest"; var methodSig1 = "Foo"; var methodSig2 = "Bar"; var target = new TestStateRecorder(mockMethodDumper); target.StartTest(testName); Assert.IsNotNull(target.CurrentTest); Assert.AreEqual(testName, target.CurrentTest.Name); target.RecordVoidInstanceMethodCall(new TestClass(), methodSig1); AssertRecorderListAndCounterStates( expectedMethodCounter: 1U, expectedTestCounter: 0U, numberOfTestExecutions: 0, target: target); target.RecordVoidInstanceMethodCall(new TestClass(), methodSig2); AssertRecorderListAndCounterStates( expectedMethodCounter: 2U, expectedTestCounter: 0U, numberOfTestExecutions: 0, target: target); target.EndTest(); AssertRecorderListAndCounterStates( expectedMethodCounter: 0U, expectedTestCounter: 1U, numberOfTestExecutions: 1, target: target); }
public void RecordVoidInstanceMethodCall_CorrectState() { var testName = "MyTest"; var methodSig = "Foo"; var target = new TestStateRecorder(mockMethodDumper); target.StartTest(testName); target.RecordVoidInstanceMethodCall(new TestClass(), methodSig); // Before: method counter incremented, test counter hasn't yet. Methods has one // element, tests has none until EndTest is called. Assert.IsNotNull(target.CurrentTest); Assert.AreEqual(testName, target.CurrentTest.Name); AssertRecorderListAndCounterStates( expectedMethodCounter: 1U, expectedTestCounter: 0U, numberOfTestExecutions: 0, target: target); target.EndTest(); // After: Method counter and test counter at one now. Both lists have one element. AssertRecorderListAndCounterStates( expectedMethodCounter: 0U, expectedTestCounter: 1U, numberOfTestExecutions: 1, target: target); // The point here isn't to re-test the method call dumper, but just the pieces we interact // with in the state recorder. Assert.IsNotNull(target.AnalysisLog); Assert.IsNotNull(target.AnalysisLog.TestExecutions); // Test executions var testExecution = target.AnalysisLog.TestExecutions.FirstOrDefault(); Assert.IsNotNull(testExecution); Assert.IsNotNull(testExecution.MethodCalls); Assert.AreEqual(1, testExecution.MethodCalls.Count); Assert.AreEqual(0U, testExecution.Id); // Method calls var dumpedCall = testExecution.MethodCalls.FirstOrDefault(); Assert.IsNotNull(dumpedCall); Assert.AreEqual(methodSig, dumpedCall.Signature); // Make sure we recorded the right sig Assert.AreEqual(0U, dumpedCall.Id); // Make sure we recorded the right method call sequence number }
public void EndToEndTest_PassTestBoundary_CorrectState() { var testName1 = "MyTest1"; var testName2 = "MyTest2"; var testClass = new TestClass(); var target = new TestStateRecorder(mockMethodDumper); target.StartTest(testName1); Assert.IsNotNull(target.CurrentTest); Assert.AreEqual(testName1, target.CurrentTest.Name); target.RecordVoidInstanceMethodCall(testClass, "Foo"); target.AddMethodToDynamicCallGraph("Baz"); target.AddMethodToDynamicCallGraph("Biff"); target.RecordInstanceMethodCall(testClass, 5, "Bar"); target.AddMethodToDynamicCallGraph("Zoo"); target.EndTest(); // Test counter state. AssertRecorderListAndCounterStates( expectedMethodCounter: 0U, expectedTestCounter: 1U, numberOfTestExecutions: 1, target: target); // Do it all again. target.StartTest(testName2); Assert.IsNotNull(target.CurrentTest); Assert.AreEqual(testName2, target.CurrentTest.Name); target.AddMethodToDynamicCallGraph("Baz"); target.RecordVoidInstanceMethodCall(testClass, "Foo"); target.AddMethodToDynamicCallGraph("Zoo"); target.AddMethodToDynamicCallGraph("Boo"); target.RecordInstanceMethodCall(testClass, 5, "Bar"); target.EndTest(); // Test counter state AssertRecorderListAndCounterStates( expectedMethodCounter: 0U, expectedTestCounter: 2U, numberOfTestExecutions: 2, target: target); AssertSequencesAreCorrect(target); }
public void EndTest_CorrectState() { var testName = "MyTest"; var target = new TestStateRecorder(mockMethodDumper); target.StartTest(testName); Assert.IsNull(target.CurrentMethodCall); Assert.AreEqual(testName, target.CurrentTest.Name); target.EndTest(); Assert.IsNull(target.CurrentTest); AssertRecorderListAndCounterStates( expectedMethodCounter: 0U, expectedTestCounter: 1U, numberOfTestExecutions: 1, target: target); // Check Id is set to correct counter value. Assert.AreEqual(0U, target.AnalysisLog.TestExecutions.First().Id); }