コード例 #1
0
        public void Assert_That_Id_Is_Not_Empty_When_AddingNodes()
        {
            var parent = new WidgetMock();
            var child  = new WidgetMock();

            parent.Add(child);

            Assert.AreNotEqual(Guid.Empty, child.Id);
        }
コード例 #2
0
        public void Assert_Parent_Child_Relationship_When_AddingNodes()
        {
            var parent = new WidgetMock();
            var child  = new WidgetMock();

            parent.Add(child);

            Assert.IsTrue(parent.Contains(child));
            Assert.AreSame(parent, child.Parent);
            Assert.AreNotEqual(Guid.Empty, child.Id);
        }
コード例 #3
0
        public void CreateNotification_Should_ReturnNewNotification()
        {
            var item = new WidgetMock
            {
                State = State.Ok
            };

            var notification = item.CreateNotification();

            Assert.IsNotNull(notification);
            Assert.AreNotEqual(Notification.Empty, notification);
        }
コード例 #4
0
        public void Should_GenerateNewId_When_Cloning()
        {
            var item = new WidgetMock
            {
                Id   = Guid.NewGuid(),
                Name = Guid.NewGuid().ToString(),
            };

            var copy = (Item)item.Clone();

            Assert.AreNotEqual(item.Id, copy.Id);
        }
コード例 #5
0
        public void Assert_That_State_Is_Disabled_When_Disabled()
        {
            var widget = new WidgetMock
            {
                IsEnabled = true,
                State     = State.Ok
            };

            widget.IsEnabled = false;

            Assert.AreEqual(State.Disabled, widget.State);
        }
コード例 #6
0
        public void Assert_That_Child_Is_Removed()
        {
            var parent = new WidgetMock();
            var child  = new WidgetMock();

            parent.Add(child);

            Assert.IsTrue(parent.Contains(child));

            parent.Remove(child);

            Assert.IsFalse(parent.Contains(child));
        }
コード例 #7
0
        public void Assert_That_WidgetAddedEvent_Is_Fired_When_ChildAdded()
        {
            var eventFired = false;

            this.Subscribe <WidgetAdded>(e => eventFired = true);

            var parent = new WidgetMock();
            var child  = new WidgetMock();

            parent.Add(child);

            Assert.IsTrue(eventFired);
        }
コード例 #8
0
        public void Assert_That_Nodes_Are_Cleared()
        {
            var parent = new WidgetMock();
            var child  = new WidgetMock();

            parent.Add(child);

            Assert.IsTrue(parent.Items.Contains(child));

            parent.Clear();

            Assert.IsFalse(parent.Items.Any());
        }
コード例 #9
0
        public void Default_State_Is_None_When_Adding()
        {
            var folder    = new Folder();
            var subFolder = new Folder();
            var plugin    = new WidgetMock();

            folder.Add(subFolder);
            subFolder.Add(plugin);

            Assert.AreEqual(State.None, plugin.State);
            Assert.AreEqual(State.None, folder.State);
            Assert.AreEqual(State.None, subFolder.State);
        }
コード例 #10
0
        public void PreviousState()
        {
            var item = new WidgetMock
            {
                State = State.Ok
            };

            item.State = State.Error;

            Assert.AreEqual(State.Ok, item.PreviousState);

            item.State = State.Ok;

            Assert.AreEqual(State.Error, item.PreviousState);
        }
コード例 #11
0
        public void Assert_That_State_Bubbles_Up()
        {
            var grandParent = new Folder();
            var parent      = new Folder();
            var widget      = new WidgetMock();

            grandParent.Add(parent);
            parent.Add(widget);

            widget.State = State.Ok;

            Assert.AreEqual(State.Ok, widget.State);
            Assert.AreEqual(State.Ok, parent.State);
            Assert.AreEqual(State.Ok, grandParent.State);
        }
コード例 #12
0
        public void NotificationIsRequired_When_PreviousState_Changed()
        {
            var item = new WidgetMock
            {
                ShowNotifications = true,
                State             = State.Ok
            };

            item.State = item.State;

            Assert.IsFalse(item.IsNotificationRequired());

            item.State = State.Error;

            Assert.IsTrue(item.IsNotificationRequired());
        }
コード例 #13
0
        public void NotificationIsRequired_When_ShowNotifications_Is_True()
        {
            var item = new WidgetMock
            {
                ShowNotifications = false,
                State             = State.Ok
            };

            item.State = State.Error;

            Assert.IsFalse(item.IsNotificationRequired());

            item.ShowNotifications = true;

            Assert.IsTrue(item.IsNotificationRequired());
        }
コード例 #14
0
        public void NotificationIsRequired_When_PreviousState_IsNotNullOrNone()
        {
            var item = new WidgetMock
            {
                ShowNotifications = true,
            };

            Assert.IsFalse(item.IsNotificationRequired());

            item.State = State.Ok;

            Assert.IsFalse(item.IsNotificationRequired());

            item.State = State.Error;

            Assert.IsTrue(item.IsNotificationRequired());
        }
