public void TryGetVariousKeyClass() { IKeyToParametersConverter converter = CreateConverter(); IKeyValueCollection parameters = new KeyValueCollection() .Add("ID", 5) .Add("Type", "Product"); Assert.AreEqual(true, converter.TryGet(parameters, out Int32Key int32Key)); Assert.AreEqual(5, int32Key.ID); Assert.AreEqual("Product", int32Key.Type); parameters = new KeyValueCollection() .Add("Identifier", "abcdef") .Add("Type", "Product"); Assert.AreEqual(true, converter.TryGet(parameters, out StringKey stringKey)); Assert.AreEqual("abcdef", stringKey.Identifier); Assert.AreEqual("Product", stringKey.Type); Guid guid = Guid.NewGuid(); parameters = new KeyValueCollection() .Add("Guid", guid) .Add("Type", "Product"); Assert.AreEqual(true, converter.TryGet(parameters, out GuidKey guidKey)); Assert.AreEqual(guid, guidKey.Guid); Assert.AreEqual("Product", guidKey.Type); }
public void TryGetPrefix() { IKeyToParametersConverter converter = CreateConverter(); IKeyValueCollection parameters = new KeyValueCollection() .Add("SourceID", 5) .Add("SourceType", "Product") .Add("TargetID", 6) .Add("TargetType", "Category"); Assert.AreEqual(true, converter.TryGet(parameters, "Source", out Int32Key sourceKey)); Assert.AreEqual(5, sourceKey.ID); Assert.AreEqual("Product", sourceKey.Type); Assert.AreEqual(true, converter.TryGet(parameters, "Target", out Int32Key targetKey)); Assert.AreEqual(6, targetKey.ID); Assert.AreEqual("Category", targetKey.Type); }