Exemplo n.º 1
0
        public async Task GivenAnAssetHasBeenCreated_WhenWeSearchViaSchemeIdThatHasBeenSet_ThenWeCanFindTheSameAssetAnd(int schemeId, int schemeId2, int schemeId3)
        {
            //arrange
            using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var createdAsset  = CreateAsset(schemeId, null);
                var createdAsset2 = CreateAsset(schemeId2, null);
                var createdAsset3 = CreateAsset(schemeId3, null);

                var assetRegisterVersion = await CreateAggregatedAssets(new List <IAsset> {
                    createdAsset, createdAsset2, createdAsset3
                })
                                           .ConfigureAwait(false);

                var assetSearch = new AssetPagedSearchQuery
                {
                    SchemeId = schemeId2,
                    AssetRegisterVersionId = assetRegisterVersion.Id
                };
                //act
                var assets = await _classUnderTest.Search(assetSearch, CancellationToken.None).ConfigureAwait(false);

                //assert
                assets.Results.Count.Should().Be(1);
                assets.Results.ElementAtOrDefault(0).AssetIsEqual(assetRegisterVersion.Assets[1].Id, assetRegisterVersion.Assets[1]);
                trans.Dispose();
            }
        }
Exemplo n.º 2
0
        public async Task GivenAnAssetHasBeenCreatedWithTheSameDeveloper_WhenWeSearch_ThenWeCanFindIt(string developer, string searchDeveloper)
        {
            //arrange
            using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var random               = new Random();
                var randomInt            = random.Next();
                var createdAsset         = CreateAssetWithDeveloper(randomInt, developer);
                var createdAsset2        = CreateAssetWithDeveloper(randomInt, $"Random : {randomInt}");
                var assetRegisterVersion = await CreateAggregatedAssets(new List <IAsset> {
                    createdAsset, createdAsset2
                })
                                           .ConfigureAwait(false);

                //act
                var assetSearch = new AssetPagedSearchQuery
                {
                    Developer = searchDeveloper,
                    AssetRegisterVersionId = assetRegisterVersion.Id
                };
                //act
                var assets = await _classUnderTest.Search(assetSearch, CancellationToken.None).ConfigureAwait(false);

                //assert
                assets.Results.Count.Should().Be(1);

                trans.Dispose();
            }
        }
Exemplo n.º 3
0
        public async Task GivenMultipleAssetsHaveBeenCreated_WhenWeSearchDeveloperWithPageSize_ReturnCorrectNumberOfPages(string developer, int pageSize, int numberOfAssets, int expectedNumberOfPages)
        {
            using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var assets = new List <IAsset>();
                for (var i = 0; i < numberOfAssets; i++)
                {
                    var entity = CreateAssetWithDeveloper(null, developer);
                    assets.Add(entity);
                }

                var assetRegisterVersion = await CreateAggregatedAssets(assets)
                                           .ConfigureAwait(false);

                var assetQuery = new AssetPagedSearchQuery
                {
                    Developer = developer,
                    PageSize  = pageSize,
                    AssetRegisterVersionId = assetRegisterVersion.Id
                };

                var response = await _classUnderTest.Search(assetQuery, CancellationToken.None);

                response.NumberOfPages.Should().Be(expectedNumberOfPages);

                trans.Dispose();
            }
        }
Exemplo n.º 4
0
        public async Task GivenMultiplesAssetsHaveBeenCreatedWithTheSameDeveloper_WhenWeSearch_ThenTheAssetsAreOrderedBySchemeIdDesc(string developer, string searchDeveloper)
        {
            //arrange
            using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var random               = new Random();
                var randomInt            = random.Next();
                var createdAsset         = CreateAssetWithDeveloper(randomInt, developer);
                var createdAsset2        = CreateAssetWithDeveloper(randomInt + 1, developer);
                var createdAsset3        = CreateAssetWithDeveloper(randomInt + 2, $"Random {randomInt + 2}");
                var assetRegisterVersion = await CreateAggregatedAssets(new List <IAsset> {
                    createdAsset, createdAsset2, createdAsset3
                })
                                           .ConfigureAwait(false);

                //act
                var assetSearch = new AssetPagedSearchQuery
                {
                    Developer = searchDeveloper,
                    AssetRegisterVersionId = assetRegisterVersion.Id
                };
                //act
                var assets = await _classUnderTest.Search(assetSearch, CancellationToken.None).ConfigureAwait(false);

                //assert
                Assert.Greater(assets.Results.ElementAt(0).SchemeId, assets.Results.ElementAt(1).SchemeId);

                trans.Dispose();
            }
        }
Exemplo n.º 5
0
        public async Task GivenMultipleAssetsHaveBeenCreated_WhenWeSearchWithPageSize_ReturnCorrectNumberOfAssetsPerPage(string address, int pageSize, int page, int numberOfAssets, int expectedNumberOfAssets)
        {
            using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var assets = new List <IAsset>();
                for (var i = 0; i < numberOfAssets; i++)
                {
                    var entity = TestData.Domain.GenerateAsset();
                    entity.Address = address;
                    assets.Add(entity);
                }

                var assetRegisterVersion = await CreateAggregatedAssets(assets)
                                           .ConfigureAwait(false);

                var assetQuery = new AssetPagedSearchQuery
                {
                    Address  = address,
                    PageSize = pageSize,
                    Page     = page,
                    AssetRegisterVersionId = assetRegisterVersion.Id
                };

                var response = await _classUnderTest.Search(assetQuery, CancellationToken.None);

                response.Results.Count.Should().Be(expectedNumberOfAssets);

                trans.Dispose();
            }
        }
