Пример #1
0
        public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            var createModel = new ApiSpaceFeatureRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiSpaceFeatureResponseModel> createResult = await client.SpaceFeatureCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiSpaceFeatureResponseModel getResponse = await client.SpaceFeatureGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.SpaceFeatureDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiSpaceFeatureResponseModel verifyResponse = await client.SpaceFeatureGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Пример #2
0
        public virtual ApiSpaceFeatureResponseModel MapBOToModel(
            BOSpaceFeature boSpaceFeature)
        {
            var model = new ApiSpaceFeatureResponseModel();

            model.SetProperties(boSpaceFeature.Id, boSpaceFeature.Name);

            return(model);
        }
Пример #3
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiSpaceFeatureModelMapper();
            var model  = new ApiSpaceFeatureResponseModel();

            model.SetProperties(1, "A");
            ApiSpaceFeatureRequestModel response = mapper.MapResponseToRequest(model);

            response.Name.Should().Be("A");
        }
Пример #4
0
        public void MapBOToModel()
        {
            var            mapper = new BOLSpaceFeatureMapper();
            BOSpaceFeature bo     = new BOSpaceFeature();

            bo.SetProperties(1, "A");
            ApiSpaceFeatureResponseModel response = mapper.MapBOToModel(bo);

            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
        }
Пример #5
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiSpaceFeatureResponseModel response = await client.SpaceFeatureGetAsync(1);

            response.Should().NotBeNull();
        }
Пример #6
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiSpaceFeatureResponseModel response = await this.SpaceFeatureService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Пример #7
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <ISpaceFeatureRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <SpaceFeature>(null));
            var service = new SpaceFeatureService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.SpaceFeatureModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLSpaceFeatureMapperMock,
                                                  mock.DALMapperMockFactory.DALSpaceFeatureMapperMock);

            ApiSpaceFeatureResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Пример #8
0
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            ApiSpaceFeatureResponseModel model = await client.SpaceFeatureGetAsync(1);

            ApiSpaceFeatureModelMapper mapper = new ApiSpaceFeatureModelMapper();

            UpdateResponse <ApiSpaceFeatureResponseModel> updateResponse = await client.SpaceFeatureUpdateAsync(model.Id, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
        public async void Create_Errors()
        {
            SpaceFeatureControllerMockFacade mock = new SpaceFeatureControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiSpaceFeatureRequestModel>()));
        }
        public async void All_Exists()
        {
            SpaceFeatureControllerMockFacade mock = new SpaceFeatureControllerMockFacade();
            var record  = new ApiSpaceFeatureResponseModel();
            var records = new List <ApiSpaceFeatureResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            SpaceFeatureController controller = new SpaceFeatureController(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 <ApiSpaceFeatureResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Пример #11
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiSpaceFeatureRequestModel> patch)
        {
            ApiSpaceFeatureResponseModel record = await this.SpaceFeatureService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiSpaceFeatureRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiSpaceFeatureResponseModel> result = await this.SpaceFeatureService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Пример #12
0
        public async void TestGet()
        {
            ApiSpaceFeatureResponseModel response = await this.Client.SpaceFeatureGetAsync(1);

            response.Should().NotBeNull();
        }