Provides a minimalistic HTTP webserver that can provide only a single file. Useful for testing download code.
Наследование: IDisposable
Пример #1
0
 public void TestGetIconDownload()
 {
     const string iconData = "test";
     using (var server = new MicroServer("icon.png", iconData.ToStream()))
     {
         string path = _cache.GetIcon(server.FileUri, new SilentTaskHandler());
         File.ReadAllText(path).Should().Be(iconData);
     }
 }
        public void DownloadAndApplySingleFile()
        {
            using (var stream = SingleFileData.ToStream())
            using (var microServer = new MicroServer(SingleFileName, stream))
            {
                var file = new SingleFile {Href = microServer.FileUri, Destination = SingleFileName};
                file.DownloadAndApply(new SilentTaskHandler()).Dispose();

                file.Size.Should().Be(stream.Length);
            }
        }
        public void BuildSingleFile()
        {
            using (var originalStream = SingleFileData.ToStream())
            using (var microServer = new MicroServer(SingleFileName, originalStream))
            {
                var implementation = ImplementationUtils.Build(new SingleFile {Href = microServer.FileUri, Destination = SingleFileName}, new SilentTaskHandler());
                ("sha256new_" + implementation.ManifestDigest.Sha256New).Should().Be(_singleFileSha256Digest);

                var file = (SingleFile)implementation.RetrievalMethods[0];
                file.Size.Should().Be(originalStream.Length);
            }
        }
        public void DownloadAndApplyArchive()
        {
            using (var stream = typeof(ArchiveExtractorTest).GetEmbeddedStream("testArchive.zip"))
            using (var microServer = new MicroServer("archive.zip", stream))
            {
                var archive = new Archive {Href = microServer.FileUri};
                archive.DownloadAndApply(new SilentTaskHandler()).Dispose();

                archive.MimeType.Should().Be(Archive.MimeTypeZip);
                archive.Size.Should().Be(stream.Length);
            }
        }
        public void BuildArchive()
        {
            using (var stream = typeof(ArchiveExtractorTest).GetEmbeddedStream("testArchive.zip"))
            using (var microServer = new MicroServer("archive.zip", stream))
            {
                var implementation = ImplementationUtils.Build(new Archive {Href = microServer.FileUri}, new SilentTaskHandler());
                implementation.ManifestDigest.Sha256New.Should().Be(ArchiveSha256Digest);

                var archive = (Archive)implementation.RetrievalMethods[0];
                archive.MimeType.Should().Be(Archive.MimeTypeZip);
                archive.Size.Should().Be(stream.Length);
            }
        }
 public void AddMissingExceptions()
 {
     using (var stream = typeof(ArchiveExtractorTest).GetEmbeddedStream("testArchive.zip"))
     using (var microServer = new MicroServer("archive.zip", stream))
     {
         var implementation = new Implementation {ManifestDigest = new ManifestDigest(sha1New: "invalid"), RetrievalMethods = {new Archive {Href = microServer.FileUri}}};
         implementation.Invoking(x => x.AddMissing(new SilentTaskHandler())).ShouldThrow<DigestMismatchException>();
     }
 }
        public void AddMissingRecipe()
        {
            using (var stream = typeof(ArchiveExtractorTest).GetEmbeddedStream("testArchive.zip"))
            using (var microServer = new MicroServer("archive.zip", stream))
            {
                var implementation = new Implementation {RetrievalMethods = {new Recipe {Steps = {new Archive {Href = microServer.FileUri}}}}};
                implementation.AddMissing(new SilentTaskHandler());
                implementation.ManifestDigest.Sha256New.Should().Be(ArchiveSha256Digest);

                var archive = (Archive)((Recipe)implementation.RetrievalMethods[0]).Steps[0];
                archive.MimeType.Should().Be(Archive.MimeTypeZip);
                archive.Size.Should().Be(stream.Length);
            }
        }
Пример #8
0
 public virtual void SetUp()
 {
     Server = new MicroServer("file", GetTestFileStream());
 }
Пример #9
0
        public void TestGetIconDownloadFail()
        {
            const string iconData = "test";
            using (var server = new MicroServer("empty", new MemoryStream()))
            {
                // Write a file to the cache directory, mark it as outdated, use an unreachable/invalid URI
                string prePath = Path.Combine(_tempDir, new FeedUri(server.FileUri + "-invalid").Escape());
                File.WriteAllText(prePath, iconData);
                File.SetLastWriteTimeUtc(prePath, new DateTime(1980, 1, 1));

                string path = _cache.GetIcon(new Uri(server.FileUri + "-invalid"), new SilentTaskHandler());
                File.ReadAllText(path).Should().Be(iconData);
            }
        }
        /// <summary>
        /// Tests the sync logic with custom <see cref="AppList"/>s.
        /// </summary>
        /// <param name="resetMode">The <see cref="SyncResetMode"/> to pass to <see cref="SyncIntegrationManager.Sync"/>.</param>
        /// <param name="appListLocal">The current local <see cref="AppList"/>.</param>
        /// <param name="appListLast">The state of the <see cref="AppList"/> after the last successful sync.</param>
        /// <param name="appListServer">The current server-side <see cref="AppList"/>.</param>
        private void TestSync(SyncResetMode resetMode, AppList appListLocal, AppList appListLast, AppList appListServer)
        {
            appListLocal.SaveXml(_appListPath);
            appListLast?.SaveXml(_appListPath + SyncIntegrationManager.AppListLastSyncSuffix);

            using (var stream = File.Create(_appListPath + ".zip"))
                appListServer.SaveXmlZip(stream);

            using (var appListServerFile = File.OpenRead(_appListPath + ".zip"))
            using (var syncServer = new MicroServer("app-list", appListServerFile))
            {
                using (var integrationManager = new SyncIntegrationManager(_appListPath, new SyncServer {Uri = syncServer.ServerUri, Username = "******", Password = "******"}, interfaceId => new Feed(), new SilentTaskHandler()))
                    integrationManager.Sync(resetMode);

                appListServer = AppList.LoadXmlZip(syncServer.FileContent);
            }

            appListLocal = XmlStorage.LoadXml<AppList>(_appListPath);
            appListLast = XmlStorage.LoadXml<AppList>(_appListPath + SyncIntegrationManager.AppListLastSyncSuffix);
            appListServer.Should().Be(appListLocal, because: "Server and local data should be equal after sync");
            appListLast.Should().Be(appListLocal, because: "Last sync snapshot and local data should be equal after sync");
        }