Example #1
0
        public void AddRange_Mutliple_EventFired()
        {
            var stubbedWindow = new StubbedWindow();

            var sut      = new ConControls.Controls.ControlCollection(stubbedWindow);
            var control1 = new StubbedConsoleControl(stubbedWindow);
            var control2 = new StubbedConsoleControl(stubbedWindow);
            var control3 = new StubbedConsoleControl(stubbedWindow);
            var control4 = new StubbedConsoleControl(stubbedWindow);

            int fired = 0;

            sut.ControlCollectionChanged += (sender, e) =>
            {
                fired++;
                if (fired == 1)
                {
                    e.AddedControls.Should().Equal(control1, control2);
                    return;
                }

                fired.Should().Be(2);
                e.AddedControls.Should().Equal(control3, control4);
            };
            sut.AddRange(control1, null !, control2);
            fired.Should().Be(1);
            sut.AddRange(control3, null !, control2, control4);
            fired.Should().Be(2);
        }
Example #2
0
        public void AddRange_WithWrongWindow_Exception()
        {
            var stubbedWindow   = new StubbedWindow();
            var differentWindow = new StubbedWindow();
            var sut             = new ConControls.Controls.ControlCollection(stubbedWindow);

            sut.AddRange(new StubbedConsoleControl(stubbedWindow), new StubbedConsoleControl(differentWindow), new StubbedConsoleControl(stubbedWindow));
        }
Example #3
0
        public void AddRange_Mutliple_Distinct()
        {
            var stubbedWindow = new StubbedWindow();

            var sut      = new ConControls.Controls.ControlCollection(stubbedWindow);
            var control1 = new StubbedConsoleControl(stubbedWindow);
            var control2 = new StubbedConsoleControl(stubbedWindow);
            var control3 = new StubbedConsoleControl(stubbedWindow);
            var control4 = new StubbedConsoleControl(stubbedWindow);

            sut.AddRange(control1, null !, control2);
            sut.Count.Should().Be(2);
            sut[0].Should().BeSameAs(control1);
            sut[1].Should().BeSameAs(control2);
            sut.AddRange(control3, null !, control2, control4);
            sut.Count.Should().Be(4);
            sut[0].Should().BeSameAs(control1);
            sut[1].Should().BeSameAs(control2);
            sut[2].Should().BeSameAs(control3);
            sut[3].Should().BeSameAs(control4);
        }
Example #4
0
        public void RemoveRange_RemovedAndEventFired()
        {
            using var stubbedWindow = new StubbedWindow();

            var sut      = new ConControls.Controls.ControlCollection(stubbedWindow);
            var control1 = new StubbedConsoleControl(stubbedWindow);
            var control2 = new StubbedConsoleControl(stubbedWindow);
            var control3 = new StubbedConsoleControl(stubbedWindow);
            var control4 = new StubbedConsoleControl(stubbedWindow);

            sut.AddRange(control1, control2, control3);

            int fired = 0;

            sut.ControlCollectionChanged += (sender, e) =>
            {
                fired.Should().Be(0);
                e.RemovedControls.Should().Equal(control1, control3);
                fired++;
            };
            sut.RemoveRange(control1, null !, control4, control3);
            sut.Should().Equal(control2);
            fired.Should().Be(1);
        }