Пример #1
0
        public async Task TestRemoteSource_AcquireAsync()
        {
            RemoteTemplatesSource   rts = new RemoteTemplatesSource();
            CancellationTokenSource cts = new CancellationTokenSource();

            await rts.LoadConfigAsync(cts.Token);

            var package = rts.Config.Latest;

            await rts.AcquireAsync(package, cts.Token);

            string acquiredContentFolder = package.LocalPath;

            Assert.NotNull(acquiredContentFolder);

            // Ensure package is not downloaded again if already downloaded
            await rts.AcquireAsync(package, cts.Token);

            Assert.True(acquiredContentFolder == package.LocalPath);

            // Reset localPath and ensure it is acquired again
            if (Directory.Exists(Path.GetDirectoryName(package.LocalPath)))
            {
                Directory.Delete(Path.GetDirectoryName(package.LocalPath), true);
            }

            await rts.AcquireAsync(package, cts.Token);

            Assert.True(package.LocalPath != acquiredContentFolder);

            if (Directory.Exists(Path.GetDirectoryName(package.LocalPath)))
            {
                Directory.Delete(Path.GetDirectoryName(package.LocalPath), true);
            }
        }
Пример #2
0
        public async Task TestRemoteSource_GetContentAsync()
        {
            string drive   = Path.GetPathRoot(new Uri(typeof(TemplatePackageTests).Assembly.CodeBase).LocalPath);
            string testDir = Path.Combine(drive, $@"Temp\TestRts{Process.GetCurrentProcess().Id}_{Thread.CurrentThread.ManagedThreadId}");

            try
            {
                RemoteTemplatesSource   rts = new RemoteTemplatesSource();
                CancellationTokenSource cts = new CancellationTokenSource();
                await rts.LoadConfigAsync(cts.Token);

                var package = rts.Config.Latest;

                await rts.AcquireAsync(package, cts.Token);

                var contentInfo = await rts.GetContentAsync(package, testDir, cts.Token);

                Assert.True(Directory.Exists(contentInfo.Path));
            }
            finally
            {
                if (Directory.Exists(testDir))
                {
                    Directory.Delete(testDir, true);
                }
            }
        }
Пример #3
0
        public async Task TestRemoteSource_GetLocalContentAsync()
        {
            string drive   = Path.GetPathRoot(new Uri(typeof(TemplatePackageTests).Assembly.CodeBase).LocalPath);
            string testDir = Path.Combine(drive, $@"Temp\TestRts{Process.GetCurrentProcess().Id}_{Thread.CurrentThread.ManagedThreadId}");

            try
            {
                RemoteTemplatesSource   rts = new RemoteTemplatesSource(Platforms.Uwp, ProgrammingLanguages.CSharp);
                CancellationTokenSource cts = new CancellationTokenSource();

                var packageFile = Path.GetFullPath(@".\Packaging\MsSigned\Templates.mstx");

                var package = new TemplatesPackageInfo()
                {
                    Name           = Path.GetFileName(packageFile),
                    LocalPath      = packageFile,
                    WizardVersions = new List <Version>()
                    {
                        GenContext.GetWizardVersionFromAssembly()
                    },
                };

                var contentInfo = await rts.GetContentAsync(package, testDir, cts.Token);

                Assert.True(Directory.Exists(contentInfo.Path));
            }
            finally
            {
                if (Directory.Exists(testDir))
                {
                    Directory.Delete(testDir, true);
                }
            }
        }
