Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blame Sequence File Changes #1716

Merged
merged 6 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change in UTs
  • Loading branch information
vagisha-nidhi committed Aug 6, 2018
commit 908297c71ebfd434e314b41256afc3261ffb3844
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,6 @@ public override void Initialize(
this.attachmentGuid = Guid.NewGuid().ToString().Replace("-", string.Empty);
}

/// <summary>
/// Returns the testObjectDictionary
/// </summary>
/// <returns> testObjectDictionary </returns>
internal Dictionary<Guid, BlameTestObject> GetTestObjectDictionary()
{
return this.testObjectDictionary;
}

/// <summary>
/// Returns the testSequence for testing
/// </summary>
/// <returns> testSequence </returns>
internal List<Guid> GetTestSequence()
{
return this.testSequence;
}

private void ValidateAndAddProcessDumpParameters(XmlElement collectDumpNode)
{
foreach (XmlAttribute attribute in collectDumpNode.Attributes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ public void TriggerSessionEndedHandlerShouldNotWriteToFileIfNoTestHostCrash()
}

/// <summary>
/// The event handlers should generate correct test sequence and testObjectDictionary if test start count is greater than test end count
/// The event handlers should generate correct test sequence and testObjectDictionary for both completed and not completed tests
/// </summary>
[TestMethod]
public void EventHandlersShouldGenerateCorrectTestSequenceAndTestObjectDictionaryIfTestStartCountIsGreaterThanEndCount()
public void EventHandlersShouldGenerateCorrectTestSequenceAndTestObjectDictionaryForBothCompletedAndNotCompletedTests()
{
// Initializing Blame Data Collector
this.blameDataCollector.Initialize(
Expand All @@ -155,81 +155,18 @@ public void EventHandlersShouldGenerateCorrectTestSequenceAndTestObjectDictionar
blameTestObject1.IsCompleted = true;
this.mockDataColectionEvents.Raise(x => x.SessionEnd += null, new SessionEndEventArgs(this.dataCollectionContext));

// Verify WriteTestSequence Call
this.mockBlameReaderWriter.Verify(x => x.WriteTestSequence(It.IsAny<List<Guid>>(), It.IsAny<Dictionary<Guid, BlameTestObject>>(), It.IsAny<string>()), Times.Once);

var blameObjectList = new List<BlameTestObject> { blameTestObject1, blameTestObject2 };

// Verify test sequence
var testSequence = this.blameDataCollector.GetTestSequence();
Assert.AreEqual(testSequence.Count, 2);
Assert.AreEqual(testSequence.First(), blameTestObject1.Id);
Assert.AreEqual(testSequence.Last(), blameTestObject2.Id);

// Verify testObjectDictionary
var testObjectDictionary = this.blameDataCollector.GetTestObjectDictionary();
Assert.AreEqual(testObjectDictionary.Count, 2);

foreach (var blameObject in blameObjectList)
{
Assert.AreEqual(testObjectDictionary[blameObject.Id].FullyQualifiedName, blameObject.FullyQualifiedName);
Assert.AreEqual(testObjectDictionary[blameObject.Id].Source, blameObject.Source);
Assert.AreEqual(testObjectDictionary[blameObject.Id].IsCompleted, blameObject.IsCompleted);
Assert.AreEqual(testObjectDictionary[blameObject.Id].DisplayName, blameObject.DisplayName);
}
}

/// <summary>
/// The event handlers should generate correct test sequence and testObjectDictionary if test start count is same as test end count
/// </summary>
[TestMethod]
public void EventHandlersShouldGenerateCorrectTestSequenceAndTestObjectDictionaryIfTestStartCountIsSameAsEndCount()
{
// Initializing Blame Data Collector
this.blameDataCollector.Initialize(
this.configurationElement,
this.mockDataColectionEvents.Object,
this.mockDataCollectionSink.Object,
this.mockLogger.Object,
this.context);

TestCase testcase1 = new TestCase("TestProject.UnitTest.TestMethod1", new Uri("test:/abc"), "abc.dll");
TestCase testcase2 = new TestCase("TestProject.UnitTest.TestMethod2", new Uri("test:/abc"), "abc.dll");
var blameTestObject1 = new BlameTestObject(testcase1);
var blameTestObject2 = new BlameTestObject(testcase2);

// Setup and Raise TestCaseStart and Session End Event
this.mockBlameReaderWriter.Setup(x => x.WriteTestSequence(It.IsAny<List<Guid>>(), It.IsAny<Dictionary<Guid, BlameTestObject>>(), It.IsAny<string>())).Returns(this.filepath);
this.mockDataColectionEvents.Raise(x => x.TestCaseStart += null, new TestCaseStartEventArgs(testcase1));
this.mockDataColectionEvents.Raise(x => x.TestCaseStart += null, new TestCaseStartEventArgs(testcase2));
this.mockDataColectionEvents.Raise(x => x.TestCaseEnd += null, new TestCaseEndEventArgs(testcase1, TestOutcome.Passed));
blameTestObject1.IsCompleted = true;
this.mockDataColectionEvents.Raise(x => x.TestCaseEnd += null, new TestCaseEndEventArgs(testcase2, TestOutcome.Passed));
blameTestObject2.IsCompleted = true;
this.mockDataColectionEvents.Raise(x => x.SessionEnd += null, new SessionEndEventArgs(this.dataCollectionContext));

// Verify WriteTestSequence Call
this.mockBlameReaderWriter.Verify(x => x.WriteTestSequence(It.IsAny<List<Guid>>(), It.IsAny<Dictionary<Guid, BlameTestObject>>(), It.IsAny<string>()), Times.Never);

var blameObjectList = new List<BlameTestObject> { blameTestObject1, blameTestObject2 };

// Verify test sequence
var testSequence = this.blameDataCollector.GetTestSequence();
Assert.AreEqual(testSequence.Count, 2);
Assert.AreEqual(testSequence.First(), blameTestObject1.Id);
Assert.AreEqual(testSequence.Last(), blameTestObject2.Id);

// Verify testObjectDictionary
var testObjectDictionary = this.blameDataCollector.GetTestObjectDictionary();
Assert.AreEqual(testObjectDictionary.Count, 2);

foreach (var blameObject in blameObjectList)
{
Assert.AreEqual(testObjectDictionary[blameObject.Id].FullyQualifiedName, blameObject.FullyQualifiedName);
Assert.AreEqual(testObjectDictionary[blameObject.Id].Source, blameObject.Source);
Assert.AreEqual(testObjectDictionary[blameObject.Id].IsCompleted, blameObject.IsCompleted);
Assert.AreEqual(testObjectDictionary[blameObject.Id].DisplayName, blameObject.DisplayName);
}
// Verify call to mockBlameReaderWriter
this.mockBlameReaderWriter.Verify(
x => x.WriteTestSequence(
It.Is<List<Guid>>(y => y.Count == 2 && y.First() == blameTestObject1.Id && y.Last() == blameTestObject2.Id),
It.Is<Dictionary<Guid, BlameTestObject>>(
y => y.Count == 2 &&
y[blameTestObject1.Id].IsCompleted == true && y[blameTestObject2.Id].IsCompleted == false &&
y[blameTestObject1.Id].FullyQualifiedName == "TestProject.UnitTest.TestMethod1" && y[blameTestObject2.Id].FullyQualifiedName == "TestProject.UnitTest.TestMethod2" &&
y[blameTestObject1.Id].Source == "abc.dll" && y[blameTestObject2.Id].Source == "abc.dll" &&
y[blameTestObject1.Id].DisplayName == "TestProject.UnitTest.TestMethod1" && y[blameTestObject2.Id].DisplayName == "TestProject.UnitTest.TestMethod2"),
It.IsAny<string>()),
Times.Once);
}

/// <summary>
Expand Down