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 ApiMachineRequestModel(); createModel.SetProperties("B", "B", "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B"); CreateResponse <ApiMachineResponseModel> createResult = await client.MachineCreateAsync(createModel); createResult.Success.Should().BeTrue(); ApiMachineResponseModel getResponse = await client.MachineGetAsync(2); getResponse.Should().NotBeNull(); ActionResponse deleteResult = await client.MachineDeleteAsync(2); deleteResult.Success.Should().BeTrue(); ApiMachineResponseModel verifyResponse = await client.MachineGetAsync(2); verifyResponse.Should().BeNull(); }
public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiMachineRequestModel model) { this.DescriptionRules(); this.JwtKeyRules(); this.LastIpAddressRules(); this.MachineGuidRules(); this.NameRules(); return(await this.ValidateAsync(model, id)); }
private async Task <ApiMachineResponseModel> CreateRecord() { var model = new ApiMachineRequestModel(); model.SetProperties("B", "B", "B", Guid.Parse("3842cac4-b9a0-8223-0dcc-509a6f75849b"), "B"); CreateResponse <ApiMachineResponseModel> result = await this.Client.MachineCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
private async Task <ApiMachineResponseModel> CreateRecord() { var model = new ApiMachineRequestModel(); model.SetProperties("B", "B", "B", true, "B", "B", "B", "B", "B", "B", "B", "B"); CreateResponse <ApiMachineResponseModel> result = await this.Client.MachineCreateAsync(model); result.Success.Should().BeTrue(); return(result.Record); }
public virtual async Task <IActionResult> Create([FromBody] ApiMachineRequestModel model) { CreateResponse <ApiMachineResponseModel> result = await this.MachineService.Create(model); if (result.Success) { return(this.Created($"{this.Settings.ExternalBaseUrl}/api/Machines/{result.Record.Id}", result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } }
public void MapModelToBO() { var mapper = new BOLMachineMapper(); ApiMachineRequestModel model = new ApiMachineRequestModel(); model.SetProperties("A", "A", "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A"); BOMachine response = mapper.MapModelToBO(1, model); response.Description.Should().Be("A"); response.JwtKey.Should().Be("A"); response.LastIpAddress.Should().Be("A"); response.MachineGuid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Name.Should().Be("A"); }
public virtual async Task <CreateResponse <ApiMachineResponseModel> > Create( ApiMachineRequestModel model) { CreateResponse <ApiMachineResponseModel> response = new CreateResponse <ApiMachineResponseModel>(await this.machineModelValidator.ValidateCreateAsync(model)); if (response.Success) { var bo = this.bolMachineMapper.MapModelToBO(default(string), model); var record = await this.machineRepository.Create(this.dalMachineMapper.MapBOToEF(bo)); response.SetRecord(this.bolMachineMapper.MapBOToModel(this.dalMachineMapper.MapEFToBO(record))); } return(response); }
private async Task <ApiMachineRequestModel> PatchModel(int id, JsonPatchDocument <ApiMachineRequestModel> patch) { var record = await this.MachineService.Get(id); if (record == null) { return(null); } else { ApiMachineRequestModel request = this.MachineModelMapper.MapResponseToRequest(record); patch.ApplyTo(request); return(request); } }
public async Task <ValidationResult> ValidateUpdateAsync(string id, ApiMachineRequestModel model) { this.CommunicationStyleRules(); this.EnvironmentIdsRules(); this.FingerprintRules(); this.IsDisabledRules(); this.JSONRules(); this.MachinePolicyIdRules(); this.NameRules(); this.RelatedDocumentIdsRules(); this.RolesRules(); this.TenantIdsRules(); this.TenantTagsRules(); this.ThumbprintRules(); return(await this.ValidateAsync(model, id)); }
public virtual BOMachine MapModelToBO( int id, ApiMachineRequestModel model ) { BOMachine boMachine = new BOMachine(); boMachine.SetProperties( id, model.Description, model.JwtKey, model.LastIpAddress, model.MachineGuid, model.Name); return(boMachine); }
public void CreatePatch() { var mapper = new ApiMachineModelMapper(); var model = new ApiMachineRequestModel(); model.SetProperties("A", "A", "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), "A"); JsonPatchDocument <ApiMachineRequestModel> patch = mapper.CreatePatch(model); var response = new ApiMachineRequestModel(); patch.ApplyTo(response); response.Description.Should().Be("A"); response.JwtKey.Should().Be("A"); response.LastIpAddress.Should().Be("A"); response.MachineGuid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da")); response.Name.Should().Be("A"); }
public async void Create() { var mock = new ServiceMockFacade <IMachineRepository>(); var model = new ApiMachineRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Machine>())).Returns(Task.FromResult(new Machine())); var service = new MachineService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLMachineMapperMock, mock.DALMapperMockFactory.DALMachineMapperMock); CreateResponse <ApiMachineResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.MachineModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiMachineRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Machine>())); }
public async void Delete() { var mock = new ServiceMockFacade <IMachineRepository>(); var model = new ApiMachineRequestModel(); mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <string>())).Returns(Task.CompletedTask); var service = new MachineService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.MachineModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLMachineMapperMock, mock.DALMapperMockFactory.DALMachineMapperMock); ActionResponse response = await service.Delete(default(string)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <string>())); mock.ModelValidatorMockFactory.MachineModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <string>())); }
public virtual async Task <UpdateResponse <ApiMachineResponseModel> > Update( string id, ApiMachineRequestModel model) { var validationResult = await this.machineModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { var bo = this.bolMachineMapper.MapModelToBO(id, model); await this.machineRepository.Update(this.dalMachineMapper.MapBOToEF(bo)); var record = await this.machineRepository.Get(id); return(new UpdateResponse <ApiMachineResponseModel>(this.bolMachineMapper.MapBOToModel(this.dalMachineMapper.MapEFToBO(record)))); } else { return(new UpdateResponse <ApiMachineResponseModel>(validationResult)); } }
public void MapResponseToRequest() { var mapper = new ApiMachineModelMapper(); var model = new ApiMachineResponseModel(); model.SetProperties("A", "A", "A", "A", true, "A", "A", "A", "A", "A", "A", "A", "A"); ApiMachineRequestModel response = mapper.MapResponseToRequest(model); response.CommunicationStyle.Should().Be("A"); response.EnvironmentIds.Should().Be("A"); response.Fingerprint.Should().Be("A"); response.IsDisabled.Should().Be(true); response.JSON.Should().Be("A"); response.MachinePolicyId.Should().Be("A"); response.Name.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.Roles.Should().Be("A"); response.TenantIds.Should().Be("A"); response.TenantTags.Should().Be("A"); response.Thumbprint.Should().Be("A"); }
public virtual async Task <IActionResult> Update(int id, [FromBody] ApiMachineRequestModel model) { ApiMachineRequestModel request = await this.PatchModel(id, this.MachineModelMapper.CreatePatch(model)); if (request == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { UpdateResponse <ApiMachineResponseModel> result = await this.MachineService.Update(id, request); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual BOMachine MapModelToBO( string id, ApiMachineRequestModel model ) { BOMachine boMachine = new BOMachine(); boMachine.SetProperties( id, model.CommunicationStyle, model.EnvironmentIds, model.Fingerprint, model.IsDisabled, model.JSON, model.MachinePolicyId, model.Name, model.RelatedDocumentIds, model.Roles, model.TenantIds, model.TenantTags, model.Thumbprint); return(boMachine); }
public void CreatePatch() { var mapper = new ApiMachineModelMapper(); var model = new ApiMachineRequestModel(); model.SetProperties("A", "A", "A", true, "A", "A", "A", "A", "A", "A", "A", "A"); JsonPatchDocument <ApiMachineRequestModel> patch = mapper.CreatePatch(model); var response = new ApiMachineRequestModel(); patch.ApplyTo(response); response.CommunicationStyle.Should().Be("A"); response.EnvironmentIds.Should().Be("A"); response.Fingerprint.Should().Be("A"); response.IsDisabled.Should().Be(true); response.JSON.Should().Be("A"); response.MachinePolicyId.Should().Be("A"); response.Name.Should().Be("A"); response.RelatedDocumentIds.Should().Be("A"); response.Roles.Should().Be("A"); response.TenantIds.Should().Be("A"); response.TenantTags.Should().Be("A"); response.Thumbprint.Should().Be("A"); }
public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiMachineRequestModel> patch) { ApiMachineResponseModel record = await this.MachineService.Get(id); if (record == null) { return(this.StatusCode(StatusCodes.Status404NotFound)); } else { ApiMachineRequestModel model = await this.PatchModel(id, patch); UpdateResponse <ApiMachineResponseModel> result = await this.MachineService.Update(id, model); if (result.Success) { return(this.Ok(result)); } else { return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result)); } } }
public virtual async Task <UpdateResponse <ApiMachineResponseModel> > MachineUpdateAsync(int id, ApiMachineRequestModel item) { HttpResponseMessage httpResponse = await this.client.PutAsJsonAsync($"api/Machines/{id}", item).ConfigureAwait(false); return(JsonConvert.DeserializeObject <UpdateResponse <ApiMachineResponseModel> >(httpResponse.Content.ContentToString())); }