Example #1
0
        public async void BulkInsert_No_Errors()
        {
            ChainStatusControllerMockFacade mock = new ChainStatusControllerMockFacade();

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

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

            records.Add(new ApiChainStatusRequestModel());
            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 <ApiChainStatusResponseModel>;

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

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

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

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

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