public void Add_AddNullElement_ThrowsArgumentNullException()
        {
            //arrange
            var arr = new DynamicSortedArray <string> {
                "a", "b", "c"
            };

            //act & assert
            Assert.Throws <ArgumentNullException>(() => arr.Add((string)null));
        }
Exemplo n.º 2
0
        static void Main()
        {
            var arr = new DynamicSortedArray <int>();

            arr.Added   += (sender, arguments) => Console.WriteLine(arguments.Message);
            arr.Removed += (sender, arguments) => Console.WriteLine(arguments.Message);

            arr.Add(3, 1, 5, 10, 5);
            OutputData(arr);

            arr.Add(0);
            OutputData(arr);

            arr.Add(6);
            OutputData(arr);

            arr.Add(12);
            OutputData(arr);

            Console.ReadKey();
        }
        public void Add_AddElementInCenter_ReturnNothing()
        {
            //arrange
            var arr = new DynamicSortedArray <int> {
                1, 2, 4
            };
            var addingValue      = 3;
            var expectedPosition = 2;

            //act
            arr.Add(addingValue);
            //assert
            Assert.Equal(addingValue, arr[expectedPosition]);
        }
        public void Add_CheckThatEventRaisedWhenAddingFirstElementToArray_ReturnNothing()
        {
            //arrange
            var arr = new DynamicSortedArray <int>();
            //act
            var receivedEvent = Assert.Raises <AddToArrayEventArgs <int> >(
                a => arr.Added += a,
                a => arr.Added -= a,
                () => { arr.Add(0); });

            //assert
            Assert.NotNull(receivedEvent);

            Assert.Equal(0, receivedEvent.Arguments.AddedItem);
            Assert.Equal("0 added first element", receivedEvent.Arguments.Message);
        }
        public void Add_CheckThatEventRaisedWhenAddingElementInCenterOfArray_ReturnNothing()
        {
            //arrange
            var arr = new DynamicSortedArray <int> {
                2, 2, 5, 8, 1, 6
            };
            //act
            var receivedEvent = Assert.Raises <AddToArrayEventArgs <int> >(
                a => arr.Added += a,
                a => arr.Added -= a,
                () => { arr.Add(4); });

            //assert
            Assert.NotNull(receivedEvent);

            Assert.Equal(4, receivedEvent.Arguments.AddedItem);
            Assert.Equal("4 added", receivedEvent.Arguments.Message);
        }