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); } } }
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_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); } }
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_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); } }
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 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); } }