Пример #4
0
        public async Task TestRemoteSource_AcquireCancelAsync()
        {
            RemoteTemplatesSource   rts = new RemoteTemplatesSource(Platforms.Uwp, ProgrammingLanguages.CSharp);
            CancellationTokenSource cts = new CancellationTokenSource();

            await rts.LoadConfigAsync(cts.Token);

            var package = rts.Config.Latest;

            cts.CancelAfter(TimeSpan.FromMilliseconds(100));
            await Assert.ThrowsAsync <OperationCanceledException>(async() =>
            {
                await rts.AcquireAsync(package, cts.Token);
            });

            string acquiredContentFolder = package.LocalPath;

            Assert.Null(acquiredContentFolder);

            // Ensure package is downloaded again if cancelled
            await rts.AcquireAsync(package, cts.Token);

            Assert.True(acquiredContentFolder != package.LocalPath);

            if (Directory.Exists(Path.GetDirectoryName(package.LocalPath)))
            {
                Directory.Delete(Path.GetDirectoryName(package.LocalPath), true);
            }
        }
        public async Task TestRemoteSource_AcquireCancelAsync()
        {
            var platform = Platforms.Uwp;
            var language = ProgrammingLanguages.CSharp;

            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "InstalledTemplates");

            RemoteTemplatesSource   rts = new RemoteTemplatesSource(platform, language, path, new TestDigitalSignatureService());
            CancellationTokenSource cts = new CancellationTokenSource();

            await rts.LoadConfigAsync(cts.Token);

            var package = rts.Config.Latest;

            cts.CancelAfter(TimeSpan.FromMilliseconds(20));
            await Assert.ThrowsAsync <OperationCanceledException>(async() =>
            {
                await rts.AcquireAsync(package, cts.Token);
            });

            string acquiredContentFolder = package.LocalPath;

            Assert.Null(acquiredContentFolder);

            // Ensure package is downloaded again if cancelled
            await rts.AcquireAsync(package, cts.Token);

            Assert.True(acquiredContentFolder != package.LocalPath);

            if (Directory.Exists(Path.GetDirectoryName(package.LocalPath)))
            {
                Directory.Delete(Path.GetDirectoryName(package.LocalPath), true);
            }
        }
