private async Task Delete(DocumentId documentId, bool shouldExist)
    {
        ContractClient client = TestApplication.GetContractClient();

        var query = new QueryParameter()
        {
            Filter    = documentId.Id.Split('/').Reverse().Skip(1).Reverse().Join("/"),
            Recursive = false,
        };

        BatchSet <string> searchList = await client.Search(query).ReadNext();

        searchList.Should().NotBeNull();
        bool exists = searchList.Records.Any(x => x.EndsWith(documentId.Path));

        if (!shouldExist && !exists)
        {
            return;
        }
        exists.Should().BeTrue();

        (await client.Delete(documentId)).Should().BeTrue();

        searchList = await client.Search(query).ReadNext();

        searchList.Should().NotBeNull();
        searchList.Records.Any(x => x.EndsWith(documentId.Path)).Should().BeFalse();
    }
Beispiel #2
0
        public async Task GivenFakePackage_WhenFullLifeCycle_ShouldPass()
        {
            TestWebsiteHost host = TestApplication.GetHost();

            const string payload = "This is a test";
            string       id      = "fake1";

            byte[] bytes = Encoding.UTF8.GetBytes(payload);

            ArticlePayload articlePayload = bytes.ToArticlePayload((ArticleId)id);

            await host.ArticleClient.Set(articlePayload);

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

            readPayload.Should().NotBeNull();

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

            string payloadText = Encoding.UTF8.GetString(readPayload !.ToBytes());

            payloadText.Should().Be(payload);

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

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.StartsWith(id)).Should().BeTrue();

            (await host.ArticleClient.Delete((ArticleId)id)).Should().BeTrue();

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

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.StartsWith(id)).Should().BeFalse();
        }
    public async Task GivenNoContract_WhenCreated_ShouldVerify()
    {
        ContractClient client = TestApplication.GetContractClient();

        var documentId = new DocumentId("test/unit-tests-smart/contract1");

        var query = new QueryParameter()
        {
            Filter    = "test/unit-tests-smart",
            Recursive = false,
        };

        IReadOnlyList <string> search = (await client.Search(query).ReadNext()).Records;

        if (search.Any(x => x == (string)documentId))
        {
            await client.Delete(documentId);
        }

        var blkHeader = new BlkHeader
        {
            PrincipalId = "dev/user/[email protected]",
            DocumentId  = (string)documentId,
            Creator     = "test",
            Description = "test description",
        };

        await client.Create(blkHeader);

        BlockChainModel model = await client.Get(documentId);

        model.Should().NotBeNull();
        model.Blocks.Should().NotBeNull();
        model.Blocks.Count.Should().Be(2);

        model.Blocks[0].Should().NotBeNull();
        model.Blocks[0].IsValid().Should().BeTrue();

        model.Blocks[1].Should().NotBeNull();
        model.Blocks[1].IsValid().Should().BeTrue();
        model.Blocks[1].DataBlock.Should().NotBeNull();
        model.Blocks[1].DataBlock.BlockType.Should().Be(typeof(BlkHeader).Name);

        bool isValid = await client.Validate(model);

        isValid.Should().BeTrue();


        BatchSet <string> searchList = await client.Search(query).ReadNext();

        searchList.Should().NotBeNull();
        searchList.Records.Any(x => x.EndsWith(documentId.Path)).Should().BeTrue();

        (await client.Delete(documentId)).Should().BeTrue();

        searchList = await client.Search(query).ReadNext();

        searchList.Should().NotBeNull();
        searchList.Records.Any(x => x.EndsWith(documentId.Path)).Should().BeFalse();
    }
Beispiel #4
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();
        }
        //[Fact]
        public async Task GivenMultiLinkRecord_WhenFullLifeCycle_ShouldComplete()
        {
            TestWebsiteHost host = await TestApplication.DevHost.GetHost();

            await DeleteAllLink(host);

            int half = TestData.RandomNames.Count / 2;
            IReadOnlyList <LinkRecord> records = TestData.RandomNames.Take(half)
                                                 .Zip(TestData.RandomNames.Skip(half), (name, site) => (name, site))
                                                 .Select((x, i) => new LinkRecord
            {
                Id          = $"link_{x.name}",
                RedirectUrl = $"http://{x.site}/Document",
                Owner       = $"l-Owner_{i % 5}",
                Tags        = Enumerable.Range(0, i % 3)
                              .Select(x => new KeyValue($"Key_{x}", $"Value_{x}"))
                              .ToList(),
            })
                                                 .ToArray();

            foreach (var item in records)
            {
                await host.PathFinderClient.Link.Set(item);
            }

            BatchSet <LinkRecord> list = await host.PathFinderClient.Link.List(QueryParameters.Default).ReadNext();

            list.Should().NotBeNull();
            list.Records.Count.Should().Be(half);

            records
            .Zip(list.Records, (o, i) => (o, i))
            .All(x => x.o == x.i)
            .Should().BeTrue();
        }
