예제 #1
0
        public virtual async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);
            var        client     = new ApiClient(testServer.CreateClient());

            client.SetBearerToken(JWTTestHelper.GenerateBearerToken());
            ApplicationDbContext context = testServer.Host.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;

            IColumnSameAsFKTableService service = testServer.Host.Services.GetService(typeof(IColumnSameAsFKTableService)) as IColumnSameAsFKTableService;
            var model = new ApiColumnSameAsFKTableServerRequestModel();

            model.SetProperties(1, 1);
            CreateResponse <ApiColumnSameAsFKTableServerResponseModel> createdResponse = await service.Create(model);

            createdResponse.Success.Should().BeTrue();

            ActionResponse deleteResult = await client.ColumnSameAsFKTableDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();
            ApiColumnSameAsFKTableServerResponseModel verifyResponse = await service.Get(2);

            verifyResponse.Should().BeNull();
        }
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiColumnSameAsFKTableServerModelMapper();
            var model  = new ApiColumnSameAsFKTableServerResponseModel();

            model.SetProperties(1, 1, 1);
            ApiColumnSameAsFKTableServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.Person.Should().Be(1);
            response.PersonId.Should().Be(1);
        }
예제 #3
0
        public virtual async Task <IActionResult> Create([FromBody] ApiColumnSameAsFKTableServerRequestModel model)
        {
            CreateResponse <ApiColumnSameAsFKTableServerResponseModel> result = await this.ColumnSameAsFKTableService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/ColumnSameAsFKTables/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public void CreatePatch()
        {
            var mapper = new ApiColumnSameAsFKTableServerModelMapper();
            var model  = new ApiColumnSameAsFKTableServerRequestModel();

            model.SetProperties(1, 1);

            JsonPatchDocument <ApiColumnSameAsFKTableServerRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiColumnSameAsFKTableServerRequestModel();

            patch.ApplyTo(response);
            response.Person.Should().Be(1);
            response.PersonId.Should().Be(1);
        }
예제 #5
0
        private async Task <ApiColumnSameAsFKTableServerRequestModel> PatchModel(int id, JsonPatchDocument <ApiColumnSameAsFKTableServerRequestModel> patch)
        {
            var record = await this.ColumnSameAsFKTableService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiColumnSameAsFKTableServerRequestModel request = this.ColumnSameAsFKTableModelMapper.MapServerResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
예제 #6
0
        public async void Delete_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock  = new ServiceMockFacade <IColumnSameAsFKTableService, IColumnSameAsFKTableRepository>();
            var model = new ApiColumnSameAsFKTableServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new ColumnSameAsFKTableService(mock.LoggerMock.Object,
                                                         mock.MediatorMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         mock.ModelValidatorMockFactory.ColumnSameAsFKTableModelValidatorMock.Object,
                                                         mock.DALMapperMockFactory.DALColumnSameAsFKTableMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.ColumnSameAsFKTableModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <ColumnSameAsFKTableDeletedNotification>(), It.IsAny <CancellationToken>()));
        }
예제 #7
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiColumnSameAsFKTableServerRequestModel model)
        {
            ApiColumnSameAsFKTableServerRequestModel request = await this.PatchModel(id, this.ColumnSameAsFKTableModelMapper.CreatePatch(model)) as ApiColumnSameAsFKTableServerRequestModel;

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiColumnSameAsFKTableServerResponseModel> result = await this.ColumnSameAsFKTableService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
예제 #8
0
        public async void Delete_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <IColumnSameAsFKTableService, IColumnSameAsFKTableRepository>();
            var model         = new ApiColumnSameAsFKTableServerRequestModel();
            var validatorMock = new Mock <IApiColumnSameAsFKTableServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateDeleteAsync(It.IsAny <int>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new ColumnSameAsFKTableService(mock.LoggerMock.Object,
                                                         mock.MediatorMock.Object,
                                                         mock.RepositoryMock.Object,
                                                         validatorMock.Object,
                                                         mock.DALMapperMockFactory.DALColumnSameAsFKTableMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <ColumnSameAsFKTableDeletedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }
예제 #9
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiColumnSameAsFKTableServerRequestModel> patch)
        {
            ApiColumnSameAsFKTableServerResponseModel record = await this.ColumnSameAsFKTableService.Get(id);

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

                UpdateResponse <ApiColumnSameAsFKTableServerResponseModel> result = await this.ColumnSameAsFKTableService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }