public void Can_Create_StateCategories() { // Arrange // - create the mock repository Mock<ILocationRepository> mock = new Mock<ILocationRepository>(); mock.Setup(m => m.Locations).Returns(new List<Location> { new Location {Id = 1, Name = "L1", State="MI" }, new Location {Id = 2, Name = "L2", State="IL"}, new Location {Id = 3, Name = "L3", State="MI"}, new Location {Id = 4, Name = "L4", State="IN"}, new Location {Id = 5, Name = "L5", State="MI"} }); // Arrange - create the controller NavController target = new NavController(mock.Object); // Act - get the set of states string[] results = ((IEnumerable<string>)target.Menu().Model).ToArray(); //Assert Assert.AreEqual(results.Length, 3); Assert.AreEqual(results[0], "IL"); Assert.AreEqual(results[1], "IN"); Assert.AreEqual(results[2], "MI"); }
public void Indicates_Selected_State() { // Arrange // - create the mock repository Mock<ILocationRepository> mock = new Mock<ILocationRepository>(); mock.Setup(m => m.Locations).Returns(new List<Location> { new Location {Id = 1, Name = "L1", State="MI" }, new Location {Id = 2, Name = "L2", State="IL"}, new Location {Id = 3, Name = "L3", State="MI"}, new Location {Id = 4, Name = "L4", State="IN"}, new Location {Id = 5, Name = "L5", State="MI"} }); // Arrange - create the controller NavController target = new NavController(mock.Object); //Arrange string stateToSelect = "MI"; // Act - get the set of states string result = target.Menu(stateToSelect).ViewBag.SelectedState; //Assert Assert.AreEqual(result, stateToSelect); }