public async void Create_Errors() { BadgeControllerMockFacade mock = new BadgeControllerMockFacade(); var mockResponse = new Mock <CreateResponse <ApiBadgeServerResponseModel> >(null as ApiBadgeServerResponseModel); var mockRecord = new ApiBadgeServerResponseModel(); mockResponse.SetupGet(x => x.Success).Returns(false); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiBadgeServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiBadgeServerResponseModel> >(mockResponse.Object)); BadgeController controller = new BadgeController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiBadgeServerRequestModel()); response.Should().BeOfType <ObjectResult>(); (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiBadgeServerRequestModel>())); }
public async void Create_No_Errors() { BadgeControllerMockFacade mock = new BadgeControllerMockFacade(); var mockResponse = ValidationResponseFactory <ApiBadgeServerResponseModel> .CreateResponse(null as ApiBadgeServerResponseModel); mockResponse.SetRecord(new ApiBadgeServerResponseModel()); mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiBadgeServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiBadgeServerResponseModel> >(mockResponse)); BadgeController controller = new BadgeController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object); controller.ControllerContext = new ControllerContext(); controller.ControllerContext.HttpContext = new DefaultHttpContext(); IActionResult response = await controller.Create(new ApiBadgeServerRequestModel()); response.Should().BeOfType <CreatedResult>(); (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created); var createResponse = (response as CreatedResult).Value as CreateResponse <ApiBadgeServerResponseModel>; createResponse.Record.Should().NotBeNull(); mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiBadgeServerRequestModel>())); }