public void GetRamdom_OK() { // Arrange var fact = new ChuckNorrisFunFact() { Id = 1, ModifiedBy = "Me", ModifiedWhen = new DateTime(1000), Fact = "Some Fact", Rating = 10 }; var repository = new Mock <IFunFactsRepository>(); repository.Setup(ffr => ffr.GetRandom()).Returns(fact); ChuckNorrisFunFactsController controller = new ChuckNorrisFunFactsController(repository.Object); // Act var response = controller.GetRamdom(); // Assert Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <IFunFact>)); var result = (response as OkNegotiatedContentResult <IFunFact>).Content; var serializer = new JavaScriptSerializer(); Assert.AreEqual(serializer.Serialize(fact), serializer.Serialize(result)); }
public void GetRamdom_NotFound() { // Arrange var repository = new Mock <IFunFactsRepository>(); repository.Setup(ffr => ffr.GetRandom()).Returns <IFunFact>(null); ChuckNorrisFunFactsController controller = new ChuckNorrisFunFactsController(repository.Object); // Act var response = controller.GetRamdom(); // Assert Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(NotFoundResult)); }