Пример #6
0
        public async Task TestRemoteSource_GetContentCancelAsync()
        {
            string drive   = Path.GetPathRoot(new Uri(typeof(TemplatePackageTests).Assembly.CodeBase).LocalPath);
            string testDir = Path.Combine(drive, $@"Temp\TestRts{Process.GetCurrentProcess().Id}_{Thread.CurrentThread.ManagedThreadId}");

            try
            {
                RemoteTemplatesSource   rts = new RemoteTemplatesSource(Platforms.Uwp, ProgrammingLanguages.CSharp);
                CancellationTokenSource cts = new CancellationTokenSource();
                await rts.LoadConfigAsync(cts.Token);

                var package = rts.Config.Latest;

                await rts.AcquireAsync(package, cts.Token);

                cts.CancelAfter(TimeSpan.FromSeconds(1));
                await Assert.ThrowsAsync <OperationCanceledException>(async() =>
                {
                    await rts.GetContentAsync(package, testDir, cts.Token);
                });

                // Ensure package is extracted again if cancelled
                var contentInfo = await rts.GetContentAsync(package, testDir, cts.Token);

                Assert.True(Directory.Exists(contentInfo.Path));
            }
            finally
            {
                if (Directory.Exists(testDir))
                {
                    Directory.Delete(testDir, true);
                }
            }
        }
        public async Task TestRemoteSource_GetContentNoPackageAsync()
        {
            string drive   = Path.GetPathRoot(new Uri(typeof(TemplatePackageTests).Assembly.CodeBase).LocalPath);
            string testDir = Path.Combine(drive, $@"Temp\TestRts{Process.GetCurrentProcess().Id}_{Thread.CurrentThread.ManagedThreadId}");

            try
            {
                var    platform = Platforms.Uwp;
                var    language = ProgrammingLanguages.CSharp;
                string path     = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "InstalledTemplates");

                RemoteTemplatesSource   rts = new RemoteTemplatesSource(platform, language, path, new TestDigitalSignatureService());
                CancellationTokenSource cts = new CancellationTokenSource();
                await rts.LoadConfigAsync(cts.Token);

                var package = rts.Config.Latest;

                var contentInfo = await rts.GetContentAsync(package, testDir, cts.Token);

                Assert.Null(contentInfo);
            }
            finally
            {
                if (Directory.Exists(testDir))
                {
                    Directory.Delete(testDir, true);
                }
            }
        }
        public void TestRemoteSource_Acquire()
        {
            RemoteTemplatesSource rts = new RemoteTemplatesSource();

            rts.LoadConfig();
            var package = rts.Config.Latest;

            rts.Acquire(ref package);

            string acquiredContentFolder = package.LocalPath;

            Assert.NotNull(acquiredContentFolder);

            // Ensure package is not downloaded again if already downloaded
            rts.Acquire(ref package);
            Assert.True(acquiredContentFolder == package.LocalPath);

            // Reset localPath and ensure it is acquired again
            if (Directory.Exists(Path.GetDirectoryName(package.LocalPath)))
            {
                Directory.Delete(Path.GetDirectoryName(package.LocalPath), true);
            }

            rts.Acquire(ref package);

            Assert.True(package.LocalPath != acquiredContentFolder);

            if (Directory.Exists(Path.GetDirectoryName(package.LocalPath)))
            {
                Directory.Delete(Path.GetDirectoryName(package.LocalPath), true);
            }
        }
        public void TestRemoteSource()
        {
            // Bug #333
            // Location will give access to temp location.
            // code base won't if they are on diff drives
            //
            // If someone has a temp dir that is different than their extention
            // move will fail, you need to copy / delete
            // string drive = Path.GetPathRoot(Assembly.GetExecutingAssembly().Location);
            string drive        = Path.GetPathRoot(new Uri(typeof(TemplatePackageTests).Assembly.CodeBase).LocalPath);
            string targetFolder = Path.Combine(drive, @"Temp\TestRts");

            try
            {
                RemoteTemplatesSource rts = new RemoteTemplatesSource();
                rts.Acquire(targetFolder);

                string acquiredContentFolder = Directory.EnumerateDirectories(targetFolder).FirstOrDefault();

                Assert.NotNull(acquiredContentFolder);

                // There is just one
                Assert.True(Directory.EnumerateDirectories(targetFolder).Count() == 1);

                // Ensure even downloaded, if there is coincident content, it is not duplicated.
                rts.Acquire(targetFolder);
                Assert.True(Directory.EnumerateDirectories(targetFolder).Count() == 1);

                // Change the previous acquired content and ensure it is acquired again
                Directory.Move(acquiredContentFolder, acquiredContentFolder + "_old");

                rts.Acquire(targetFolder);

                Assert.True(Directory.EnumerateDirectories(targetFolder).Count() == 2);
            }
            finally
            {
                if (Directory.Exists(targetFolder))
                {
                    Directory.Delete(targetFolder, true);
                }
            }
        }
        public async Task DigitalSignaturService_VerifySignatures()
        {
            string drive = Path.GetPathRoot(new Uri(typeof(DigitalSignaturServiceTests).Assembly.CodeBase).LocalPath);

            DigitalSignatureService dss = new DigitalSignatureService();
            RemoteTemplatesSource   rts = new RemoteTemplatesSource(Platforms.Uwp, ProgrammingLanguages.CSharp, null, new DigitalSignatureService());
            CancellationTokenSource cts = new CancellationTokenSource();
            await rts.LoadConfigAsync(cts.Token);

            var templatesPackage = rts.Config.Latest;

            await rts.AcquireAsync(templatesPackage, cts.Token);

            using (Package package = Package.Open(templatesPackage.LocalPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var signatureValid = dss.VerifySignatures(package);

                Assert.True(signatureValid);
            }
        }
        public async Task TestRemoteSource_AcquireAsync()
        {
            var platform = Platforms.Uwp;
            var language = ProgrammingLanguages.CSharp;

            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "InstalledTemplates");

            RemoteTemplatesSource   rts = new RemoteTemplatesSource(platform, language, path, new TestDigitalSignatureService());
            CancellationTokenSource cts = new CancellationTokenSource();

            await rts.LoadConfigAsync(cts.Token);

            var package = rts.Config.Latest;

            await rts.AcquireAsync(package, cts.Token);

            string acquiredContentFolder = package.LocalPath;

            Assert.NotNull(acquiredContentFolder);

            // Ensure package is not downloaded again if already downloaded
            await rts.AcquireAsync(package, cts.Token);

            Assert.True(acquiredContentFolder == package.LocalPath);

            // Reset localPath and ensure it is acquired again
            if (Directory.Exists(Path.GetDirectoryName(package.LocalPath)))
            {
                Directory.Delete(Path.GetDirectoryName(package.LocalPath), true);
            }

            await rts.AcquireAsync(package, cts.Token);

            Assert.True(package.LocalPath != acquiredContentFolder);

            if (Directory.Exists(Path.GetDirectoryName(package.LocalPath)))
            {
                Directory.Delete(Path.GetDirectoryName(package.LocalPath), true);
            }
        }
