public void ProcessData_WithInvalidModel_Returns_BadRequestResult() { // Arrange var dataProcessorServiceMock = new Mock <IDataProcessorService>(); var loggerMock = new Mock <ILogger <DataProcessorController> >(); var controller = new DataProcessorController(dataProcessorServiceMock.Object, loggerMock.Object); controller.ModelState.AddModelError("Model", "SomeError"); var model = new DataDTO(); // Act var result = controller.ProcessData(model).GetAwaiter().GetResult(); // Assert Assert.IsType <BadRequestObjectResult>(result); }
public void ProcessData_WithValidModelAndProcessingError_Returns_ConflictResult() { // Arrange var dataProcessorServiceMock = new Mock <IDataProcessorService>(); dataProcessorServiceMock.Setup(service => service .ProcessData(It.IsAny <DataDTO>())) .Returns(Task.FromResult <(ReportDTO, bool)>((null, false))); var loggerMock = new Mock <ILogger <DataProcessorController> >(); var controller = new DataProcessorController(dataProcessorServiceMock.Object, loggerMock.Object); var model = GetData(); // Act var result = controller.ProcessData(model).GetAwaiter().GetResult(); // Assert Assert.IsType <ConflictResult>(result); }
public void ProcessData_WithValidModel_Returns_OkResult() { // Arrange var dataProcessorServiceMock = new Mock <IDataProcessorService>(); dataProcessorServiceMock.Setup(service => service .ProcessData(It.IsAny <DataDTO>())) .Returns(Task.FromResult <(ReportDTO, bool)>((GetReport(), true))); var loggerMock = new Mock <ILogger <DataProcessorController> >(); var controller = new DataProcessorController(dataProcessorServiceMock.Object, loggerMock.Object); var model = GetData(); // Act var result = controller.ProcessData(model).GetAwaiter().GetResult(); // Assert var okObjectResult = Assert.IsType <OkObjectResult>(result); Assert.IsAssignableFrom <ReportDTO>(okObjectResult.Value); }