Beispiel #6
0
        public async Task GivenMultiLinkRecord_WhenFullLifeCycle_ShouldComplete()
        {
            TestWebsiteHost host = await TestApplication.DefaultHost.GetHost();

            const string testPrefix = "test01-";

            await DeleteAll(host, testPrefix);

            const int    max         = 100;
            const string redirectUrl = "http://localhost:5003/Document";

            IReadOnlyList <LinkRecord> records = Enumerable.Range(0, max)
                                                 .Select(x => new LinkRecord
            {
                Id          = $"{testPrefix}lnk_{x}",
                RedirectUrl = redirectUrl,
                Owner       = $"Owner_{x}",
            })
                                                 .ToArray();

            foreach (var item in records)
            {
                await host.PathFinderClient.Link.Set(item);
            }

            BatchSet <LinkRecord> list = await host.PathFinderClient.Link.List(new QueryParameters { Id = testPrefix }).ReadNext();

            list.Should().NotBeNull();
            list.Records.Count.Should().Be(max);

            records
            .Zip(list.Records, (o, i) => (o, i))
            .All(x => x.o == x.i)
            .Should().BeTrue();
        }
Beispiel #7
0
        public async Task GivenMultiLinkRecord_WhenSearchedRedirectUrl_ShouldComplete()
        {
            // Arrange
            TestWebsiteHost host = await TestApplication.SearchHost.GetHost();

            // Act / Assert
            BatchSet <LinkRecord> list = await host.PathFinderClient.Link.List(new QueryParameters { RedirectUrl = "ee" }).ReadNext();

            list.Should().NotBeNull();
            list.Records.Should().NotBeNull();
            list.Records.Count.Should().Be(5);

            // Act / Assert
            list = await host.PathFinderClient.Link.List(new QueryParameters { RedirectUrl = "sa" }).ReadNext();

            list.Should().NotBeNull();
            list.Records.Should().NotBeNull();
            list.Records.Count.Should().Be(3);
        }
Beispiel #8
0
        public async Task GivenRecord_WhenRoundTrip_ShouldMatch()
        {
            ArtifactClient client = TestApplication.GetArtifactClient();

            var        payload    = new Payload("name1", "value1");
            DocumentId documentId = new DocumentId("contract:test/testing/payload.json");

            Document document = new DocumentBuilder()
                                .SetDocumentId(documentId)
                                .SetData(payload)
                                .Build()
                                .Verify();

            await client.Set(document);

            Document?readDocument = await client.Get(documentId);

            readDocument.Should().NotBeNull();
            readDocument !.Verify();

            (document == readDocument).Should().BeTrue();

            Payload?readPayload = readDocument !.DeserializeData <Payload>();

            readPayload.Should().NotBeNull();
            (payload == readPayload).Should().BeTrue();

            var search = new QueryParameter {
                Container = "contract", Filter = "test/testing"
            };

            BatchSet <DatalakePathItem> searchList = await client.Search(search).ReadNext();

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.Name.EndsWith(documentId.Path)).Should().BeTrue();

            (await client.Delete(documentId)).Should().BeTrue();

            searchList = await client.Search(search).ReadNext();

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.Name.EndsWith(documentId.Path)).Should().BeFalse();
        }
Beispiel #9
0
        public async Task GivenMultiLinkRecord_WhenSearchedForId_ShouldComplete()
        {
            // Arrange
            TestWebsiteHost host = await TestApplication.SearchHost.GetHost();

            // Act / Assert
            BatchSet <MetadataRecord> list = await host.PathFinderClient.Metadata.List(new QueryParameters { Id = "Z" }).ReadNext();

            list.Should().NotBeNull();
            list.Records.Should().NotBeNull();
            list.Records.Count.Should().Be(2);

            // Act / Assert
            list = await host.PathFinderClient.Metadata.List(new QueryParameters { Id = "na" }).ReadNext();

            list.Should().NotBeNull();
            list.Records.Should().NotBeNull();
            list.Records.Count.Should().Be(8);
        }
