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

            var mockResponse = ValidationResponseFactory <ApiAdminServerResponseModel> .CreateResponse(null as ApiAdminServerResponseModel);

            mockResponse.SetRecord(new ApiAdminServerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiAdminServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiAdminServerResponseModel> >(mockResponse));
            AdminController controller = new AdminController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiAdminServerRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiAdminServerResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiAdminServerRequestModel>()));
        }
Ejemplo n.º 2
0
        public async void All_Exists()
        {
            AdminControllerMockFacade mock = new AdminControllerMockFacade();
            var record  = new ApiAdminServerResponseModel();
            var records = new List <ApiAdminServerResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(Task.FromResult(records));
            AdminController controller = new AdminController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0, string.Empty);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiAdminServerResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Ejemplo n.º 3
0
        public async void BulkInsert_Errors()
        {
            AdminControllerMockFacade mock = new AdminControllerMockFacade();

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

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

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

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