Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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);
                }
            }
        }
        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);
                }
            }
        }