Beispiel #1
0
        public void FullCycleTest()
        {
            this.goalStateFileIdx = 0;

            string         webApiBaseAddress = "http://hiahia.com:8080";
            string         appDataRootPath   = TestUtility.TestDirectory + "\\Data";
            string         localFileRootPath = UpdateServicelet.GetUpdateServiceRootPath(appDataRootPath);
            PackageManager pkgMgr            = new PackageManager(
                new FilePathResolver(webApiBaseAddress, localFileRootPath),
                new Uri("http://dummy"),
                TimeSpan.FromSeconds(10),
                new TraceLogger(new MockUpTraceEventProvider()));

            pkgMgr.TimerFired     += this.OnTimerFired;
            pkgMgr.TimerCompleted += this.OnTimerCompleted;

            pkgMgr.Start();
            this.syncEvent.WaitOne();

            // allow the last no-op timer to be scheduled if allowed by the system
            Thread.Sleep(3000);

            pkgMgr.Stop();

            // verify that the timer never gets fired again.
            Thread.Sleep(20000);
            Assert.AreEqual(3, this.goalStateFileIdx);
            Directory.Delete(appDataRootPath, recursive: true);
        }
Beispiel #2
0
        public void IntegrationTest()
        {
            TraceLogger   traceLogger      = new TraceLogger(new MockUpTraceEventProvider());
            Uri           goalStateFileUri = this.PrepareTargetGoalStateFile();
            ProgramConfig config           = new ProgramConfig(
                ProgramParameterDefinitions.ExecutionModes.Service,
                new AppConfig(
                    new Uri("http://localhost", UriKind.Absolute),
                    null,
                    TestUtility.TestDirectory + "\\Data",
                    goalStateFileUri,
                    TimeSpan.FromSeconds(3000),
                    TimeSpan.FromSeconds(3000)));
            UpdateServicelet server = new UpdateServicelet(config, traceLogger);

            server.Start();

            // ensure that the packages have been downloaded
            Thread.Sleep(10000);

            GoalState goalState;

            Assert.IsTrue(GoalState.TryCreate(new Uri("http://localhost/api/files/goalstate", UriKind.Absolute), server.Logger, out goalState));
            string packageDownloadDstDirectory = TestUtility.TestDirectory + "\\DownloadDstDir";

            if (!Directory.Exists(packageDownloadDstDirectory))
            {
                Directory.CreateDirectory(packageDownloadDstDirectory);
            }

            TaskManager tskMgr = new TaskManager(traceLogger);

            foreach (PackageDetails package in goalState.Packages)
            {
                string fileName = new Uri(package.TargetPackageLocation).Segments.Last();
                tskMgr.AddTask(Utility.DownloadFileAsync(package.TargetPackageLocation, packageDownloadDstDirectory + "\\" + fileName));
            }

            Assert.IsTrue(tskMgr.WaitForAllTasks());

            Assert.AreEqual(5, Directory.GetFiles(TestUtility.TestDirectory + "\\Data\\UpdateService\\Packages", "*.cab", SearchOption.TopDirectoryOnly).Length);


            server.Stop();

            Assert.IsFalse(GoalState.TryCreate(new Uri("http://localhost/api/files/goalstat", UriKind.Absolute), server.Logger, out goalState));

            Directory.Delete(TestUtility.TestDirectory + "\\Data", recursive: true);
            File.Delete(TestUtility.TestDirectory + "\\WsusIntegration.json");
            Directory.Delete(packageDownloadDstDirectory, recursive: true);
        }
Beispiel #3
0
        public void ConstructorTest()
        {
            ProgramConfig svcConfig = new ProgramConfig(
                ProgramParameterDefinitions.ExecutionModes.Service,
                new AppConfig(new Uri("http://hiahia.net:433", UriKind.Absolute), null, TestUtility.TestDirectory, new Uri("http://goalstate"), TimeSpan.FromHours(12), TimeSpan.FromHours(24)));
            TraceLogger      logger = new TraceLogger(new MockUpTraceEventProvider());
            UpdateServicelet result = new UpdateServicelet(svcConfig, logger);

            Assert.IsNotNull(result.ApiHost);
            Assert.AreSame(logger, result.ApiHost.Logger);
            Assert.AreEqual(svcConfig.AppConfig.EndpointBaseAddress.AbsoluteUri, result.ApiHost.BaseAddress);
            Assert.IsNotNull(result.ApiHost.FilePathResolver);

            Assert.IsNotNull(result.PkgMgr);

            string dataRootPath = TestUtility.TestDirectory + "\\UpdateService";

            Assert.IsTrue(Directory.Exists(dataRootPath));
            Directory.Delete(dataRootPath, recursive: true);
        }