Beispiel #1
0
        public async void BulkInsert_No_Errors()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();

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

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

            records.Add(new ApiTweetRequestModel());
            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 <ApiTweetResponseModel>;

            result.Should().NotBeEmpty();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiTweetRequestModel>()));
        }
        public async void BulkInsert_Errors()
        {
            TweetControllerMockFacade mock = new TweetControllerMockFacade();

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

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

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

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