public void Can_Get_Details() { // Arrange // - create the mock repository Mock<IEventStore> mock = new Mock<IEventStore>(); var allEvents = new List<IEvent<IIdentity>>() { new ProductAddedToOrder() {Id = new OrderId(777), Date = DateTime.Now, Version = 1}, new ProductAddedToOrder() {Id = new OrderId(777), Date = DateTime.Now, Version = 3}, new ProductAddedToOrder() {Id = new OrderId(777), Date = DateTime.Now, Version = 5} }; mock.Setup(m => m.GetEventsForAggregate<IIdentity>(It.IsAny<IIdentity>())).Returns(allEvents.AsQueryable()); // create instance of a controller EventViewerController controller = new EventViewerController(mock.Object); // Action: try to find event with Version = 3 string result = (string)((ViewResultBase)controller.Details("777", 3)).ViewData["EventDetails"]; // Assert Assert.IsTrue(result.Length > 0); Assert.IsTrue(result.Contains("\"Version\": 3,")); }
public void Can_Get_Details() { // Arrange // - create the mock repository Mock<IEventStore> mock = new Mock<IEventStore>(); var allEvents = new IEvent[] { new ProductAddedToOrder() {Id = new OrderId(777), Date = DateTime.Now, Version = 1}, new ProductAddedToOrder() {Id = new OrderId(777), Date = DateTime.Now, Version = 3}, new ProductAddedToOrder() {Id = new OrderId(777), Date = DateTime.Now, Version = 5} }; mock.Setup(m => m.GetEventsForAggregate(It.IsAny<string>())).Returns(allEvents.AsQueryable()); // create instance of a controller EventViewerController controller = new EventViewerController(mock.Object); // Action: try to find event with Version = 3 var result = ((ViewResultBase)controller.Details("777", 3)).Model as EventDetailsViewModel; // Assert Assert.IsNotNull(result); Assert.IsNotNull(result.EventDetails); }