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

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

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

            records.Add(new ApiStudentRequestModel());
            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 <ApiStudentResponseModel>;

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

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

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

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

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