Esempio n. 1
0
        public void Add_should_behave_as_same_as_original_if_the_instance_behavior_is_set_that()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var listProxy = new PProxyList <int>();
                listProxy.
                ExcludeGeneric().
                IncludeAddT().
                    DefaultBehavior = IndirectionBehaviors.Fallthrough;
                var list_sut        = (List <int>)listProxy;
                // You have to call the constructor of the type that is original for a proxy.
                // This isn't easy usage, but I believe that proxy is usually set indirection settings explicitly.
                typeof(List <int>).GetConstructor(Type.EmptyTypes).Invoke(list_sut, new object[0]);

                var list = new List <int>();

                // Act
                list_sut.Add(42);
                list.Add(10);

                // Assert
                CollectionAssert.AreEqual(new[] { 42 }, list_sut);
                CollectionAssert.AreEqual(new[] { 10 }, list);
            }
        }
Esempio n. 2
0
        public void Add_should_throw_NotImplementedException_if_the_instance_behavior_is_set_that()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var listProxy = new PProxyList <int>();
                listProxy.
                ExcludeGeneric().
                IncludeAddT().
                    DefaultBehavior = IndirectionBehaviors.NotImplemented;
                var list_sut        = (List <int>)listProxy;

                var list = new List <int>();

                // Act, Assert
                ExceptionAssert.Throws <NotImplementedException>(() => list_sut.Add(42));
                ExceptionAssert.DoesNotThrow(() => list.Add(10));
            }
        }
Esempio n. 3
0
        public void Add_should_be_callable_indirectly_against_only_specified_instance()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var actual            = default(int);
                var listProxy         = new PProxyList <int>();
                listProxy.AddT().Body = (@this, item) => actual = item;
                var list_sut          = (List <int>)listProxy;

                var list = new List <int>();

                // Act
                list_sut.Add(42);
                list.Add(10);

                // Assert
                Assert.AreEqual(42, actual);
            }
        }
Esempio n. 4
0
        public void Add_should_be_callable_indirectly_against_only_specified_instance()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var actual = default(int);
                var listProxy = new PProxyList<int>();
                listProxy.AddT().Body = (@this, item) => actual = item;
                var list_sut = (List<int>)listProxy;

                var list = new List<int>();

                // Act
                list_sut.Add(42);
                list.Add(10);

                // Assert
                Assert.AreEqual(42, actual);
            }
        }
Esempio n. 5
0
        public void Add_should_do_nothing_if_the_instance_behavior_is_set_that()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var listProxy = new PProxyList <int>();
                listProxy.
                ExcludeGeneric().
                IncludeAddT().
                    DefaultBehavior = IndirectionBehaviors.DefaultValue;
                var list_sut        = (List <int>)listProxy;

                var list = new List <int>();

                // Act
                list_sut.Add(42);
                list.Add(10);

                // Assert
                CollectionAssert.IsEmpty(list_sut);
                CollectionAssert.AreEqual(new[] { 10 }, list);
            }
        }
Esempio n. 6
0
        public void Add_should_throw_NotImplementedException_if_the_instance_behavior_is_set_that()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var listProxy = new PProxyList<int>();
                listProxy.
                    ExcludeGeneric().
                    IncludeAddT().
                    DefaultBehavior = IndirectionBehaviors.NotImplemented;
                var list_sut = (List<int>)listProxy;

                var list = new List<int>();

                // Act, Assert
                Assert.Throws<NotImplementedException>(() => list_sut.Add(42));
                Assert.DoesNotThrow(() => list.Add(10));
            }
        }
Esempio n. 7
0
        public void Add_should_behave_as_same_as_original_if_the_instance_behavior_is_set_that()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var listProxy = new PProxyList<int>();
                listProxy.
                    ExcludeGeneric().
                    IncludeAddT().
                    DefaultBehavior = IndirectionBehaviors.Fallthrough;
                var list_sut = (List<int>)listProxy;
                // You have to call the constructor of the type that is original for a proxy.
                // This isn't easy usage, but I believe that proxy is usually set indirection settings explicitly.
                typeof(List<int>).GetConstructor(Type.EmptyTypes).Invoke(list_sut, new object[0]);

                var list = new List<int>();

                // Act
                list_sut.Add(42);
                list.Add(10);

                // Assert
                CollectionAssert.AreEqual(new[] { 42 }, list_sut);
                CollectionAssert.AreEqual(new[] { 10 }, list);
            }
        }
Esempio n. 8
0
        public void Add_should_do_nothing_if_the_instance_behavior_is_set_that()
        {
            using (new IndirectionsContext())
            {
                // Arrange
                var listProxy = new PProxyList<int>();
                listProxy.
                    ExcludeGeneric().
                    IncludeAddT().
                    DefaultBehavior = IndirectionBehaviors.DefaultValue;
                var list_sut = (List<int>)listProxy;

                var list = new List<int>();

                // Act
                list_sut.Add(42);
                list.Add(10);

                // Assert
                CollectionAssert.IsEmpty(list_sut);
                CollectionAssert.AreEqual(new[] { 10 }, list);
            }
        }