Esempio n. 1
0
        public async void BulkInsert_No_Errors()
        {
            StudioControllerMockFacade mock = new StudioControllerMockFacade();

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

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

            records.Add(new ApiStudioRequestModel());
            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 <ApiStudioResponseModel>;

            result.Should().NotBeEmpty();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiStudioRequestModel>()));
        }
Esempio n. 2
0
        public async void BulkInsert_Errors()
        {
            StudioControllerMockFacade mock = new StudioControllerMockFacade();

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

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

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

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