public async Task PostToggleAsync_BadRequest() { var mock = new Mock <IToggleBusinessManager>(); mock.Setup(toggleBusinessManager => toggleBusinessManager.PostToggleAsync(null)); using (var controller = new ToggleController(mock.Object)) { var responseActionResult = await controller.PostToggleAsync(null) as BadRequestResult; Assert.IsNotNull(responseActionResult); } }
public async Task PostToggleAsync_InternalServerError() { var toogleDto = ToggleFakeData.GetToggleDto2(); var id = Guid.NewGuid().ToString(); var mock = new Mock <IToggleBusinessManager>(); mock.Setup(toggleBusinessManager => toggleBusinessManager.PostToggleAsync(toogleDto)).Throws(new NullReferenceException()); using (var controller = new ToggleController(mock.Object)) { var responseActionResult = await controller.PostToggleAsync(toogleDto) as ExceptionResult; Assert.IsNotNull(responseActionResult); Assert.IsTrue(responseActionResult.Exception is NullReferenceException); } }
public async Task PostToggleAsync_Ok() { var toogleDto = ToggleFakeData.GetToggleDto2(); var mock = new Mock <IToggleBusinessManager>(); mock.Setup(toggleBusinessManager => toggleBusinessManager.PostToggleAsync(toogleDto)).Returns(Task.FromResult(new Response <ToggleDto> { IsValid = true, Result = toogleDto })); using (var controller = new ToggleController(mock.Object)) { var responseActionResult = await controller.PostToggleAsync(toogleDto) as OkNegotiatedContentResult <Response <ToggleDto> >; Assert.IsNotNull(responseActionResult); Assert.IsTrue(responseActionResult.Content.IsValid); Assert.IsNotNull(responseActionResult.Content.Result); } }