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

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

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

            records.Add(new ApiTeamRequestModel());
            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 <ApiTeamResponseModel>;

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

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

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

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

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