public void RuleSetConflictsController_FixConflictsCommandStatus()
        {
            // Arrange
            var testSubject = new RuleSetConflictsController(this.host, this.conflictsManager);

            // Case 1: Nulls
            testSubject.FixConflictsCommand.CanExecute(null).Should().BeFalse();

            // Case 2: Empty collections
            testSubject.FixConflictsCommand.CanExecute(new ProjectRuleSetConflict[0]).Should().BeFalse();

            // Valid input
            ProjectRuleSetConflict[] conflicts = new[] { ConfigurableConflictsManager.CreateConflict() };

            // Case 3: Valid input, busy, has bound project
            this.host.VisualStateManager.IsBusy = true;
            this.host.VisualStateManager.SetBoundProject(new Uri("http://foo"), null, "project123");
            testSubject.FixConflictsCommand.CanExecute(conflicts).Should().BeFalse();

            // Case 4: Valid input, not busy, not bound project
            this.host.VisualStateManager.IsBusy = false;
            this.host.VisualStateManager.ClearBoundProject();
            testSubject.FixConflictsCommand.CanExecute(conflicts).Should().BeFalse();

            // Case 5: Valid input, not busy, has bound project
            this.host.VisualStateManager.IsBusy = false;
            this.host.VisualStateManager.SetBoundProject(new Uri("http://foo"), null, "project123");
            testSubject.FixConflictsCommand.CanExecute(conflicts).Should().BeTrue();
        }
        public void RuleSetConflictsController_FixConflictsCommandStatus()
        {
            // Setup
            var testSubject = new RuleSetConflictsController(this.host);

            // Case 1: Nulls
            Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(null));

            // Case 2: Empty collections
            Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(new ProjectRuleSetConflict[0]));

            // Valid input
            ProjectRuleSetConflict[] conflicts = new[] { ConfigurableConflictsManager.CreateConflict() };

            // Case 3: Valid input, busy, has bound project
            this.host.VisualStateManager.IsBusy = true;
            this.host.VisualStateManager.SetBoundProject(new Integration.Service.ProjectInformation());
            Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(conflicts));

            // Case 4: Valid input, not busy, not bound project
            this.host.VisualStateManager.IsBusy = false;
            this.host.VisualStateManager.ClearBoundProject();
            Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(conflicts));

            // Case 5: Valid input, not busy, has bound project
            this.host.VisualStateManager.IsBusy = false;
            this.host.VisualStateManager.SetBoundProject(new Integration.Service.ProjectInformation());
            Assert.IsTrue(testSubject.FixConflictsCommand.CanExecute(conflicts));
        }
        public void RuleSetConflictsController_Ctor()
        {
            Exceptions.Expect<ArgumentNullException>(() => new RuleSetConflictsController(null));

            var testSubject = new RuleSetConflictsController(this.host);
            Assert.IsNotNull(testSubject.FixConflictsCommand, "Command instance is expected");
        }
        public void RuleSetConflictsController_Ctor()
        {
            Exceptions.Expect <ArgumentNullException>(() => new RuleSetConflictsController(null));

            var testSubject = new RuleSetConflictsController(this.host);

            Assert.IsNotNull(testSubject.FixConflictsCommand, "Command instance is expected");
        }
        public void RuleSetConflictsController_Ctor()
        {
            Exceptions.Expect <ArgumentNullException>(() => new RuleSetConflictsController(null, this.conflictsManager));
            Exceptions.Expect <ArgumentNullException>(() => new RuleSetConflictsController(this.host, null));

            var testSubject = new RuleSetConflictsController(this.host, this.conflictsManager);

            testSubject.FixConflictsCommand.Should().NotBeNull("Command instance is expected");
        }
        public void RuleSetConflictsController_FixConflictsCommandExecution()
        {
            // Arrange
            var testSubject = new RuleSetConflictsController(this.host, this.conflictsManager);

            this.ConfigureServiceProviderForFixConflictsCommandExecution();
            this.host.VisualStateManager.IsBusy = false;
            this.host.VisualStateManager.SetBoundProject(new Uri("http://foo"), null, "project123");
            var section = ConfigurableSectionController.CreateDefault();

            this.host.SetActiveSection(section);
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;

            ProjectRuleSetConflict[] conflicts = new[] { ConfigurableConflictsManager.CreateConflict() };

            RuleSet fixedRuleSet = TestRuleSetHelper.CreateTestRuleSet(3);

            fixedRuleSet.FilePath = "MyFixedRules.ruleset";

            RuleSetInspectorTestDataProvider inspectorData = new RuleSetInspectorTestDataProvider();
            var weakenedRulesMap = new Dictionary <RuleReference, RuleAction>();

            inspectorData.FindConflictsResult = new RuleConflictInfo(new RuleReference[0], weakenedRulesMap);
            inspectorData.FixConflictsResult  = new FixedRuleSetInfo(fixedRuleSet, new[] { "reset.ruleset" }, new[] { "deletedRuleId1" });
            this.ruleSetInspector.FindConflictingRulesAction = inspectorData.FindConflictingRulesAction;
            this.ruleSetInspector.FixConflictingRulesAction  = inspectorData.FixConflictingRulesAction;

            ICommand fixMeCommand = testSubject.CreateFixConflictsCommand(conflicts);

            section.UserNotifications.ShowNotificationWarning("fix me", NotificationIds.RuleSetConflictsId, fixMeCommand);

            // Act
            fixMeCommand.Execute(null);

            // Assert
            this.sccFS.files.Should().ContainKey(fixedRuleSet.FilePath);
            this.rsSerializer.AssertRuleSetsAreSame(fixedRuleSet.FilePath, fixedRuleSet);
            this.outputWindowPane.AssertOutputStrings(1);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0,
                                                                             words: new[] { fixedRuleSet.FilePath, "deletedRuleId1", "reset.ruleset" },
                                                                             splitter: new[] { '\n', '\r', '\t', '\'', ':' });
            notifications.AssertNoNotification(NotificationIds.RuleSetConflictsId);
        }
        public void RuleSetConflictsController_CheckForConflicts()
        {
            // Setup
            var conflictsMananger = new ConfigurableConflictsManager();

            this.serviceProvider.RegisterService(typeof(IConflictsManager), conflictsMananger);
            var  testSubject = new RuleSetConflictsController(this.host);
            bool result;

            // Case 1: No conflicts
            // Act
            result = testSubject.CheckForConflicts();

            // Verify
            Assert.IsFalse(result, "Not expecting any conflicts");
            this.outputWindowPane.AssertOutputStrings(0);

            // Case 2: Has conflicts, no active section
            ProjectRuleSetConflict conflict = conflictsMananger.AddConflict();

            // Act
            result = testSubject.CheckForConflicts();

            // Verify
            Assert.IsTrue(result, "Conflicts expected");
            this.outputWindowPane.AssertOutputStrings(1);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0, new[] { conflict.Conflict.MissingRules.Single().FullId });

            // Case 3: Has conflicts, has active section
            var section = ConfigurableSectionController.CreateDefault();

            this.host.SetActiveSection(section);

            // Act
            result = testSubject.CheckForConflicts();

            // Verify
            Assert.IsTrue(result, "Conflicts expected");
            ((ConfigurableUserNotification)section.UserNotifications).AssertNotification(NotificationIds.RuleSetConflictsId);
            this.outputWindowPane.AssertOutputStrings(2);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(1, new[] { conflict.Conflict.MissingRules.Single().FullId });
        }
        public void RuleSetConflictsController_Clear()
        {
            // Setup
            var testSubject = new RuleSetConflictsController(this.host);

            // Case 1: No active section (should not crash)
            testSubject.Clear();

            // Case 2: Has active section
            var section = ConfigurableSectionController.CreateDefault();
            this.host.SetActiveSection(section);
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;
            section.UserNotifications.ShowNotificationWarning("message", NotificationIds.RuleSetConflictsId, null);

            // Act
            testSubject.Clear();

            // Verify
            notifications.AssertNoNotification(NotificationIds.RuleSetConflictsId);
        }
        public void RuleSetConflictsController_Clear()
        {
            // Arrange
            var testSubject = new RuleSetConflictsController(this.host, this.conflictsManager);

            // Case 1: No active section (should not crash)
            testSubject.Clear();

            // Case 2: Has active section
            var section = ConfigurableSectionController.CreateDefault();

            this.host.SetActiveSection(section);
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;

            section.UserNotifications.ShowNotificationWarning("message", NotificationIds.RuleSetConflictsId, null);

            // Act
            testSubject.Clear();

            // Assert
            notifications.AssertNoNotification(NotificationIds.RuleSetConflictsId);
        }
        public void RuleSetConflictsController_CheckForConflicts()
        {
            // Arrange
            var  testSubject = new RuleSetConflictsController(this.host, this.conflictsManager);
            bool result;

            // Case 1: No conflicts
            // Act
            result = testSubject.CheckForConflicts();

            // Assert
            result.Should().BeFalse("Not expecting any conflicts");
            this.outputWindowPane.AssertOutputStrings(0);

            // Case 2: Has conflicts, no active section
            ProjectRuleSetConflict conflict = conflictsManager.AddConflict();

            // Act
            result = testSubject.CheckForConflicts();

            // Assert
            result.Should().BeTrue("Conflicts expected");
            this.outputWindowPane.AssertOutputStrings(1);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0, new[] { conflict.Conflict.MissingRules.Single().FullId });

            // Case 3: Has conflicts, has active section
            var section = ConfigurableSectionController.CreateDefault();

            this.host.SetActiveSection(section);

            // Act
            result = testSubject.CheckForConflicts();

            // Assert
            result.Should().BeTrue("Conflicts expected");
            ((ConfigurableUserNotification)section.UserNotifications).AssertNotification(NotificationIds.RuleSetConflictsId);
            this.outputWindowPane.AssertOutputStrings(2);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(1, new[] { conflict.Conflict.MissingRules.Single().FullId });
        }
        public void RuleSetConflictsController_CheckForConflicts()
        {
            // Setup
            var conflictsMananger = new ConfigurableConflictsManager();
            this.serviceProvider.RegisterService(typeof(IConflictsManager), conflictsMananger);
            var testSubject = new RuleSetConflictsController(this.host);
            bool result;

            // Case 1: No conflicts
            // Act
            result = testSubject.CheckForConflicts();

            // Verify
            Assert.IsFalse(result, "Not expecting any conflicts");
            this.outputWindowPane.AssertOutputStrings(0);

            // Case 2: Has conflicts, no active section
            ProjectRuleSetConflict conflict = conflictsMananger.AddConflict();

            // Act
            result = testSubject.CheckForConflicts();

            // Verify
            Assert.IsTrue(result, "Conflicts expected");
            this.outputWindowPane.AssertOutputStrings(1);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0, new[] { conflict.Conflict.MissingRules.Single().FullId });

            // Case 3: Has conflicts, has active section
            var section = ConfigurableSectionController.CreateDefault();
            this.host.SetActiveSection(section);

            // Act
            result = testSubject.CheckForConflicts();

            // Verify
            Assert.IsTrue(result, "Conflicts expected");
            ((ConfigurableUserNotification)section.UserNotifications).AssertNotification(NotificationIds.RuleSetConflictsId);
            this.outputWindowPane.AssertOutputStrings(2);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(1, new[] { conflict.Conflict.MissingRules.Single().FullId });
        }
        public void RuleSetConflictsController_FixConflictsCommandExecution()
        {
            // Setup
            var testSubject = new RuleSetConflictsController(this.host);
            this.ConfigureServiceProviderForFixConflictsCommandExecution();
            this.host.VisualStateManager.IsBusy = false;
            this.host.VisualStateManager.SetBoundProject(new Integration.Service.ProjectInformation());
            var section = ConfigurableSectionController.CreateDefault();
            this.host.SetActiveSection(section);
            ConfigurableUserNotification notifications = (ConfigurableUserNotification)section.UserNotifications;

            ProjectRuleSetConflict[] conflicts = new[] { ConfigurableConflictsManager.CreateConflict() };

            RuleSet fixedRuleSet = TestRuleSetHelper.CreateTestRuleSet(3);
            fixedRuleSet.FilePath = "MyFixedRules.ruleset";

            RuleSetInspectorTestDataProvider inspectorData = new RuleSetInspectorTestDataProvider();
            var weakenedRulesMap = new Dictionary<RuleReference, RuleAction>();
            inspectorData.FindConflictsResult = new RuleConflictInfo(new RuleReference[0], weakenedRulesMap);
            inspectorData.FixConflictsResult = new FixedRuleSetInfo(fixedRuleSet, new[] { "reset.ruleset" }, new[] { "deletedRuleId1" });
            this.ruleSetInspector.FindConflictingRulesAction = inspectorData.FindConflictingRulesAction;
            this.ruleSetInspector.FixConflictingRulesAction = inspectorData.FixConflictingRulesAction;

            ICommand fixMeCommand = testSubject.CreateFixConflictsCommand(conflicts);
            section.UserNotifications.ShowNotificationWarning("fix me", NotificationIds.RuleSetConflictsId, fixMeCommand);

            // Act
            fixMeCommand.Execute(null);

            // Verify
            this.sccFS.AssertFileExists(fixedRuleSet.FilePath);
            this.rsSerializer.AssertRuleSetsAreSame(fixedRuleSet.FilePath, fixedRuleSet);
            this.outputWindowPane.AssertOutputStrings(1);
            this.outputWindowPane.AssertMessageContainsAllWordsCaseSensitive(0,
                words: new[] { fixedRuleSet.FilePath, "deletedRuleId1", "reset.ruleset" },
                splitter:new[] {'\n', '\r', '\t', '\'', ':' });
            notifications.AssertNoNotification(NotificationIds.RuleSetConflictsId);
        }
        public void RuleSetConflictsController_FixConflictsCommandStatus()
        {
            // Setup
            var testSubject = new RuleSetConflictsController(this.host);

            // Case 1: Nulls
            Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(null));

            // Case 2: Empty collections
            Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(new ProjectRuleSetConflict[0]));

            // Valid input
            ProjectRuleSetConflict[] conflicts = new[] { ConfigurableConflictsManager.CreateConflict() };

            // Case 3: Valid input, busy, has bound project
            this.host.VisualStateManager.IsBusy = true;
            this.host.VisualStateManager.SetBoundProject(new Integration.Service.ProjectInformation());
            Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(conflicts));

            // Case 4: Valid input, not busy, not bound project
            this.host.VisualStateManager.IsBusy = false;
            this.host.VisualStateManager.ClearBoundProject();
            Assert.IsFalse(testSubject.FixConflictsCommand.CanExecute(conflicts));

            // Case 5: Valid input, not busy, has bound project
            this.host.VisualStateManager.IsBusy = false;
            this.host.VisualStateManager.SetBoundProject(new Integration.Service.ProjectInformation());
            Assert.IsTrue(testSubject.FixConflictsCommand.CanExecute(conflicts));
        }