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

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

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

            records.Add(new ApiLinkRequestModel());
            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 <ApiLinkResponseModel>;

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

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

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

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

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