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

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

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

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

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

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).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);

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

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

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

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiAdminRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiAdminResponseModel> >(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 <ApiAdminRequestModel>();

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