Example #1
0
        public void GivenTestData_WhenBuildPackage_ShouldBeAbleToReadManifest()
        {
            string specFile    = new TestResources().WriteTestData_1();
            string buildFolder = Path.Combine(Path.GetTempPath(), nameof(nBlog), "build", Guid.NewGuid().ToString());

            string packageFile = new ArticlePackageBuilder()
                                 .SetSpecFile(specFile)
                                 .SetBuildFolder(buildFolder)
                                 .SetObjFolder(Path.Combine(buildFolder, "obj"))
                                 .Build();

            byte[]         fileBytes      = File.ReadAllBytes(packageFile);
            ArticlePayload articlePayload = fileBytes.ToArticlePayload((ArticleId)"id");

            ArticleManifest articleManifest = articlePayload.ReadManifest();

            articleManifest.Should().NotBeNull();
            articleManifest.Should().NotBeNull();
            articleManifest.ArticleId.Should().Be("article/contact");
            articleManifest.Title.Should().Be("Contact");
            articleManifest.Author.Should().Be("Ghost Writer");
            articleManifest.Date.Should().Be(new DateTime(2020, 1, 2));

            Enumerable.SequenceEqual(articleManifest.Tags, new[] { "Tag1", "Tag2" }).Should().BeTrue();
        }
Example #2
0
        public async Task GivenRealPackage_WhenFullLifeCycleInFolder_ShouldPass()
        {
            TestWebsiteHost host = TestApplication.GetHost();

            string specFile    = new TestResources().WriteTestData_1();
            string buildFolder = Path.Combine(Path.GetTempPath(), nameof(nBlog), "build", Guid.NewGuid().ToString());

            string packageFile = new ArticlePackageBuilder()
                                 .SetSpecFile(specFile)
                                 .SetBuildFolder(buildFolder)
                                 .SetObjFolder(Path.Combine(buildFolder, "obj"))
                                 .Build();

            byte[]          packageBytes    = File.ReadAllBytes(packageFile);
            ArticlePayload  articlePayload  = packageBytes.ToArticlePayload();
            ArticleManifest articleManifest = packageBytes.ReadManifest();

            await host.ArticleClient.Set(articlePayload);

            ArticlePayload?readPayload = await host.ArticleClient.Get((ArticleId)articlePayload.Id);

            readPayload.Should().NotBeNull();

            ArticleManifest readArticleManifest = articlePayload.ReadManifest();

            articleManifest.ArticleId.Should().Be(readArticleManifest.ArticleId);
            articleManifest.PackageVersion.Should().Be(readArticleManifest.PackageVersion);
            articleManifest.Title.Should().Be(readArticleManifest.Title);
            articleManifest.Summary.Should().Be(readArticleManifest.Summary);
            articleManifest.Author.Should().Be(readArticleManifest.Author);
            articleManifest.ImageFile.Should().Be(readArticleManifest.ImageFile);
            articleManifest.Date.Should().Be(readArticleManifest.Date);
            Enumerable.SequenceEqual(articleManifest.Tags !, readArticleManifest.Tags !).Should().BeTrue();
            Enumerable.SequenceEqual(articleManifest.Categories !, readArticleManifest.Categories !).Should().BeTrue();

            (articlePayload == readPayload).Should().BeTrue();

            BatchSet <string> searchList = await host.ArticleClient.List(QueryParameters.Default).ReadNext();

            searchList.Should().NotBeNull();

            searchList.Records.Any(x => x.StartsWith(articlePayload.Id)).Should().BeTrue();

            (await host.ArticleClient.Delete((ArticleId)articlePayload.Id)).Should().BeTrue();

            searchList = await host.ArticleClient.List(QueryParameters.Default).ReadNext();

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.StartsWith(articlePayload.Id)).Should().BeFalse();
        }
Example #3
0
        public void GivenTestData_WhenBuildPackage_ShouldVerify()
        {
            string specFile    = new TestResources().WriteTestData_1();
            string buildFolder = Path.Combine(Path.GetTempPath(), nameof(nBlog), "build", Guid.NewGuid().ToString());

            string packageFile = new ArticlePackageBuilder()
                                 .SetSpecFile(specFile)
                                 .SetBuildFolder(buildFolder)
                                 .SetObjFolder(Path.Combine(buildFolder, "obj"))
                                 .Build();

            IReadOnlyList <WordCount> wordCounts = new ArticlePackageIndexBuilder().Build(packageFile);

            wordCounts.Should().NotBeNull();
            wordCounts.Count.Should().BeGreaterThan(0);

            var list = new[]
            {
                new WordCount {
                    Word = "#nblog", Count = 1
                },
                new WordCount {
                    Word = "Contact", Count = 2
                },
                new WordCount {
                    Word = "Email", Count = 1
                },
                new WordCount {
                    Word = "nBlog@domain", Count = 1
                },
                new WordCount {
                    Word = "net", Count = 1
                },
                new WordCount {
                    Word = "Please", Count = 1
                },
                new WordCount {
                    Word = "Twitter", Count = 1
                },
                new WordCount {
                    Word = "us", Count = 1
                },
            };

            Enumerable.SequenceEqual(wordCounts, list).Should().BeTrue();
        }
Example #4
0
        public void GivenTestData_WhenBuildPackage_ShouldVerify()
        {
            string specFile    = new TestResources().WriteTestData_1();
            string buildFolder = Path.Combine(Path.GetTempPath(), nameof(nBlog), "build", Guid.NewGuid().ToString());

            string packageFile = new ArticlePackageBuilder()
                                 .SetSpecFile(specFile)
                                 .SetBuildFolder(buildFolder)
                                 .SetObjFolder(Path.Combine(buildFolder, "obj"))
                                 .Build();

            ArticlePackageDetails articlePackageDetails = new ArticlePackageExpander(packageFile).Expand();

            articlePackageDetails.Should().NotBeNull();
            articlePackageDetails.ArticleManifest.Should().NotBeNull();
            articlePackageDetails.ArticleManifest.ArticleId.Should().Be("article/contact");
            articlePackageDetails.ArticleManifest.Title.Should().Be("Contact");
            articlePackageDetails.ArticleManifest.Author.Should().Be("Ghost Writer");
            articlePackageDetails.ArticleManifest.Date.Should().Be(new DateTime(2020, 1, 2));

            Enumerable.SequenceEqual(articlePackageDetails.ArticleManifest.Tags, new[] { "Tag1", "Tag2" }).Should().BeTrue();

            var files = new[]
            {
                "articlePackage.manifest.json",
                "Application.Contact.md",
            };

            Enumerable.SequenceEqual(articlePackageDetails.Files.OrderBy(x => x), files.OrderBy(x => x)).Should().BeTrue();

            const string mdFileName = "Application.Contact.md";

            byte[] md        = GetFileHash(Path.Combine(Path.GetDirectoryName(specFile), mdFileName));
            byte[] restoreMd = GetFileHash(Path.Combine(articlePackageDetails.BasePath, mdFileName));
            Enumerable.SequenceEqual(md, restoreMd).Should().BeTrue();
        }