Exemplo n.º 6
0
        public async Task GivenMultiplesAssetsHaveBeenCreatedWithASimilarAddress_WhenWeSearch_ThenWeCanFindMultipleAssets(int?schemeId, string address, string searchAddress)
        {
            //arrange
            using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var createdAsset         = CreateAsset(schemeId, address);
                var createdAsset2        = CreateAsset(schemeId, address);
                var assetRegisterVersion = await CreateAggregatedAssets(new List <IAsset> {
                    createdAsset, createdAsset2
                })
                                           .ConfigureAwait(false);

                //act
                var assetSearch = new AssetPagedSearchQuery
                {
                    SchemeId = schemeId,
                    Address  = searchAddress,
                    AssetRegisterVersionId = assetRegisterVersion.Id
                };
                //act
                var assets = await _classUnderTest.Search(assetSearch, CancellationToken.None).ConfigureAwait(false);

                //assert
                assets.Results.Count.Should().Be(2);

                trans.Dispose();
            }
        }
Exemplo n.º 7
0
        public async Task GivenAnAssetHasBeenCreated_WhenWeSearch_ThenWeCanFindTheSameAsset(int?schemeId, string address, string searchAddress)
        {
            //arrange
            using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var createdAsset         = CreateAsset(schemeId, address);
                var assetRegisterVersion = await CreateAggregatedAssets(new List <IAsset> {
                    createdAsset
                })
                                           .ConfigureAwait(false);

                //act
                var assetSearch = new AssetPagedSearchQuery
                {
                    SchemeId = schemeId,
                    Address  = searchAddress,
                    AssetRegisterVersionId = assetRegisterVersion.Id
                };
                //act
                var assets = await _classUnderTest.Search(assetSearch, CancellationToken.None).ConfigureAwait(false);

                //assert
                assets.Results.ElementAtOrDefault(0).AssetIsEqual(assetRegisterVersion.Assets[0].Id, assetRegisterVersion.Assets[0]);

                trans.Dispose();
            }
        }
Exemplo n.º 8
0
        public async Task GivenAnAssetHasBeenCreated_WhenWeSearchViaFieldsThatHaventBeenSet_ThenWeGetNullOrEmptyArray(int?schemeId, string searchAddress)
        {
            //arrange
            using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var createdAsset = CreateAsset(null, null);

                var assetRegisterVersion = await CreateAggregatedAssets(new List <IAsset> {
                    createdAsset
                })
                                           .ConfigureAwait(false);

                //act
                var assetSearch = new AssetPagedSearchQuery
                {
                    SchemeId = schemeId,
                    Address  = searchAddress,
                    AssetRegisterVersionId = assetRegisterVersion.Id
                };
                //act
                var assets = await _classUnderTest.Search(assetSearch, CancellationToken.None).ConfigureAwait(false);

                //assert
                assets.Results.Should().BeNullOrEmpty();

                trans.Dispose();
            }
        }
Exemplo n.º 9
0
        public async Task GivenAnAssetHasBeenCreated_WhenWeSearchViaSchemeIdThatHasntBeenSet_ThenWeCantFindTheSameAsset(int schemeId)
        {
            //arrange
            using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var entity = TestData.Domain.GenerateAsset();

                var assetRegisterVersion = await CreateAggregatedAssets(new List <IAsset> {
                    entity
                })
                                           .ConfigureAwait(false);

                var assetSearch = new AssetPagedSearchQuery
                {
                    SchemeId = schemeId,
                    AssetRegisterVersionId = assetRegisterVersion.Id
                };
                //act
                var assets = await _classUnderTest.Search(assetSearch, CancellationToken.None).ConfigureAwait(false);

                //assert
                assets.Results.Should().BeNullOrEmpty();
                trans.Dispose();
            }
        }
Exemplo n.º 10
0
        private async Task <IPagedResults <IAsset> > SearchAssets(SearchAssetRequest request, CancellationToken cancellationToken)
        {
            var assetSearch = new AssetPagedSearchQuery
            {
                SchemeId = request.SchemeId,
                Address  = request.Address,
                Region   = request.Region,
                AssetRegisterVersionId = request.AssetRegisterVersionId,
                Developer = request.Developer,
            };

            if (request.Page != null)
            {
                assetSearch.Page = request.Page;
            }
            if (request.PageSize != null)
            {
                assetSearch.PageSize = request.PageSize;
            }

            var foundAssets = await _assetSearcher.Search(assetSearch, cancellationToken).ConfigureAwait(false);

            if (foundAssets == null)
            {
                foundAssets = new PagedResults <IAsset>
                {
                    Results       = new List <IAsset>(),
                    NumberOfPages = 0,
                    TotalCount    = 0
                }
            }
            ;

            return(foundAssets);
        }
    }