Beispiel #10
0
        public async Task GivenMultiLinkRecord_WhenManuallyPaged_ShouldComplete()
        {
            TestWebsiteHost host = await TestApplication.DefaultHost.GetHost();

            const string testPrefix = "metadata-test02-";

            await DeleteAll(host, testPrefix);

            const int max      = 100;
            const int pageSize = 10;

            IReadOnlyList <MetadataRecord> records = Enumerable.Range(0, max)
                                                     .Select(x => new MetadataRecord
            {
                Id         = $"{testPrefix}meta_{x}",
                Properties = new[]
                {
                    new KeyValue("key1", "value1"),
                    new KeyValue("key2", "value2"),
                },
            })
                                                     .ToArray();

            foreach (var item in records)
            {
                await host.PathFinderClient.Metadata.Set(item);
            }

            var aggList = new List <MetadataRecord>();

            int index = 0;

            while (aggList.Count < max)
            {
                BatchSet <MetadataRecord> list = await host.PathFinderClient.Metadata.List(new QueryParameters { Id = testPrefix, Index = index, Count = pageSize }).ReadNext();

                list.Should().NotBeNull();
                list.Records.Count.Should().Be(pageSize);

                index += list.Records.Count;
                aggList.AddRange(list.Records);
            }

            aggList.Count.Should().Be(max);

            records
            .Zip(aggList, (o, i) => (o, i))
            .All(x => x.o == x.i)
            .Should().BeTrue();

            BatchSet <MetadataRecord> finalList = await host.PathFinderClient.Metadata.List(new QueryParameters { Id = testPrefix, Index = index, Count = pageSize }).ReadNext();

            finalList.Should().NotBeNull();
            finalList.Records.Count.Should().Be(0);
        }
Beispiel #11
0
        public async Task GivenData_WhenRoundTrip_ShouldMatch(string id)
        {
            ArtifactClient client = TestApplication.GetArtifactClient();

            const string payload    = "This is a test";
            DocumentId   documentId = new DocumentId(id);

            Document document = new DocumentBuilder()
                                .SetDocumentId(documentId)
                                .SetData(payload)
                                .Build()
                                .Verify();

            await client.Set(document);

            Document?readPayload = await client.Get(documentId);

            readPayload.Should().NotBeNull();
            readPayload !.Verify();

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

            string?payloadText = readPayload !.DeserializeData <string>();

            payloadText.Should().Be(payload);

            var search = new QueryParameter {
                Container = "contract", Recursive = true
            };

            BatchSet <DatalakePathItem> searchList = await client.Search(search).ReadNext();

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.Name.EndsWith(documentId.Path)).Should().BeTrue();

            (await client.Delete(documentId)).Should().BeTrue();

            searchList = await client.Search(search).ReadNext();

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.Name.EndsWith(documentId.Path)).Should().BeFalse();
        }
Beispiel #12
0
        public async Task GivenMultiLinkRecord_WhenManuallyPaged_ShouldComplete()
        {
            TestWebsiteHost host = await TestApplication.DefaultHost.GetHost();

            const string testPrefix = "test02-";

            await DeleteAll(host, testPrefix);

            const int    max         = 100;
            const int    pageSize    = 10;
            const string redirectUrl = "http://localhost:5003/Document";

            IReadOnlyList <LinkRecord> records = Enumerable.Range(0, max)
                                                 .Select(x => new LinkRecord
            {
                Id          = $"{testPrefix}lnk_{x}",
                RedirectUrl = redirectUrl
            })
                                                 .ToArray();

            foreach (var item in records)
            {
                await host.PathFinderClient.Link.Set(item);
            }

            var aggList = new List <LinkRecord>();

            int index = 0;

            while (aggList.Count < max)
            {
                BatchSet <LinkRecord> list = await host.PathFinderClient.Link.List(new QueryParameters { Id = testPrefix, Index = index, Count = pageSize }).ReadNext();

                list.Should().NotBeNull();
                list.Records.Count.Should().Be(pageSize);

                index += list.Records.Count;
                aggList.AddRange(list.Records);
            }

            aggList.Count.Should().Be(max);

            records
            .Zip(aggList, (o, i) => (o, i))
            .All(x => x.o == x.i)
            .Should().BeTrue();

            BatchSet <LinkRecord> finalList = await host.PathFinderClient.Link.List(new QueryParameters { Id = testPrefix, Index = index, Count = pageSize }).ReadNext();

            finalList.Should().NotBeNull();
            finalList.Records.Count.Should().Be(0);
        }
Beispiel #13
0
        public async Task GivenData_WhenRoundTrip_ShouldMatch(string id)
        {
            TestWebsiteHost host = TestApplication.GetHost();

            const string payload    = "This is a test";
            ArtifactId   artifactId = new ArtifactId(id);

            byte[] bytes = Encoding.UTF8.GetBytes(payload);

            ArtifactPayload articlePayload = bytes.ToArtifactPayload(artifactId);

            await host.ArtifactClient.Set(articlePayload);

            ArtifactPayload?readPayload = await host.ArtifactClient.Get(artifactId);

            readPayload.Should().NotBeNull();

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

            string payloadText = Encoding.UTF8.GetString(readPayload !.ToBytes());

            payloadText.Should().Be(payload);

            var search = new QueryParameter {
                Namespace = artifactId.Namespace
            };

            BatchSet <string> searchList = await host.ArtifactClient.List(search).ReadNext();

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.StartsWith(artifactId.Path)).Should().BeTrue();

            (await host.ArtifactClient.Delete(artifactId)).Should().BeTrue();

            searchList = await host.ArtifactClient.List(search).ReadNext();

            searchList.Should().NotBeNull();
            searchList.Records.Any(x => x.StartsWith(artifactId.Path)).Should().BeFalse();
        }
