public async Task Update_Infrastructure_Exception() { Log.Logger.Information($"Begin of Update_Infrastructure_Exception() unit test."); var updateModel = new UpdateResourceModel { InstanceType = InstanceType.XLarge, Memory = new Memory { Size = 100, SpaceSizeUnit = SizeUnit.GiB }, NetworkPerformance = Performance.High, Processor = new Processor { Cores = 64, Speed = 300 }, Storage = new Storage { Size = 800, VolumeType = VolumeType.Extension }, Tag = "New Dev Machine 2" }; Log.Logger.Information($"Begin of UpdateAsync()"); var updateTask = infrastructureOperation.UpdateAsync("ABC", "UAT", updateModel); var exception = await Assert.ThrowsAnyAsync <Exception>(() => updateTask); Log.Error(exception, "Error updating infrastructure."); Log.Logger.Information($"End of UpdateAsync()"); }
public async Task Update_Infrastructure() { Log.Logger.Information($"Begin of Update_Infrastructure()"); var updateModel = new UpdateResourceModel { InstanceType = InstanceType.XLarge, Memory = new Memory { Size = 100, SpaceSizeUnit = SizeUnit.GiB }, NetworkPerformance = Performance.High, Processor = new Processor { Cores = 64, Speed = 300 }, Storage = new Storage { Size = 800, VolumeType = VolumeType.Extension }, Tag = "New Dev Machine 2" }; Log.Logger.Information($"Begin of UpdateAsync()"); await infrastructureOperation.UpdateAsync("IGS", "UAT", updateModel); Log.Logger.Information($"End of UpdateAsync()"); }
public async Task UpdateResourceTransactionAsync(Resource entity, UpdateResourceModel model, FileDestinationMetadata metadata = null) { if (model.Info != null) { model.Info.CopyTo(entity); if (model.Info.Image != null) { await SetResourceImageUrlAsync(entity, model.Info.Image, metadata); } if (model.Info.Logo != null) { await SetResourceLogoUrlAsync(entity, model.Info.Logo, metadata); } } if (model.NewResourceContents != null) { CreateResourceContents(model.NewResourceContents, entity); } if (model.UpdateResourceContents != null) { UpdateResourceContents(model.UpdateResourceContents, entity.Id); } if (model.DeleteResourceContentLangs != null) { await DeleteContentsOfResourceAsync(model.DeleteResourceContentLangs, entity.Id); } if (model.CategoryIds != null) { await DeleteAllCategoriesOfResourceAsync(entity); AddResourceCategoriesToResource(model.CategoryIds, entity); } }
public async Task UpdateAsync(string providerName, string infraName, UpdateResourceModel model) { try { _logger.Information($"Begin of {nameof(UpdateAsync)} method."); var resourceFileOperation = new ResourceFileOperation(_logger); var deserializedJson = await LoadAsync(providerName, infraName); var newJsonContent = resourceFileOperation.UpdateResourceFile(deserializedJson, model); var infraJsonPath = await _findInfrastructure.FindInfrastructureJsonPathAsync(providerName, infraName); await File.WriteAllTextAsync(infraJsonPath, newJsonContent.ToString()); _logger.Information($"End of {nameof(UpdateAsync)} method."); } catch (ArgumentNullException argumentNullExp) { _logger.Error(argumentNullExp, $"One or more argument is null. {GetType().Name}.{nameof(UpdateAsync)}"); throw; } catch (ArgumentException argumentExp) { _logger.Error(argumentExp, $"Arguments error. {GetType().Name}.{nameof(UpdateAsync)}"); throw; } catch (JsonReaderException jsonReaderExp) { _logger.Error(jsonReaderExp, $"Error reading Json resource config file. {GetType().Name}.{nameof(UpdateAsync)}"); throw; } catch (DirectoryNotFoundException directoryNotFoundExp) { _logger.Error(directoryNotFoundExp, $"Infrastructure resource directory is not existed. {GetType().Name}.{nameof(UpdateAsync)}"); throw; } catch (IOException ioExp) { _logger.Error(ioExp, $"Can not access infrastructure resource config file. { GetType().Name}.{ nameof(UpdateAsync)}"); throw; } catch (Exception exp) { _logger.Error(exp, $"Error finding infrastructure resource config file. { GetType().Name}.{ nameof(UpdateAsync)}"); throw; } }
public JObject UpdateResourceFile(JObject deserializedJsonContent, UpdateResourceModel updateResourceModel) { try { _logger.Information($"Begin of {nameof(UpdateResourceFile)} method."); _deserializedJsonContent = deserializedJsonContent; _updateResourceModel = updateResourceModel; resourceFileToken = _deserializedJsonContent.Property("ResourceFile").First() .Last().Children().FirstOrDefault(); UpdateInstanceType(); UpdateStorage(); UpdateProcessor(); UpdateMemory(); UpdateNetwork(); UpdateTag(); _logger.Information($"End of {nameof(UpdateResourceFile)} method."); return(_deserializedJsonContent); } catch (ArgumentNullException argumentNullExp) { _logger.Error(argumentNullExp, $"One or more argument is null. {GetType().Name}.{nameof(UpdateResourceFile)}"); throw; } catch (ArgumentException argumentExp) { _logger.Error(argumentExp, $"Arguments error. {GetType().Name}.{nameof(UpdateResourceFile)}"); throw; } catch (DirectoryNotFoundException directoryNotFoundExp) { _logger.Error(directoryNotFoundExp, $"Infrastructure resource directory is not existed. {GetType().Name}.{nameof(UpdateResourceFile)}"); throw; } catch (IOException ioExp) { _logger.Error(ioExp, $"Can not access infrastructure resource config file. { GetType().Name}.{ nameof(UpdateResourceFile)}"); throw; } catch (Exception exp) { _logger.Error(exp, $"Error finding infrastructure resource config file. { GetType().Name}.{ nameof(UpdateResourceFile)}"); throw; } }
public IActionResult Update(int id, UpdateResourceModel model) { var entity = _service.Resources.Id(id).FirstOrDefault(); if (entity == null) { return(NotFound(AppResult.NotFound())); } var validationData = _service.ValidateUpdateResource(User, entity, model); if (!validationData.IsValid) { return(BadRequest(AppResult.FailValidation(data: validationData))); } _service.UpdateResource(entity, model); context.SaveChanges(); return(NoContent()); }
public async Task <IActionResult> Update(int id, UpdateResourceModel model) { var entity = _service.Resources.Id(id).FirstOrDefault(); if (entity == null) { return(NotFound(new AppResultBuilder().NotFound())); } var validationResult = _service.ValidateUpdateResource(User, entity, model); if (!validationResult.Valid) { return(BadRequest(validationResult.Result)); } using (var trans = context.Database.BeginTransaction()) { await _service.UpdateResourceTransactionAsync(entity, model); context.SaveChanges(); trans.Commit(); } return(NoContent()); }
public ValidationData ValidateUpdateResource(ClaimsPrincipal principal, Resource entity, UpdateResourceModel model) { return(new ValidationData()); }
public void UpdateResource(Resource entity, UpdateResourceModel model) { model.CopyTo(entity); }
public ValidationResult ValidateUpdateResource(ClaimsPrincipal principal, Resource entity, UpdateResourceModel model) { return(ValidationResult.Pass()); }