Beispiel #1
0
 private static ScheduledTaskDetails GetTaskDetails(SchedulerAppTask schedulerAppTask, string exeAbsolutePath, bool isEnabled, bool isRunning, ScheduledTaskRepetition repetition)
 {
     return
         (new ScheduledTaskDetails(
              schedulerAppTask.Name,
              isEnabled,
              isRunning,
              DateTime.Now,
              DateTime.Now,
              exeAbsolutePath,
              schedulerAppTask.ScheduledHour,
              schedulerAppTask.ScheduledMinute,
              schedulerAppTask.ExecutionTimeLimitInMinutes,
              repetition));
 }
Beispiel #2
0
        public void SetUp()
        {
            _projectInfoRepositoryFake     = new Mock <IProjectInfoRepository>();
            _environmentInfoRepositoryFake = new Mock <IEnvironmentInfoRepository>();
            _artifactsRepositoryFake       = new Mock <IArtifactsRepository>();
            _taskSchedulerFake             = new Mock <ITaskScheduler>();
            _passwordCollectorFake         = new Mock <IPasswordCollector>();
            _directoryAdapterFake          = new Mock <IDirectoryAdapter>();
            _fileAdapterFake    = new Mock <IFileAdapter>();
            _zipFileAdapterFake = new Mock <IZipFileAdapter>();

            _projectInfo = ProjectInfoGenerator.GetSchedulerAppProjectInfo();

            SchedulerAppTask schedulerAppTask1 = _projectInfo.SchedulerAppTasks.First();
            SchedulerAppTask schedulerAppTask2 = _projectInfo.SchedulerAppTasks.Second();

            _environmentInfo =
                DeploymentDataGenerator.GetEnvironmentInfo(
                    new[]
            {
                new EnvironmentUser(schedulerAppTask1.UserId, "user_name_1"),
                new EnvironmentUser(schedulerAppTask2.UserId, "user_name_2"),
            });

            _projectInfoRepositoryFake.Setup(pir => pir.FindByName(It.IsAny <string>()))
            .Returns(_projectInfo);

            string exeAbsolutePath1 =
                Path.Combine(
                    _environmentInfo.SchedulerAppsBaseDirPath,
                    _projectInfo.SchedulerAppDirName,
                    schedulerAppTask1.ExecutableName);

            var scheduledTaskRepetition1 =
                new ScheduledTaskRepetition(
                    schedulerAppTask1.Repetition.Interval,
                    schedulerAppTask1.Repetition.Duration,
                    schedulerAppTask1.Repetition.StopAtDurationEnd);

            ScheduledTaskDetails taskDetails1 =
                GetTaskDetails(schedulerAppTask1, exeAbsolutePath1, true, false, scheduledTaskRepetition1);

            ScheduledTaskDetails taskDetailsDisabled1 =
                GetTaskDetails(schedulerAppTask1, exeAbsolutePath1, false, false, scheduledTaskRepetition1);

            int timesCalled11 = 0;

            _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.First(), schedulerAppTask1.Name))
            .Returns(() =>
            {
                timesCalled11++;

                if (timesCalled11 == 1)
                {
                    return(taskDetails1);
                }

                if (timesCalled11 == 2)
                {
                    return(taskDetailsDisabled1);
                }

                throw new Exception("Unexpected number of calls!");
            });

            int timesCalled21 = 0;

            _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.Second(), schedulerAppTask1.Name))
            .Returns(() =>
            {
                timesCalled21++;

                if (timesCalled21 == 1)
                {
                    return(taskDetails1);
                }

                if (timesCalled21 == 2)
                {
                    return(taskDetailsDisabled1);
                }

                throw new Exception("Unexpected number of calls!");
            });

            string exeAbsolutePath2 =
                Path.Combine(
                    _environmentInfo.SchedulerAppsBaseDirPath,
                    _projectInfo.SchedulerAppDirName,
                    schedulerAppTask2.ExecutableName);

            var scheduledTaskRepetition2 =
                new ScheduledTaskRepetition(
                    schedulerAppTask2.Repetition.Interval,
                    schedulerAppTask2.Repetition.Duration,
                    schedulerAppTask2.Repetition.StopAtDurationEnd);

            ScheduledTaskDetails taskDetails2 =
                GetTaskDetails(schedulerAppTask2, exeAbsolutePath2, true, false, scheduledTaskRepetition2);

            ScheduledTaskDetails taskDetailsDisabled2 =
                GetTaskDetails(schedulerAppTask2, exeAbsolutePath2, false, false, scheduledTaskRepetition2);

            int timesCalled12 = 0;

            _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.First(), schedulerAppTask2.Name))
            .Returns(() =>
            {
                timesCalled12++;

                if (timesCalled12 == 1)
                {
                    return(taskDetails2);
                }

                if (timesCalled12 == 2)
                {
                    return(taskDetailsDisabled2);
                }

                throw new Exception("Unexpected number of calls!");
            });

            int timesCalled22 = 0;

            _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.Second(), schedulerAppTask2.Name))
            .Returns(() =>
            {
                timesCalled22++;

                if (timesCalled22 == 1)
                {
                    return(taskDetails2);
                }

                if (timesCalled22 == 2)
                {
                    return(taskDetailsDisabled2);
                }

                throw new Exception("Unexpected number of calls!");
            });

            _environmentInfoRepositoryFake
            .Setup(x => x.FindByName(It.IsAny <string>()))
            .Returns(_environmentInfo);

            _directoryAdapterFake
            .Setup(x => x.Exists(It.IsAny <string>()))
            .Returns(true);

            _deployTask =
                new DeploySchedulerAppDeploymentTask(
                    _projectInfoRepositoryFake.Object,
                    _environmentInfoRepositoryFake.Object,
                    _artifactsRepositoryFake.Object,
                    _taskSchedulerFake.Object,
                    _passwordCollectorFake.Object,
                    _directoryAdapterFake.Object,
                    _fileAdapterFake.Object,
                    _zipFileAdapterFake.Object);

            _deployTask.Initialize(DeploymentInfoGenerator.GetSchedulerAppDeploymentInfo());
        }