Beispiel #14
0
        public async Task GivenMultiLinkRecord_WhenSearchedBothIdAndRedirectUrlAndOwner_ShouldComplete()
        {
            // Arrange
            TestWebsiteHost host = await TestApplication.SearchHost.GetHost();

            // Act
            BatchSet <MetadataRecord> list = await host.PathFinderClient.Metadata.List(new QueryParameters { Id = "sa", Owner = "3" }).ReadNext();

            // Assert
            list.Should().NotBeNull();
            list.Records.Should().NotBeNull();
            list.Records.Count.Should().Be(14);
        }
Beispiel #15
0
        public async Task GivenMultiLinkRecord_WhenSearchedAllFields_ShouldComplete()
        {
            // Arrange
            TestWebsiteHost host = await TestApplication.SearchHost.GetHost();

            // Act
            BatchSet <LinkRecord> list = await host.PathFinderClient.Link.List(new QueryParameters { Id = "Z", RedirectUrl = "sa", Owner = "3", Tag = "2" }).ReadNext();

            // Assert
            list.Should().NotBeNull();
            list.Records.Should().NotBeNull();
            list.Records.Count.Should().Be(13);
        }
Beispiel #16
0
        public async Task GivenMultiMetadataRecord_WhenFullLifeCycle_ShouldComplete()
        {
            TestWebsiteHost host = await TestApplication.DefaultHost.GetHost();

            const string testPrefix = "metadata-test01-";

            await DeleteAll(host, testPrefix);

            const int max = 100;

            IReadOnlyList <MetadataRecord> records = Enumerable.Range(0, max)
                                                     .Select(x => new MetadataRecord
            {
                Id         = $"{testPrefix}meta{x}",
                Properties = new[]
                {
                    new KeyValue("key1", "value1"),
                    new KeyValue("key2", "value2"),
                },
            })
                                                     .ToArray();

            foreach (var item in records)
            {
                await host.PathFinderClient.Metadata.Set(item);
            }

            BatchSet <MetadataRecord> list = await host.PathFinderClient.Metadata.List(new QueryParameters { Id = testPrefix }).ReadNext();

            list.Should().NotBeNull();
            list.Records.Count.Should().Be(max);

            records
            .Zip(list.Records, (o, i) => (o, i))
            .All(x => x.o == x.i)
            .Should().BeTrue();
        }
    public async Task GivenAccount_WhenRoundTrip_ShouldSucceed()
    {
        BankAccountClient client = TestApplication.GetBankAccountClient();

        DocumentId documentId = (DocumentId)"test/bank/bankAccount1";

        await client.Delete(documentId);

        BankAccount entry = new BankAccount
        {
            AccountId     = documentId.Path,
            AccountName   = "testBankAccount",
            AccountNumber = Guid.NewGuid().ToString(),
        };

        await client.Set(entry);

        BankAccount?account = await client.Get(documentId);

        account.Should().NotBeNull();
        account !.AccountId.Should().Be(entry.AccountId);
        account.AccountName.Should().Be(entry.AccountName);
        account.AccountNumber.Should().Be(entry.AccountNumber);
        account.Transactions.Count.Should().Be(0);

        account = account with
        {
            AccountName  = "newBankAccount",
            Transactions = new[]
            {
                new TrxRecord {
                    Type = TrxType.Credit, Amount = 100.0m
                },
                new TrxRecord {
                    Type = TrxType.Debit, Amount = 41.0m
                },
            }.ToList()
        };

        await client.Set(account);

        BankAccount?account1 = await client.Get(documentId);

        account1.Should().NotBeNull();
        account1 !.AccountId.Should().Be(account.AccountId);
        account1.AccountName.Should().Be(account.AccountName);
        account1.AccountNumber.Should().Be(account.AccountNumber);
        account1.Transactions.Count.Should().Be(2);
        (account1.Transactions[0] == account.Transactions[0]).Should().BeTrue();
        (account1.Transactions[1] == account.Transactions[1]).Should().BeTrue();

        var query = new QueryParameter
        {
            Filter = "test/bank"
        };

        BatchSetCursor <DatalakePathItem> cursor = client.Search(query);

        cursor.Should().NotBeNull();

        BatchSet <DatalakePathItem> batchSet = await cursor.ReadNext();

        batchSet.Should().NotBeNull();
        batchSet.Records.Any(x => x.Name.EndsWith(documentId.Path)).Should().BeTrue();

        await client.Delete(documentId);
    }
}