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);
        }
        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));
        }
        public void AddRange_EmptyRange_NotFired()
        {
            var stubbedWindow = new StubbedWindow();

            var  sut   = new ConControls.Controls.ControlCollection(stubbedWindow);
            bool fired = false;

            sut.ControlCollectionChanged += (sender, e) =>
            {
                fired = true;
                Assert.Fail();
            };
            sut.AddRange((ConControls.Controls.ConsoleControl)null !);
            fired.Should().BeFalse();
        }
        public void RemoveRange_EmptyRange_NotFired()
        {
            using var stubbedWindow = new StubbedWindow();

            var  sut   = new ConControls.Controls.ControlCollection(stubbedWindow);
            bool fired = false;

            sut.ControlCollectionChanged += (sender, e) =>
            {
                fired = true;
                Assert.Fail();
            };
            sut.RemoveRange(null !, new StubbedConsoleControl(stubbedWindow));
            fired.Should().BeFalse();
        }
Exemple #5
0
        public void Add_ControlsTwice_AddedOnceAndEventsRaised()
        {
            using var stubbedWindow = new StubbedWindow();

            var sut = new ConControls.Controls.ControlCollection(stubbedWindow);

            ConControls.Controls.ConsoleControl?control1 = new StubbedConsoleControl(stubbedWindow);
            ConControls.Controls.ConsoleControl?control2 = new StubbedConsoleControl(stubbedWindow);
            int added1 = 0, added2 = 0;

            sut.ControlCollectionChanged += (sender, e) =>
            {
                sender.Should().BeSameAs(sut);
                if (e.AddedControls.Contains(control1))
                {
                    added1++;
                }
                else if (e.AddedControls.Contains(control2))
                {
                    added2++;
                }
                else
                {
                    Assert.Fail();
                }
            };

            sut.Add(control1);
            added1.Should().Be(1);
            added2.Should().Be(0);
            sut.Count.Should().Be(1);
            sut[0].Should().BeSameAs(control1);
            sut.Add(control2);
            added1.Should().Be(1);
            added2.Should().Be(1);
            sut.Count.Should().Be(2);
            sut[0].Should().BeSameAs(control1);
            sut[1].Should().BeSameAs(control2);
            sut.Add(control1);
            added1.Should().Be(1);
            added2.Should().Be(1);
            sut.Count.Should().Be(2);
            sut[0].Should().BeSameAs(control1);
            sut[1].Should().BeSameAs(control2);
        }
        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);
        }
        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);
        }