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