コード例 #15
0
        public void Should_CreateNewObjects_When_Cloning()
        {
            var item = new WidgetMock
            {
                Id   = Guid.NewGuid(),
                Name = Guid.NewGuid().ToString(),
            };

            var copy = (Item)item.Clone();

            Assert.AreNotSame(copy, item);
            Assert.AreNotSame(copy.Items, item.Items);

            Assert.AreEqual(item.Name, copy.Name);

            Assert.IsNull(copy.Parent);
        }
コード例 #16
0
        public void NotificationNotIsRequired_When_ShowErrorNotificationsFalse_And_State_Is_Error()
        {
            var widget = new WidgetMock
            {
                ShowNotifications      = true,
                ShowErrorNotifications = false,
                State = State.Ok
            };

            widget.State = State.Error;

            Assert.IsFalse(widget.IsNotificationRequired());

            widget.State = State.Ok;

            Assert.IsFalse(widget.IsNotificationRequired());
        }
コード例 #17
0
        public void FindItemByName_Using_GetNodeAndDescendants()
        {
            const string name = "SomeName";

            var root       = new WidgetMock();
            var child      = new WidgetMock();
            var grandchild = new WidgetMock {
                Name = name
            };

            root.Add(child);
            child.Add(grandchild);

            var actual = root.GetNodeAndDescendants().FirstOrDefault(item => item.Name == name);

            Assert.IsNotNull(actual);
            Assert.AreSame(grandchild, actual);
        }
コード例 #18
0
        public void Assert_That_State_Bubbles_Up_By_Priority()
        {
            var grandParent = new Folder();
            var parent      = new Folder();
            var widget1     = new WidgetMock();
            var widget2     = new WidgetMock();

            grandParent.Add(parent);
            parent.Add(widget1);
            parent.Add(widget2);

            Assert.AreEqual(State.None, parent.State);
            Assert.AreEqual(State.None, grandParent.State);

            widget1.State = State.Ok;
            widget2.State = State.None;

            Assert.AreEqual(State.Ok, widget1.State);
            Assert.AreEqual(State.None, widget2.State);
            Assert.AreEqual(State.Ok, parent.State);
            Assert.AreEqual(State.Ok, grandParent.State);
            Assert.AreEqual(0, grandParent.Count);

            widget2.State = State.Error;

            Assert.AreEqual(State.Ok, widget1.State);
            Assert.AreEqual(State.Error, widget2.State);
            Assert.AreEqual(State.Error, parent.State);
            Assert.AreEqual(State.Error, grandParent.State);
            Assert.AreEqual(1, grandParent.Count);

            widget1.State = State.Error;

            Assert.AreEqual(2, grandParent.Count);

            widget1.State = State.Ok;
            widget2.State = State.None;

            Assert.AreEqual(State.Ok, widget1.State);
            Assert.AreEqual(State.None, widget2.State);
            Assert.AreEqual(State.Ok, parent.State);
            Assert.AreEqual(State.Ok, grandParent.State);
            Assert.AreEqual(0, grandParent.Count);
        }
コード例 #19
0
        public void Should_IncludeChildren_When_Cloning()
        {
            var item = new WidgetMock
            {
                Id   = Guid.NewGuid(),
                Name = Guid.NewGuid().ToString(),
            };

            item.Items.Add(new WidgetMock());

            var copy = (Item)item.Clone();

            Assert.IsNotNull(copy.Items);

            Assert.AreNotSame(copy.Items, item.Items);

            Assert.IsTrue(copy.Items.Count == 1);

            Assert.AreNotSame(copy.Items.First(), item.Items.First());
        }
コード例 #20
0
        public void Assert_That_StateChangedEventPublished()
        {
            var numberOfEventOccurrences = 0;

            var triggers = new List <Trigger>
            {
                new NotificationTrigger()
            };

            var folder = new Folder
            {
                Triggers = triggers
            };

            var widget = new WidgetMock
            {
                Triggers = triggers
            };

            folder.Add(widget);

            this.Subscribe <WidgetStateChanged>(IncreaseCounter);

            widget.State = State.Ok;    //affects widget and parent folders state.
            widget.State = State.Ok;    //same staet ignored
            widget.State = State.Error; //affects widget and parent folders state.

            this.Unsubscribe <WidgetStateChanged>(IncreaseCounter);

            Assert.AreEqual(4, numberOfEventOccurrences);

            void IncreaseCounter(WidgetStateChanged e)
            {
                numberOfEventOccurrences++;
            }
        }
コード例 #21
0
        public void Assert_That_DefaultStateIsNone()
        {
            var widget = new WidgetMock();

            AssertStateIsNone(widget);
        }