Пример #1
0
        public async void BulkInsert_No_Errors()
        {
            DeviceControllerMockFacade mock = new DeviceControllerMockFacade();

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

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

            records.Add(new ApiDeviceRequestModel());
            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 <ApiDeviceResponseModel>;

            result.Should().NotBeEmpty();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiDeviceRequestModel>()));
        }
Пример #2
0
        public async void BulkInsert_Errors()
        {
            DeviceControllerMockFacade mock = new DeviceControllerMockFacade();

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

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiDeviceServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiDeviceServerResponseModel> >(mockResponse.Object));
            DeviceController controller = new DeviceController(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 <ApiDeviceServerRequestModel>();

            records.Add(new ApiDeviceServerRequestModel());
            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 <ApiDeviceServerRequestModel>()));
        }