public void GetPagesCount_SizeLessThanZero_Test() { var theaterServiceMock = new Mock <ITheaterService>(); int size = new int(); theaterServiceMock.Setup(x => x.GetPagesCount(size)).Throws(new InvalidOperationException("Size should be positive numbers.")); var controller = new TheaterController(theaterServiceMock.Object); var actualResult = controller.GetPagesCount(size); var badRequestResult = (BadRequestObjectResult)actualResult; var asJson = JsonConvert.SerializeObject(badRequestResult.Value); var deserialized = JsonConvert.DeserializeObject <Dictionary <string, object> >(asJson); Assert.AreEqual("Size should be positive numbers.", deserialized["Error"]); theaterServiceMock.VerifyAll(); }
public void GetPagesCount_InternalServerError_Test() { var theaterServiceMock = new Mock <ITheaterService>(); int size = new int(); theaterServiceMock.Setup(x => x.GetPagesCount(size)).Throws <Exception>(); var controller = new TheaterController(theaterServiceMock.Object); var actualResult = controller.GetPagesCount(size); var badRequestResult = (ObjectResult)actualResult; var asJson = JsonConvert.SerializeObject(badRequestResult.Value); var deserialized = JsonConvert.DeserializeObject <Dictionary <string, object> >(asJson); Assert.IsTrue((bool)deserialized["Success"] == false); theaterServiceMock.VerifyAll(); }
public void GetPagesCount_Successfully_Test() { var theaterServiceMock = new Mock <ITheaterService>(); int size = new int(); theaterServiceMock.Setup(x => x.GetPagesCount(size)); var controller = new TheaterController(theaterServiceMock.Object); var actualResult = controller.GetPagesCount(size); var okResult = (OkObjectResult)actualResult; var asJson = JsonConvert.SerializeObject(okResult.Value); var deserialized = JsonConvert.DeserializeObject <Dictionary <string, object> >(asJson); Assert.IsTrue((bool)deserialized["Success"]); theaterServiceMock.VerifyAll(); }