public void RegisterAndFindSpecializedAdaptee1()
        {
            // arrange
            var registry = new TypeAdapterRegistry <IApple>();

            // act
            registry.Register <DisguisePearAsApple>();
            registry.Register <DisguiseSpecialPearAsApple>();
            var pearAdapter        = registry.FindAdapterTypesFor <Pear>().Single();
            var specialPearAdapter = registry.FindAdapterTypesFor <SpecialPear>().First();

            // assert
            Assert.AreEqual(typeof(DisguisePearAsApple), pearAdapter);
            Assert.AreEqual(typeof(DisguiseSpecialPearAsApple), specialPearAdapter);
        }
        public void FindReturnsEveryTypeOnlyOnce2()
        {
            // arrange
            var registry = new TypeAdapterRegistry <IApple>();

            // act
            registry.Register <DisguiseSpecialPearAndPearAsApple>();
            var pearAdapters = registry.FindAdapterTypesFor <SpecialPear>();

            // assert
            Assert.AreEqual(typeof(DisguiseSpecialPearAndPearAsApple), pearAdapters.Single());
        }
        public void SimpleRegisterAndFind()
        {
            // arrange
            var registry = new TypeAdapterRegistry <IApple>();

            // act
            registry.Register <DisguisePearAsApple>();
            var adapter = registry.FindAdapterTypesFor <Pear>().Single();

            // assert
            Assert.AreEqual(typeof(DisguisePearAsApple), adapter);
        }
        public void RegisterAndFindMultiPurposeAdapter()
        {
            // arrange
            var registry = new TypeAdapterRegistry <IApple>();

            // act
            registry.Register <DisguisePearOrOrangeAsApple>();
            var pearAdapter   = registry.FindAdapterTypesFor <Pear>().Single();
            var orangeAdapter = registry.FindAdapterTypesFor <Orange>().Single();

            // assert
            Assert.AreEqual(typeof(DisguisePearOrOrangeAsApple), pearAdapter);
            Assert.AreEqual(typeof(DisguisePearOrOrangeAsApple), orangeAdapter);
        }
        public void FindReturnsInReverseRegistrationOrder2()
        {
            // arrange
            var registry = new TypeAdapterRegistry <IApple>();

            // act
            registry.Register <DisguiseSpecialPearAndPearAsApple>();
            registry.Register <DisguiseSpecialPearAsApple>();
            registry.Register <DisguisePearAsApple>();

            var pearAdapters        = registry.FindAdapterTypesFor <Pear>().ToArray();
            var specialPearAdapters = registry.FindAdapterTypesFor <SpecialPear>().ToArray();

            // assert
            Assert.AreEqual(2, pearAdapters.Length);
            Assert.AreEqual(typeof(DisguisePearAsApple), pearAdapters[0]);
            Assert.AreEqual(typeof(DisguiseSpecialPearAndPearAsApple), pearAdapters[1]);

            Assert.AreEqual(3, specialPearAdapters.Length);
            Assert.AreEqual(typeof(DisguiseSpecialPearAsApple), specialPearAdapters[0]);
            Assert.AreEqual(typeof(DisguiseSpecialPearAndPearAsApple), specialPearAdapters[1]);
            Assert.AreEqual(typeof(DisguisePearAsApple), specialPearAdapters[2]);
        }
        public void ExpectArgumentExceptionIfAdapterWrongType()
        {
            // arrange
            var registry = new TypeAdapterRegistry <IPear>();

            try
            {
                // act
                registry.Register(typeof(DisguisePearAsApple));

                // assert
                Assert.Fail("Expecting ArgumentException");
            }
            catch (ArgumentException)
            {
                // success :-)
            }
        }
        public void ExpectArgumentExceptionIfAdapteeCouldNotBeResolved()
        {
            // arrange
            var registry = new TypeAdapterRegistry <IApple>();

            try
            {
                // act
                registry.Register <DisguisePearAsBadApple>();

                // assert
                Assert.Fail("Expecting ArgumentException");
            }
            catch (ArgumentException)
            {
                // success :-)
            }
        }