public void GetClientBalance_ServiceReturnException_ReturnInternalServerError() { AddressService.ResetCalls(); long clientId = 1; var exceptionMessage = "some exception message"; AddressService.Setup(x => x.GetBalance(clientId)).Throws(new Exception(exceptionMessage)); var controller = new AddressController(AddressService.Object, Logger.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } }; controller.ControllerContext.HttpContext.Items.Add("clientId", clientId); var actionResult = controller.GetBalance(); var result = actionResult as OkObjectResult; var result1 = actionResult as ObjectResult; AddressService.Verify(x => x.GetBalance(clientId), Times.Once); Assert.AreEqual(result, null); Assert.IsTrue(result == null); Assert.IsTrue(result1 != null); Assert.AreEqual(result1.StatusCode, 500); Assert.AreEqual(result1.Value, exceptionMessage); }
public void GetClientBalance_AddressExisted_ReturnOk() { AddressService.ResetCalls(); long clientId = 1; var balance = 456.1245m; AddressService.Setup(x => x.GetBalance(clientId)).Returns(balance); var controller = new AddressController(AddressService.Object, Logger.Object) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } }; controller.ControllerContext.HttpContext.Items.Add("clientId", clientId); var actionResult = controller.GetBalance(); var result = actionResult as OkObjectResult; AddressService.Verify(x => x.GetBalance(clientId), Times.Once); Assert.AreEqual(result.StatusCode, 200); Assert.AreEqual(result.Value, balance); }