Ejemplo n.º 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 ApiTeamRequestModel();

            createModel.SetProperties("B", 1);
            CreateResponse <ApiTeamResponseModel> createResult = await client.TeamCreateAsync(createModel);

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

            ApiTeamResponseModel getResponse = await client.TeamGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.TeamDeleteAsync(2);

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

            ApiTeamResponseModel verifyResponse = await client.TeamGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Ejemplo n.º 2
0
        private async Task <ApiTeamResponseModel> CreateRecord()
        {
            var model = new ApiTeamRequestModel();

            model.SetProperties("B", 1);
            CreateResponse <ApiTeamResponseModel> result = await this.Client.TeamCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
Ejemplo n.º 3
0
        public void MapModelToBO()
        {
            var mapper = new BOLTeamMapper();
            ApiTeamRequestModel model = new ApiTeamRequestModel();

            model.SetProperties("A", 1);
            BOTeam response = mapper.MapModelToBO(1, model);

            response.Name.Should().Be("A");
            response.OrganizationId.Should().Be(1);
        }
Ejemplo n.º 4
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiTeamModelMapper();
            var model  = new ApiTeamResponseModel();

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

            response.Name.Should().Be("A");
            response.OrganizationId.Should().Be(1);
        }
 public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiTeamRequestModel model)
 {
     this.EnvironmentIdsRules();
     this.JSONRules();
     this.MemberUserIdsRules();
     this.NameRules();
     this.ProjectGroupIdsRules();
     this.ProjectIdsRules();
     this.TenantIdsRules();
     this.TenantTagsRules();
     return(await this.ValidateAsync(model, id));
 }
Ejemplo n.º 6
0
        public virtual async Task <IActionResult> Create([FromBody] ApiTeamRequestModel model)
        {
            CreateResponse <ApiTeamResponseModel> result = await this.TeamService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Teams/{result.Record.Id}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Ejemplo n.º 7
0
        public virtual BOTeam MapModelToBO(
            int id,
            ApiTeamRequestModel model
            )
        {
            BOTeam boTeam = new BOTeam();

            boTeam.SetProperties(
                id,
                model.Name,
                model.OrganizationId);
            return(boTeam);
        }
Ejemplo n.º 8
0
        public void CreatePatch()
        {
            var mapper = new ApiTeamModelMapper();
            var model  = new ApiTeamRequestModel();

            model.SetProperties("A", 1);

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

            patch.ApplyTo(response);
            response.Name.Should().Be("A");
            response.OrganizationId.Should().Be(1);
        }
Ejemplo n.º 9
0
        private async Task <ApiTeamRequestModel> PatchModel(int id, JsonPatchDocument <ApiTeamRequestModel> patch)
        {
            var record = await this.TeamService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiTeamRequestModel request = this.TeamModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
Ejemplo n.º 10
0
        public virtual async Task <CreateResponse <ApiTeamResponseModel> > Create(
            ApiTeamRequestModel model)
        {
            CreateResponse <ApiTeamResponseModel> response = new CreateResponse <ApiTeamResponseModel>(await this.TeamModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolTeamMapper.MapModelToBO(default(int), model);
                var record = await this.TeamRepository.Create(this.DalTeamMapper.MapBOToEF(bo));

                response.SetRecord(this.BolTeamMapper.MapBOToModel(this.DalTeamMapper.MapEFToBO(record)));
            }

            return(response);
        }
Ejemplo n.º 11
0
        public void MapModelToBO()
        {
            var mapper = new BOLTeamMapper();
            ApiTeamRequestModel model = new ApiTeamRequestModel();

            model.SetProperties("A", "A", "A", "A", "A", "A", "A", "A");
            BOTeam response = mapper.MapModelToBO("A", model);

            response.EnvironmentIds.Should().Be("A");
            response.JSON.Should().Be("A");
            response.MemberUserIds.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectGroupIds.Should().Be("A");
            response.ProjectIds.Should().Be("A");
            response.TenantIds.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
Ejemplo n.º 12
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiTeamModelMapper();
            var model  = new ApiTeamResponseModel();

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

            response.EnvironmentIds.Should().Be("A");
            response.JSON.Should().Be("A");
            response.MemberUserIds.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectGroupIds.Should().Be("A");
            response.ProjectIds.Should().Be("A");
            response.TenantIds.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
Ejemplo n.º 13
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ITeamRepository>();
            var model = new ApiTeamRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Team>())).Returns(Task.FromResult(new Team()));
            var service = new TeamService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.TeamModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLTeamMapperMock,
                                          mock.DALMapperMockFactory.DALTeamMapperMock);

            CreateResponse <ApiTeamResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.TeamModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTeamRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Team>()));
        }
Ejemplo n.º 14
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ITeamRepository>();
            var model = new ApiTeamRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask);
            var service = new TeamService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.TeamModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLTeamMapperMock,
                                          mock.DALMapperMockFactory.DALTeamMapperMock);

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

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>()));
            mock.ModelValidatorMockFactory.TeamModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>()));
        }
Ejemplo n.º 15
0
        public virtual BOTeam MapModelToBO(
            string id,
            ApiTeamRequestModel model
            )
        {
            BOTeam boTeam = new BOTeam();

            boTeam.SetProperties(
                id,
                model.EnvironmentIds,
                model.JSON,
                model.MemberUserIds,
                model.Name,
                model.ProjectGroupIds,
                model.ProjectIds,
                model.TenantIds,
                model.TenantTags);
            return(boTeam);
        }
Ejemplo n.º 16
0
        public virtual async Task <UpdateResponse <ApiTeamResponseModel> > Update(
            int id,
            ApiTeamRequestModel model)
        {
            var validationResult = await this.TeamModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolTeamMapper.MapModelToBO(id, model);
                await this.TeamRepository.Update(this.DalTeamMapper.MapBOToEF(bo));

                var record = await this.TeamRepository.Get(id);

                return(new UpdateResponse <ApiTeamResponseModel>(this.BolTeamMapper.MapBOToModel(this.DalTeamMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiTeamResponseModel>(validationResult));
            }
        }
Ejemplo n.º 17
0
        public void CreatePatch()
        {
            var mapper = new ApiTeamModelMapper();
            var model  = new ApiTeamRequestModel();

            model.SetProperties("A", "A", "A", "A", "A", "A", "A", "A");

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

            patch.ApplyTo(response);
            response.EnvironmentIds.Should().Be("A");
            response.JSON.Should().Be("A");
            response.MemberUserIds.Should().Be("A");
            response.Name.Should().Be("A");
            response.ProjectGroupIds.Should().Be("A");
            response.ProjectIds.Should().Be("A");
            response.TenantIds.Should().Be("A");
            response.TenantTags.Should().Be("A");
        }
Ejemplo n.º 18
0
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTeamRequestModel model)
        {
            ApiTeamRequestModel request = await this.PatchModel(id, this.TeamModelMapper.CreatePatch(model));

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

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Ejemplo n.º 19
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTeamRequestModel> patch)
        {
            ApiTeamResponseModel record = await this.TeamService.Get(id);

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

                UpdateResponse <ApiTeamResponseModel> result = await this.TeamService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTeamRequestModel model)
 {
     this.NameRules();
     this.OrganizationIdRules();
     return(await this.ValidateAsync(model, id));
 }
Ejemplo n.º 21
0
        public virtual async Task <UpdateResponse <ApiTeamResponseModel> > TeamUpdateAsync(int id, ApiTeamRequestModel item)
        {
            HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Teams/{id}", item).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <UpdateResponse <ApiTeamResponseModel> >(httpResponse.Content.ContentToString()));
        }