public async Task <TResult> GetAsync <TResult>(ISecret <TResult> secret, IErrorsAndInfos errorsAndInfos) where TResult : class, ISecretResult <TResult>, new() { TResult valueOrDefault; SaveSample(secret, false); var encrypted = secret is IEncryptedSecret <TResult>; var fileName = FileName(secret, false, encrypted); if (!File.Exists(fileName)) { if (SecretShouldDefaultSecretsBeStored == null) { SecretShouldDefaultSecretsBeStored = new SecretShouldDefaultSecretsBeStored(); await GetAsync(SecretShouldDefaultSecretsBeStored, errorsAndInfos); } var shouldDefaultSecretsBeStored = await ValueOrDefaultAsync(SecretShouldDefaultSecretsBeStored, errorsAndInfos); if (!shouldDefaultSecretsBeStored.AutomaticallySaveDefaultSecretIfAbsent) { SaveSample(secret, true); var defaultFileName = FileName(secret, true, encrypted); errorsAndInfos.Errors.Add(string.Format(Properties.Resources.PleaseLoadSecretSampleAdjustAndThenSaveAs, defaultFileName, fileName)); return(null); } await SetAsync(secret, errorsAndInfos); return(await ValueOrDefaultAsync(secret, errorsAndInfos)); } if (Values.ContainsKey(secret.Guid)) { valueOrDefault = await ValueOrDefaultAsync(secret, errorsAndInfos); return(valueOrDefault); } var xml = await ReadFromFileAsync(secret, false, encrypted, errorsAndInfos); if (string.IsNullOrEmpty(xml)) { return(null); } valueOrDefault = XmlDeserializer.Deserialize <TResult>(xml); if (!IsGenericType(valueOrDefault.GetType())) { foreach (var property in valueOrDefault.GetType().GetProperties().Where(p => p.GetValue(valueOrDefault) == null)) { SaveSample(secret, true); var defaultFileName = FileName(secret, true, encrypted); errorsAndInfos.Errors.Add(string.Format(Properties.Resources.AddedPropertyNotFoundInLoadedSecret, property.Name, fileName, defaultFileName)); } } Values[secret.Guid] = valueOrDefault; return(valueOrDefault); }
private static async Task <ShouldDefaultSecretsBeStored> ShouldDefaultSecretsBeStoredAsync(ISecretRepository sut, IErrorsAndInfos errorsAndInfos) { var secret = new SecretShouldDefaultSecretsBeStored(); var shouldDefaultSecretsBeStored = await sut.GetAsync(secret, errorsAndInfos); Assert.IsNotNull(shouldDefaultSecretsBeStored); return(shouldDefaultSecretsBeStored); }
public void DefaultSecretsAreStoredByDefault() { var secret = new SecretShouldDefaultSecretsBeStored(); var shouldDefaultSecretsBeStored = secret.DefaultValue; Assert.IsNotNull(shouldDefaultSecretsBeStored); Assert.IsTrue(shouldDefaultSecretsBeStored.AutomaticallySaveDefaultSecretIfAbsent); }