예제 #1
0
        public void ShouldNotStartupWhenAJobSyncIsDisabled(string jobNamesEnabled, string jobNamesDisabled)
        {
            //Arrange
            var jobsEnabled = Createjobs(jobNamesEnabled, true);
            var jobsDisabled = Createjobs(jobNamesDisabled, false);

            var jobs = new List<Job>(jobsEnabled);
            jobs.AddRange(jobsDisabled);
            var config = new Config {Jobs = jobs};
            var commonMocks = SetupAndGetCommonMocks(config);

            //Act
            var applicationJobManager = new SyncApp(commonMocks.ConfigReaderMock.Object, commonMocks.SyncFactoryMock.Object);
            applicationJobManager.Start();

            //Assert
            VerifyCommomServices(jobs.Count, applicationJobManager, commonMocks.ConfigReaderMock, commonMocks.SyncFactoryMock, ApplicationIsRunning);
            foreach (var jobSyncItem in commonMocks.JobSyncList.Where(x => jobNamesEnabled.Contains(x.Object.Name)))
            {
                jobSyncItem.Verify(x => x.Start(), Times.Once);
            }

            foreach (var jobSyncItem in commonMocks.JobSyncList.Where(x => jobNamesDisabled.Contains(x.Object.Name)))
            {
                jobSyncItem.Verify(x => x.Start(), Times.Never);
            }
        }
예제 #2
0
        public void ShouldRaiseStartupEventWhenAJobSyncIsStarted(string jobNamesWithStartupWatchers, string jobNamesWithoutWatchers)
        {
            //Arrange
            var jobsWithStartSync = CreatejobsWithStartupSync(jobNamesWithStartupWatchers, true);
            var jobsNoStartSync = CreatejobsWithStartupSync(jobNamesWithoutWatchers, false);

            var jobs = new List<Job>(jobsWithStartSync);
            jobs.AddRange(jobsNoStartSync);
            var config = new Config { Jobs = jobs };
            var commonMocks = SetupAndGetCommonMocks(config);

            //Act
            var applicationJobManager = new SyncApp(commonMocks.ConfigReaderMock.Object, commonMocks.SyncFactoryMock.Object);
            applicationJobManager.Start();

            //Assert
            VerifyCommomServices(jobs.Count, applicationJobManager, commonMocks.ConfigReaderMock, commonMocks.SyncFactoryMock, ApplicationIsRunning);
            foreach (var jobSyncItem in commonMocks.JobSyncList.Where(x => jobNamesWithStartupWatchers.Contains(x.Object.Name)))
            {
                Assert.IsNotNull(jobSyncItem.Object.OnStartup);
            }

            foreach (var jobSyncItem in commonMocks.JobSyncList.Where(x => jobNamesWithoutWatchers.Contains(x.Object.Name)))
            {
                Assert.IsNull(jobSyncItem.Object.OnStartup);
            }
        }
예제 #3
0
        public void ShouldRaiseSyncCompleteEventWhenAJobSyncIsStarted()
        {
            //Arrange
            var job = CreateJobWithWhenWatchedSync("testJob");

            var jobs = new List<Job> { job };
            jobs.AddRange(jobs);
            var config = new Config { Jobs = jobs };

            var configReaderMock = new Mock<IConfigReader>();
            var syncFactoryMock = new Mock<IJobSyncFactory>();
            var jobSyncStub = new JobSyncStub(job.Name, false);

            configReaderMock.Setup(x => x.GetLoadedConfigs()).Returns(new[] { config }).Verifiable();

            syncFactoryMock.Setup(x => x.CreateJobSynchronizers(config))
                            .Returns(new []{ jobSyncStub })
                            .Verifiable();

            //Act
            var applicationJobManager = new SyncApp(configReaderMock.Object, syncFactoryMock.Object);
            var hasRunCompleted = false;
            applicationJobManager.OnRunComplete += name => { hasRunCompleted = true; };
            applicationJobManager.Start();

            jobSyncStub.TriggerOnRunComplete();

            //Assert
            Assert.IsTrue(hasRunCompleted);
        }
예제 #4
0
        public void ShouldStartupApplicationWithANumberOfSychronizers(string jobNames)
        {
            //Arrange
            var jobs = Createjobs(jobNames, true);
            var config = new Config { Jobs = jobs };
            var commonMocks = SetupAndGetCommonMocks(config);

            //Act
            var applicationJobManager = new SyncApp(commonMocks.ConfigReaderMock.Object, commonMocks.SyncFactoryMock.Object);
            applicationJobManager.Start();

            //Assert
            VerifyCommomServices(jobs.Length, applicationJobManager, commonMocks.ConfigReaderMock, commonMocks.SyncFactoryMock, ApplicationIsRunning);
            foreach (var jobSyncItem in commonMocks.JobSyncList)
            {
                jobSyncItem.Verify(x => x.Start(), Times.Once);
                jobSyncItem.Verify(x => x.Stop(), Times.Never);
            }
        }