public void ConvertViaDictionaryParametersKeyAttributeSucceeds() { // Arrange var dto = new DictionaryParametersDtoImpl() { StringPropertyDictionaryParametersKey = ExpectedStringPropertyDictionaryParametersKey , LongPropertyDictionaryParametersKey = ExpectedLongPropertyDictionaryParametersKey , StringPropertyNoAttribute = ExpectedStringPropertyNoAttribute }; var sut = new ConvertibleBaseDtoConverter(); // Act var result = sut.Convert <DictionaryParametersKeyAttribute>(dto, false); // Assert Assert.IsTrue(result.ContainsKey(DICTIONARY_PARAMETERS_KEY_STRINGPROPERTY)); Assert.AreEqual(ExpectedStringPropertyDictionaryParametersKey, result[DICTIONARY_PARAMETERS_KEY_STRINGPROPERTY]); Assert.IsTrue(result.ContainsKey(DICTIONARY_PARAMETERS_KEY_LONGPROPERTY)); Assert.AreEqual(ExpectedLongPropertyDictionaryParametersKey, result[DICTIONARY_PARAMETERS_KEY_LONGPROPERTY]); Assert.IsFalse(result.ContainsKey("StringPropertyNoAttribute")); Assert.AreEqual(2, result.Keys.Count); Assert.IsTrue(result.IsValid()); }
public void ConvertFromDictionaryParametersKeyAttributeWithTypeMismatchThrowsArgumentException() { // Arrange var parameters = new DictionaryParameters() { { DICTIONARY_PARAMETERS_KEY_STRINGPROPERTY, ExpectedStringPropertyDictionaryParametersKey } , { DICTIONARY_PARAMETERS_KEY_LONGPROPERTY, "invalid-data-type-for-mapped-proeprty" } , { CONVERSION_KEY_STRINGPROPERTY, ExpectedStringPropertyConversionKey } , { CONVERSION_KEY_LONGPROPERTY, ExpectedLongPropertyConversionKey } , { "StringPropertyNoAttribute", ExpectedStringPropertyNoAttribute } , { "LongPropertyNoAttribute", ExpectedLongPropertyNoAttribute } , { "StringPropertyRequired", ExpectedStringPropertyRequired } , { "LongPropertyRequired", ExpectedLongPropertyRequired } }; var sut = new ConvertibleBaseDtoConverter(); // Act var result = sut.Convert <DictionaryParametersDtoImpl, DictionaryParametersKeyAttribute>(parameters, false); // Assert // N/A }
public void ConvertViaConversionKeyAttributeAndMergeWithDictionaryParametersKeyAttributeSucceeds() { // Arrange var dto = new DictionaryParametersDtoImpl() { StringPropertyDictionaryParametersKey = ExpectedStringPropertyDictionaryParametersKey , LongPropertyDictionaryParametersKey = ExpectedLongPropertyDictionaryParametersKey , StringPropertyNoAttribute = ExpectedStringPropertyNoAttribute , StringPropertyConversionKey = ExpectedStringPropertyConversionKey , LongPropertyConversionKey = ExpectedLongPropertyConversionKey }; var sut = new ConvertibleBaseDtoConverter(); // Act var resultFromConversionKeyAttribute = sut.Convert <ArbitraryConversionTestAttribute>(dto, false); var resultFromDictionaryParametersKeyAttribute = sut.Convert <DictionaryParametersKeyAttribute>(dto, false); // Assert Assert.IsTrue(resultFromConversionKeyAttribute.ContainsKey(CONVERSION_KEY_STRINGPROPERTY)); Assert.AreEqual(ExpectedStringPropertyConversionKey, resultFromConversionKeyAttribute[CONVERSION_KEY_STRINGPROPERTY]); Assert.IsTrue(resultFromConversionKeyAttribute.ContainsKey(CONVERSION_KEY_LONGPROPERTY)); Assert.AreEqual(ExpectedLongPropertyConversionKey, resultFromConversionKeyAttribute[CONVERSION_KEY_LONGPROPERTY]); Assert.IsTrue(resultFromConversionKeyAttribute.IsValid()); Assert.IsTrue(resultFromDictionaryParametersKeyAttribute.ContainsKey(DICTIONARY_PARAMETERS_KEY_STRINGPROPERTY)); Assert.AreEqual(ExpectedStringPropertyDictionaryParametersKey, resultFromDictionaryParametersKeyAttribute[DICTIONARY_PARAMETERS_KEY_STRINGPROPERTY]); Assert.IsTrue(resultFromDictionaryParametersKeyAttribute.ContainsKey(DICTIONARY_PARAMETERS_KEY_LONGPROPERTY)); Assert.AreEqual(ExpectedLongPropertyDictionaryParametersKey, resultFromDictionaryParametersKeyAttribute[DICTIONARY_PARAMETERS_KEY_LONGPROPERTY]); Assert.IsFalse(resultFromDictionaryParametersKeyAttribute.ContainsKey("StringPropertyNoAttribute")); Assert.AreEqual(2, resultFromDictionaryParametersKeyAttribute.Keys.Count); Assert.IsTrue(resultFromDictionaryParametersKeyAttribute.IsValid()); var isMergeable = resultFromConversionKeyAttribute.CanAdd(resultFromDictionaryParametersKeyAttribute); Assert.IsTrue(isMergeable); var keys1 = resultFromDictionaryParametersKeyAttribute.Keys.Count; var keys2 = resultFromConversionKeyAttribute.Keys.Count; var mergedDictionaryParameters = resultFromConversionKeyAttribute.Add(resultFromDictionaryParametersKeyAttribute); Assert.AreEqual(keys1 + keys2, mergedDictionaryParameters.Keys.Count); }
public void ConvertViaDictionaryParametersKeyAttributeWithDuplicateKeysThrowsArgumentException() { // Arrange var dto = new DictionaryParametersDtoImplWithDuplicateKey() { StringPropertyDictionaryParametersKey = ExpectedStringPropertyDictionaryParametersKey , LongPropertyDictionaryParametersKey = ExpectedLongPropertyDictionaryParametersKey , StringPropertyNoAttribute = ExpectedStringPropertyNoAttribute }; var sut = new ConvertibleBaseDtoConverter(); // Act var result = sut.Convert <DictionaryParametersKeyAttribute>(dto, true); // Assert // N/A }
public void ConvertFromDictionaryParametersKeyAttributeSucceeds() { // Arrange var parameters = new DictionaryParameters() { { DICTIONARY_PARAMETERS_KEY_STRINGPROPERTY, ExpectedStringPropertyDictionaryParametersKey } , { DICTIONARY_PARAMETERS_KEY_LONGPROPERTY, ExpectedLongPropertyDictionaryParametersKey } , { CONVERSION_KEY_STRINGPROPERTY, ExpectedStringPropertyConversionKey } , { CONVERSION_KEY_LONGPROPERTY, ExpectedLongPropertyConversionKey } , { "StringPropertyNoAttribute", ExpectedStringPropertyNoAttribute } , { "LongPropertyNoAttribute", ExpectedLongPropertyNoAttribute } , { "StringPropertyRequired", ExpectedStringPropertyRequired } , { "LongPropertyRequired", ExpectedLongPropertyRequired } }; var sut = new ConvertibleBaseDtoConverter(); // Act var result = sut.Convert <DictionaryParametersDtoImpl, DictionaryParametersKeyAttribute>(parameters, false); // Assert Assert.AreEqual(ExpectedStringPropertyDictionaryParametersKey, result.StringPropertyDictionaryParametersKey); Assert.AreEqual(ExpectedLongPropertyDictionaryParametersKey, result.LongPropertyDictionaryParametersKey); Assert.AreNotEqual(ExpectedStringPropertyConversionKey, result.StringPropertyConversionKey); Assert.AreNotEqual(ExpectedLongPropertyConversionKey, result.LongPropertyConversionKey); Assert.AreNotEqual(ExpectedStringPropertyNoAttribute, result.StringPropertyNoAttribute); Assert.AreNotEqual(ExpectedLongPropertyNoAttribute, result.LongPropertyNoAttribute); Assert.AreNotEqual(ExpectedStringPropertyRequired, result.StringPropertyRequired); Assert.AreNotEqual(ExpectedLongPropertyRequired, result.LongPropertyRequired); Assert.IsFalse(result.IsValid()); }