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

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

            mockResponse.SetRecord(new ApiHandlerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiHandlerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiHandlerResponseModel> >(mockResponse));
            HandlerController controller = new HandlerController(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 <ApiHandlerRequestModel>();

            records.Add(new ApiHandlerRequestModel());
            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 <ApiHandlerResponseModel>;

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

			var mockResponse = new Mock<CreateResponse<ApiHandlerServerResponseModel>>(null as ApiHandlerServerResponseModel);
			mockResponse.SetupGet(x => x.Success).Returns(false);

			mock.ServiceMock.Setup(x => x.Create(It.IsAny<ApiHandlerServerRequestModel>())).Returns(Task.FromResult<CreateResponse<ApiHandlerServerResponseModel>>(mockResponse.Object));
			HandlerController controller = new HandlerController(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<ApiHandlerServerRequestModel>();
			records.Add(new ApiHandlerServerRequestModel());
			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<ApiHandlerServerRequestModel>()));
		}