public void TryGetPrefixWithoutTypeNonGeneric()
        {
            KeyToParametersConverter.MappingCollection definitions = new KeyToParametersConverter.MappingCollection()
                                                                     .AddParametersToInt32Key()
                                                                     .AddKeyTypeToKeyClass("Product", typeof(Int32Key))
                                                                     .AddKeyTypeToKeyClass("Category", typeof(Int32Key));

            IKeyToParametersConverter converter = new KeyToParametersConverter(definitions);

            IKeyValueCollection parameters = new KeyValueCollection()
                                             .Add("SourceID", 5)
                                             .Add("TargetID", 6);

            Assert.AreEqual(true, converter.TryGetWithoutType(parameters, "Product", "Source", out IKey key));
            if (key is Int32Key sourceKey)
            {
                Assert.AreEqual(5, sourceKey.ID);
                Assert.AreEqual("Product", sourceKey.Type);
            }
            else
            {
                Assert.Fail("Not Int32Key");
            }

            Assert.AreEqual(true, converter.TryGetWithoutType(parameters, "Category", "Target", out key));
            if (key is Int32Key targetKey)
            {
                Assert.AreEqual(6, targetKey.ID);
                Assert.AreEqual("Category", targetKey.Type);
            }
            else
            {
                Assert.Fail("Not Int32Key");
            }
        }
        public void TryGetVariousKeyClassNonGeneric()
        {
            KeyToParametersConverter.MappingCollection definitions = new KeyToParametersConverter.MappingCollection()
                                                                     .AddParametersToInt32Key()
                                                                     .AddParametersToStringKey()
                                                                     .AddParametersToGuidKey()
                                                                     .AddKeyTypeToKeyClass("Product", typeof(Int32Key))
                                                                     .AddKeyTypeToKeyClass("Project", typeof(StringKey))
                                                                     .AddKeyTypeToKeyClass("Category", typeof(GuidKey));

            IKeyToParametersConverter converter = new KeyToParametersConverter(definitions);

            IKeyValueCollection parameters = new KeyValueCollection()
                                             .Add("ID", 5)
                                             .Add("Type", "Product");

            Assert.AreEqual(true, converter.TryGet(parameters, out IKey key));
            if (key is Int32Key int32Key)
            {
                Assert.AreEqual(5, int32Key.ID);
                Assert.AreEqual("Product", int32Key.Type);
            }
            else
            {
                Assert.Fail("Not Int32Key");
            }

            parameters = new KeyValueCollection()
                         .Add("Identifier", "abcdef")
                         .Add("Type", "Project");

            Assert.AreEqual(true, converter.TryGet(parameters, out key));
            if (key is StringKey stringKey)
            {
                Assert.AreEqual("abcdef", stringKey.Identifier);
                Assert.AreEqual("Project", stringKey.Type);
            }
            else
            {
                Assert.Fail("Not StringKey");
            }

            Guid guid = Guid.NewGuid();

            parameters = new KeyValueCollection()
                         .Add("Guid", guid)
                         .Add("Type", "Category");

            Assert.AreEqual(true, converter.TryGet(parameters, out key));
            if (key is GuidKey guidKey)
            {
                Assert.AreEqual(guid, guidKey.Guid);
                Assert.AreEqual("Category", guidKey.Type);
            }
            else
            {
                Assert.Fail("Not GuidKey");
            }
        }
        public void TryGetWithoutTypeNonGeneric()
        {
            KeyToParametersConverter.MappingCollection definitions = new KeyToParametersConverter.MappingCollection()
                                                                     .AddParametersToInt32Key()
                                                                     .AddKeyTypeToKeyClass("Product", typeof(Int32Key));

            IKeyToParametersConverter converter = new KeyToParametersConverter(definitions);

            IKeyValueCollection parameters = new KeyValueCollection()
                                             .Add("ID", 5);

            Assert.AreEqual(true, converter.TryGetWithoutType(parameters, "Product", out IKey key));
            if (key is Int32Key int32Key)
            {
                Assert.AreEqual(5, int32Key.ID);
                Assert.AreEqual("Product", int32Key.Type);
            }
            else
            {
                Assert.Fail("Not Int32Key");
            }
        }
        public void ThrowMissingKeyTypeToKeyClassMappingException()
        {
            IKeyToParametersConverter converter = new KeyToParametersConverter(new KeyToParametersConverter.MappingCollection());

            converter.TryGet(new KeyValueCollection().Add("Type", "Product"), out IKey key);
        }
        public void ThrowMissingParametersToKeyClassMappingException()
        {
            IKeyToParametersConverter converter = new KeyToParametersConverter(new KeyToParametersConverter.MappingCollection());

            converter.TryGet(new KeyValueCollection(), out Int32Key int32Key);
        }
 public void ThrowAddKeyTypeToKeyClassMapping()
 {
     IKeyToParametersConverter converter = new KeyToParametersConverter(new KeyToParametersConverter.MappingCollection().AddKeyTypeToKeyClass("Product", typeof(int)));
 }
        public void ThrowMissingKeyClassToParametersMappingException()
        {
            IKeyToParametersConverter converter = new KeyToParametersConverter(new KeyToParametersConverter.MappingCollection());

            converter.Add(new KeyValueCollection(), Int32Key.Create(5, "Product"));
        }