Beispiel #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);
            }
        }
Beispiel #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));
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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));
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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);
            }
        }