Skip to content
This repository has been archived by the owner on May 21, 2018. It is now read-only.

Commit

Permalink
Use collection assert for better assertion errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cskeppstedt committed Nov 17, 2015
1 parent 33db695 commit 323a896
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions T4TS.Tests/Traversal/ProjectTraversalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using T4TS.Example.Models;
using EnvDTE;
using Moq;
using System.Collections.Generic;
using T4TS.Tests.Mocks;

namespace T4TS.Tests.Traversal
{
Expand All @@ -15,42 +17,46 @@ public class ProjectTraversalTests
[TestMethod]
public void ShouldVisitEachNamespace()
{
var proj = new Mocks.MockProjects(null, new Type[]
var proj = new Mocks.MockProjects(subProjectItems: null, types: new Type[]
{
typeof(LocalModel),
typeof(ModelFromDifferentProject)
}).Single();

int callCount = 0;
var expectedNames = new string[] { "T4TS.Tests.Traversal.Models", "T4TS.Example.Models" };
var expectedNames = new List<string> { "T4TS.Tests.Traversal.Models", "T4TS.Example.Models" };
var actualNames = new List<string>();

new ProjectTraverser(proj, (ns) => { Assert.AreEqual(expectedNames[callCount++], ns.Name); });
new ProjectTraverser(proj, (ns) => {
actualNames.Add(ns.Name);
});

Assert.AreEqual(2, callCount);
CollectionAssert.AreEqual(expectedNames, actualNames);
}

[TestMethod]
public void ShouldVisitSubProjectItems()
{
var subProjItem = new Mocks.MockProjectItems(null, new Type[]
var subProjItem = new MockProjectItems(subProjectItems: null, types: new Type[]
{
typeof(ModelFromDifferentProject)
}).Single();

var moqSubProjectItems = new Mock<ProjectItems>();
moqSubProjectItems.Setup(x => x.GetEnumerator()).Returns(() => new[] { subProjItem }.GetEnumerator());

var proj = new Mocks.MockProjects(moqSubProjectItems.Object, new Type[]
var proj = new MockProjects(subProjectItems: moqSubProjectItems.Object, types: new Type[]
{
typeof(LocalModel)
}).Single();

int callCount = 0;
var expectedNames = new string[] { "T4TS.Tests.Traversal.Models", "T4TS.Example.Models" };

new ProjectTraverser(proj, (ns) => { Assert.AreEqual(expectedNames[callCount++], ns.Name); });
var expectedNames = new List<string> { "T4TS.Tests.Traversal.Models", "T4TS.Example.Models" };
var actualNames = new List<string>();

Assert.AreEqual(2, callCount);
new ProjectTraverser(proj, (ns) => {
actualNames.Add(ns.Name);
});

CollectionAssert.AreEqual(expectedNames, actualNames);
}
}
}

0 comments on commit 323a896

Please sign in to comment.