public void MatchingOrchestrator_ValidNewSchedule(string anarchyType)
        {
            //arrange
            var schedule     = new Schedule();
            var orchestrator = Substitute.For <IActionOrchestrator>();
            var action       = Substitute.For <ICauseAnarchy>();

            action.Name.Returns("testAnarchyType");
            orchestrator.AnarchyAction.Returns(action);
            var sut = new AnarchyManagerNew(new [] { orchestrator });

            //act
            sut.AssignScheduleToActionOrchestrator(anarchyType, schedule, false);

            //assert
            orchestrator.Received(1).AssociateSchedule(schedule);
        }
        public void NoMatchingOrchestrator(string anarchyType)
        {
            //arrange
            var schedule     = new Schedule();
            var orchestrator = Substitute.For <IActionOrchestrator>();
            var action       = Substitute.For <ICauseAnarchy>();

            action.Name.Returns("testAnarchyType");
            orchestrator.AnarchyAction.Returns(action);
            var sut = new AnarchyManagerNew(new [] { orchestrator });

            //act
            var exception = Assert.Catch(() => sut.AssignScheduleToActionOrchestrator(anarchyType, schedule, false));

            //assert
            exception.Should().BeOfType <AnarchyActionNotFoundException>();
            orchestrator.Received(0).AssociateSchedule(Arg.Any <Schedule>());
        }
        public void MatchingOrchestrator_ScheduleExists_AllowUpdate()
        {
            //arrange
            var orchestrator = Substitute.For <IActionOrchestrator>();
            var action       = Substitute.For <ICauseAnarchy>();

            action.Name.Returns("testAnarchyType");
            orchestrator.ExecutionSchedule.Returns(new Schedule());
            orchestrator.AnarchyAction.Returns(action);
            var sut      = new AnarchyManagerNew(new[] { orchestrator });
            var schedule = new Schedule();

            //act
            sut.AssignScheduleToActionOrchestrator("testAnarchyType", schedule, true);

            //assert
            orchestrator.Received(1).AssociateSchedule(schedule);
        }
        public void MatchingOrchestrator_ScheduleExists_DoNotAllowUpdate()
        {
            //arrange
            var orchestrator = Substitute.For <IActionOrchestrator>();
            var action       = Substitute.For <ICauseAnarchy>();

            action.Name.Returns("testAnarchyType");
            orchestrator.ExecutionSchedule.Returns(new Schedule());
            orchestrator.AnarchyAction.Returns(action);
            var sut      = new AnarchyManagerNew(new [] { orchestrator });
            var schedule = new Schedule();

            //act
            var exception = Assert.Catch(() => sut.AssignScheduleToActionOrchestrator("testAnarchyType", new Schedule(), false));

            //assert
            exception.Should().BeOfType <ScheduleExistsException>();
            orchestrator.Received(0).AssociateSchedule(schedule);
        }
        public void SelectsFirstMatchingOrchestrator(string firstActionName, string secondActionName, int firstCount, int secondCount)
        {
            //arrange
            var schedule      = new Schedule();
            var orchestrator1 = Substitute.For <IActionOrchestrator>();
            var orchestrator2 = Substitute.For <IActionOrchestrator>();
            var firstAction   = Substitute.For <ICauseAnarchy>();

            firstAction.Name.Returns(firstActionName);
            var secondAction = Substitute.For <ICauseAnarchy>();

            secondAction.Name.Returns(secondActionName);
            orchestrator1.AnarchyAction.Returns(firstAction);
            orchestrator2.AnarchyAction.Returns(secondAction);
            var sut = new AnarchyManagerNew(new [] { orchestrator1, orchestrator2 });

            //act
            sut.AssignScheduleToActionOrchestrator("firstActionName", schedule, false);

            //assert
            orchestrator1.Received(firstCount).AssociateSchedule(Arg.Any <Schedule>());
            orchestrator2.Received(secondCount).AssociateSchedule(Arg.Any <Schedule>());
        }