Exemplo n.º 1
0
        public async void BulkInsert_No_Errors()
        {
            CityControllerMockFacade mock = new CityControllerMockFacade();

            var mockResponse = new CreateResponse <ApiCityResponseModel>(new FluentValidation.Results.ValidationResult());

            mockResponse.SetRecord(new ApiCityResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCityRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCityResponseModel> >(mockResponse));
            CityController controller = new CityController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var records = new List <ApiCityRequestModel>();

            records.Add(new ApiCityRequestModel());
            IActionResult response = await controller.BulkInsert(records);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var result = (response as OkObjectResult).Value as List <ApiCityResponseModel>;

            result.Should().NotBeEmpty();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCityRequestModel>()));
        }
Exemplo n.º 2
0
        public async void BulkInsert_Errors()
        {
            CityControllerMockFacade mock = new CityControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiCityServerResponseModel> >(null as ApiCityServerResponseModel);

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiCityServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiCityServerResponseModel> >(mockResponse.Object));
            CityController controller = new CityController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            var records = new List <ApiCityServerRequestModel>();

            records.Add(new ApiCityServerRequestModel());
            IActionResult response = await controller.BulkInsert(records);

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiCityServerRequestModel>()));
        }