public void ReturnAValueFromALookupThatIsDifferentToTheOriginalValue() { var originalValue = "Tester"; var newValue = systemUnderTest.GenerateFromLookup(originalValue, GenerateValidArgs()); newValue.Should().NotBe(originalValue); }
private double Format(double originalValue, FieldToBeObfuscated field) { if (field.ObfuscationFormatArgs.Count > 1) { throw new ValidationException($"Only a single ObfuscationFormatOption of type {ObfuscationFormatType.Lookup} can be applied to a field of type double."); } if (!field.ObfuscationFormatArgs[0].FormatType.Equals(ObfuscationFormatType.Lookup)) { throw new NotImplementedException($"The ObfuscationFormatType({field.ObfuscationFormatArgs[0].FormatType}) is not implemented for fields of type double."); } string lookupValue = optionProcessor.GenerateFromLookup(originalValue.ToString("G", CultureInfo.InvariantCulture), field.ObfuscationFormatArgs[0]); if (double.TryParse(lookupValue, out double replacementValue)) { return(replacementValue); } throw new InvalidCastException($"The value ({lookupValue}) read from the lookup source ({field.ObfuscationFormatArgs[0].Arguments["filename"]}) field ({field.ObfuscationFormatArgs[0].Arguments["columnname"]}) could not be converted to a double."); }
private string Format(string originalValue, FieldToBeObfuscated field, Dictionary <string, object> metadataParameters) { List <string> obfuscatedStrings = new List <string>(); foreach (var arg in field.ObfuscationFormatArgs) { switch (arg.FormatType) { case ObfuscationFormatType.RandomString: obfuscatedStrings.Add(optionProcessor.GenerateRandomString(originalValue, arg)); break; case ObfuscationFormatType.RandomNumber: obfuscatedStrings.Add(optionProcessor.GenerateRandomNumber(originalValue, arg).ToString(CultureInfo.InvariantCulture)); break; case ObfuscationFormatType.Lookup: obfuscatedStrings.Add(optionProcessor.GenerateFromLookup(originalValue, arg)); break; } } string replacementString = string.Format(CultureInfo.InvariantCulture, field.ObfuscationFormat, obfuscatedStrings.ToArray()); if (metadataParameters != null && metadataParameters.ContainsKey("maxlength")) { var maxLength = (int)metadataParameters["maxlength"]; if (replacementString.Length > maxLength) { replacementString = replacementString.Substring(0, maxLength); } } return(replacementString); }