public void ContextualCommandViewModel_Icon()
        {
            // Arrange
            var context     = new object();
            var command     = new RelayCommand(() => { });
            var testSubject = new ContextualCommandViewModel(context, command);

            using (var tracker = new PropertyChangedTracker(testSubject))
            {
                // Case 1: null
                // Act + Assert
                testSubject.Icon.Should().BeNull("Expected icon to return null when not set");

                // Case 2: static
                var staticIcon = new IconViewModel(null);
                testSubject.Icon = staticIcon;
                // Act + Assert
                testSubject.Icon.Should().Be(staticIcon, "Unexpected static icon");
                tracker.AssertPropertyChangedRaised(nameof(testSubject.Icon), 1);

                // Case 3: dynamic
                var dynamicIcon = new IconViewModel(null);
                var funcInvoked = false;
                Func <object, IconViewModel> func = x =>
                {
                    funcInvoked = true;
                    return(dynamicIcon);
                };
                testSubject.SetDynamicIcon(func);
                // Act + Assert
                testSubject.Icon.Should().Be(dynamicIcon, "Unexpected dynamic icon");
                funcInvoked.Should().BeTrue("Dynamic icon function  was not invoked");
                tracker.AssertPropertyChangedRaised(nameof(testSubject.Icon), 2);
            }

            // Case 4: dynamic - null exception
            Exceptions.Expect <ArgumentNullException>(() => testSubject.SetDynamicIcon(null));
        }
        private void SetServerProjectsVMCommands(ServerViewModel serverVM)
        {
            foreach (ProjectViewModel projectVM in serverVM.Projects)
            {
                projectVM.Commands.Clear();

                if (this.Host.ActiveSection == null)
                {
                    // Don't add command (which will be disabled).
                    continue;
                }

                var bindContextCommand = new ContextualCommandViewModel(projectVM,
                                                                        this.Host.ActiveSection.BindCommand,
                                                                        new BindCommandArgs(projectVM.Key, projectVM.ProjectName, serverVM.ConnectionInformation));
                bindContextCommand.SetDynamicDisplayText(x =>
                {
                    var ctx = x as ProjectViewModel;
                    Debug.Assert(ctx != null, "Unexpected fixed context for bind context command");
                    return(ctx?.IsBound ?? false ? Strings.SyncButtonText : Strings.BindButtonText);
                });
                bindContextCommand.SetDynamicIcon(x =>
                {
                    var ctx = x as ProjectViewModel;
                    Debug.Assert(ctx != null, "Unexpected fixed context for bind context command");
                    return(new IconViewModel(ctx?.IsBound ?? false ? KnownMonikers.Sync : KnownMonikers.Link));
                });

                var openProjectDashboardCommand = new ContextualCommandViewModel(projectVM, this.Host.ActiveSection.BrowseToProjectDashboardCommand)
                {
                    DisplayText = Strings.ViewInSonarQubeMenuItemDisplayText,
                    Tooltip     = Strings.ViewInSonarQubeMenuItemTooltip,
                    Icon        = new IconViewModel(KnownMonikers.OpenWebSite)
                };

                projectVM.Commands.Add(bindContextCommand);
                projectVM.Commands.Add(openProjectDashboardCommand);
            }
        }