Exemplo n.º 1
0
        /// <summary>
        /// Execute the Search Tenancy Use Case
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <SearchTenancyResponse> ExecuteAsync(SearchTenancyRequest request, CancellationToken cancellationToken)
        {
            //validate
            if (request == null)
            {
                //
                throw new BadRequestException();
            }
            //validate
            var validationResponse = request.Validate(request);

            if (!validationResponse.IsValid)
            {
                throw new BadRequestException(validationResponse);
            }

            //Execute Gateway - which will determine how to get the data we requested
            var response = await _searchGateway.SearchTenanciesAsync(request, cancellationToken).ConfigureAwait(false);

            //tenancy could have no attached contacts
            if (response == null)
            {
                return(new SearchTenancyResponse());
            }

            //Create real response and map to response object
            var useCaseResponse = new SearchTenancyResponse
            {
                Tenancies = response.Results.ConvertAll(tenancy => new SearchTenancySummary
                {
                    TenancyRef     = tenancy.TenancyRef,
                    PropertyRef    = tenancy.PropertyRef,
                    Tenure         = tenancy.Tenure,
                    CurrentBalance = new Currency
                    {
                        Value        = tenancy.CurrentBalance,
                        CurrencyCode = "GBP",
                    },
                    PrimaryContact = new PrimaryContact
                    {
                        Name         = tenancy.PrimaryContactName,
                        ShortAddress = tenancy.PrimaryContactShortAddress,
                        Postcode     = tenancy.PrimaryContactPostcode
                    }
                }),
                TotalCount = response.TotalResultsCount,
                PageCount  = response.CalculatePageCount(request.PageSize, response.TotalResultsCount)
            };

            return(useCaseResponse);
        }
Exemplo n.º 2
0
        public async Task search_returns_null_when_null_is_passed_in(string tenancyRef, string tenancyRef2)
        {
            //arrange
            //property
            var expectedProperty = Fake.UniversalHousing.GenerateFakeProperty();

            TestDataHelper.InsertProperty(expectedProperty, _db);
            //tenancy
            var expectedTenancy = Fake.UniversalHousing.GenerateFakeTenancy();

            expectedTenancy.house_ref = expectedTenancy.house_ref;
            expectedTenancy.prop_ref  = expectedProperty.prop_ref;
            expectedTenancy.tag_ref   = tenancyRef;
            TestDataHelper.InsertTenancy(expectedTenancy, _db);
            //tenancy
            var expectedTenancy2 = Fake.UniversalHousing.GenerateFakeTenancy();

            expectedTenancy2.house_ref = expectedTenancy.house_ref;
            expectedTenancy2.prop_ref  = expectedProperty.prop_ref;
            expectedTenancy2.tag_ref   = tenancyRef2;
            TestDataHelper.InsertTenancy(expectedTenancy2, _db);
            //member
            var expectedMember = Fake.UniversalHousing.GenerateFakeMember();

            expectedMember.house_ref = expectedTenancy.house_ref;
            TestDataHelper.InsertMember(expectedMember, _db);

            //act
            var response = await _classUnderTest.SearchTenanciesAsync(new SearchTenancyRequest
            {
                SearchTerm = null,
                PageSize   = 10,
                Page       = 1
            }, CancellationToken.None);

            //assert
            response.Should().NotBeNull();
            response.Results.Should().BeNullOrEmpty();
        }