Пример #12
0
        public void TestRemoteSource()
        {
            string drive        = Path.GetPathRoot(new Uri(typeof(TemplatePackageTests).Assembly.CodeBase).LocalPath);
            string targetFolder = Path.Combine(drive, $@"Temp\TestRts{Process.GetCurrentProcess().Id}_{Thread.CurrentThread.ManagedThreadId}");

            try
            {
                RemoteTemplatesSource rts = new RemoteTemplatesSource();
                rts.Acquire(targetFolder);

                string acquiredContentFolder = Directory.EnumerateDirectories(targetFolder).FirstOrDefault();

                Assert.NotNull(acquiredContentFolder);

                // There is just one
                Assert.True(Directory.EnumerateDirectories(targetFolder).Count() == 1);

                // Ensure even downloaded, if there is coincident content, it is not duplicated.
                rts.Acquire(targetFolder);
                Assert.True(Directory.EnumerateDirectories(targetFolder).Count() == 1);

                // Change the previous acquired content and ensure it is acquired again
                Directory.Move(acquiredContentFolder, acquiredContentFolder + "_old");

                rts.Acquire(targetFolder);

                Assert.True(Directory.EnumerateDirectories(targetFolder).Count() == 2);
            }
            finally
            {
                if (Directory.Exists(targetFolder))
                {
                    Directory.Delete(targetFolder, true);
                }
            }
        }
Пример #13
0
        public void TestRemoteSource()
        {
            string drive        = Path.GetPathRoot(Assembly.GetExecutingAssembly().Location);
            string targetFolder = Path.Combine(drive, @"Temp\TestRts");

            try
            {
                RemoteTemplatesSource rts = new RemoteTemplatesSource();
                rts.Adquire(targetFolder);

                string aquiredContentFolder = Directory.EnumerateDirectories(targetFolder).FirstOrDefault();

                Assert.NotNull(aquiredContentFolder);

                //There is just one
                Assert.True(Directory.EnumerateDirectories(targetFolder).Count() == 1);

                //Ensure even downloaded, if there is coincident content, it is not duplicated.
                rts.Adquire(targetFolder);
                Assert.True(Directory.EnumerateDirectories(targetFolder).Count() == 1);

                //Change the previous adquired content and ensure it is adquired again
                Directory.Move(aquiredContentFolder, aquiredContentFolder + "_old");

                rts.Adquire(targetFolder);

                Assert.True(Directory.EnumerateDirectories(targetFolder).Count() == 2);
            }
            finally
            {
                if (Directory.Exists(targetFolder))
                {
                    Directory.Delete(targetFolder, true);
                }
            }
        }
        public void TestRemoteSource_GetContent()
        {
            string drive   = Path.GetPathRoot(new Uri(typeof(TemplatePackageTests).Assembly.CodeBase).LocalPath);
            string testDir = Path.Combine(drive, $@"Temp\TestRts{Process.GetCurrentProcess().Id}_{Thread.CurrentThread.ManagedThreadId}");

            try
            {
                RemoteTemplatesSource rts = new RemoteTemplatesSource();
                rts.LoadConfig();
                var package = rts.Config.Latest;

                rts.Acquire(ref package);
                var contentInfo = rts.GetContent(package, testDir);

                Assert.True(Directory.Exists(contentInfo.Path));
            }
            finally
            {
                if (Directory.Exists(testDir))
                {
                    Directory.Delete(testDir, true);
                }
            }
        }