Exemplo n.º 1
0
        public async Task find_properties_returns_an_empty_response_when_no_matches()
        {
            var mockLogger = new Mock <ILoggerAdapter <PropertyActions> >();
            var request    = new ListByPostCodeRequest();
            var response   = new PropertyInfoResponse()
            {
                PropertyList = new PropertySummary[0],
                Success      = true
            };
            var fakeService = new Mock <IHackneyPropertyService>();

            fakeService.Setup(service => service.GetPropertyListByPostCodeAsync(It.IsAny <ListByPostCodeRequest>()))
            .ReturnsAsync(response);

            var fakeRequestBuilder = new Mock <IHackneyPropertyServiceRequestBuilder>();

            fakeRequestBuilder.Setup(service => service.BuildListByPostCodeRequest("E8 2LN")).Returns(request);
            PropertyActions propertyActions = new PropertyActions(fakeService.Object, fakeRequestBuilder.Object, mockLogger.Object);
            var             results         = await propertyActions.FindProperty("E8 2LN");

            var properties = new object[0];
            var json       = new { results = properties };

            Assert.Equal(JsonConvert.SerializeObject(json), JsonConvert.SerializeObject(results));
        }
Exemplo n.º 2
0
        public Task <PropertyInfoResponse> GetPropertyListByPostCodeAsync(ListByPostCodeRequest request)
        {
            _logger.LogInformation($"HackneyPropertyService/GetPropertyListByPostCodeAsync(): Sent request to upstream PropertyServiceClient (Postcode: {request.PostCode})");
            var response = _client.GetPropertyListByPostCodeAsync(request);

            _logger.LogInformation($"HackneyPropertyService/GetPropertyListByPostCodeAsync(): Received response from upstream PropertyServiceClient (Postcode: {request.PostCode})");
            return(response);
        }
Exemplo n.º 3
0
        public async Task find_properties_returns_a_list_of_properties()
        {
            var mockLogger = new Mock <ILoggerAdapter <PropertyActions> >();
            var request    = new ListByPostCodeRequest();

            var response = new PropertyInfoResponse()
            {
                PropertyList = new PropertySummary[2],
                Success      = true
            };
            var property1 = new PropertySummary()
            {
                ShortAddress      = "Front Office, Robert House, 6 - 15 Florfield Road",
                PostCodeValue     = "E8 1DT",
                PropertyReference = "1/43453543"
            };
            var property2 = new PropertySummary()
            {
                ShortAddress      = "Maurice Bishop House, 17 Reading Lane",
                PostCodeValue     = "E8 1DT",
                PropertyReference = "2/32453245"
            };

            response.PropertyList[0] = property1;
            response.PropertyList[1] = property2;
            var fakeService = new Mock <IHackneyPropertyService>();

            fakeService.Setup(service => service.GetPropertyListByPostCodeAsync(request))
            .ReturnsAsync(response);

            var fakeRequestBuilder = new Mock <IHackneyPropertyServiceRequestBuilder>();

            fakeRequestBuilder.Setup(service => service.BuildListByPostCodeRequest("E8 1DT")).Returns(request);
            PropertyActions propertyActions = new PropertyActions(fakeService.Object, fakeRequestBuilder.Object, mockLogger.Object);
            var             results         = await propertyActions.FindProperty("E8 1DT");

            var outputproperty1 = new {
                address           = "Front Office, Robert House, 6 - 15 Florfield Road",
                postcode          = "E8 1DT",
                propertyReference = "1/43453543"
            };
            var outputproperty2 = new
            {
                address           = "Maurice Bishop House, 17 Reading Lane",
                postcode          = "E8 1DT",
                propertyReference = "2/32453245"
            };
            var properties = new object[2];

            properties[0] = outputproperty1;
            properties[1] = outputproperty2;
            var json = new { results = properties };

            Assert.Equal(JsonConvert.SerializeObject(json), JsonConvert.SerializeObject(results));
        }
Exemplo n.º 4
0
        public async Task find_properties_raises_an_exception_if_the_property_list_is_missing()
        {
            var mockLogger = new Mock <ILoggerAdapter <PropertyActions> >();
            var request    = new ListByPostCodeRequest();
            var response   = new PropertyInfoResponse {
                Success = true
            };
            var fakeService = new Mock <IHackneyPropertyService>();

            fakeService.Setup(service => service.GetPropertyListByPostCodeAsync(It.IsAny <ListByPostCodeRequest>()))
            .ReturnsAsync(response);

            var fakeRequestBuilder = new Mock <IHackneyPropertyServiceRequestBuilder>();

            fakeRequestBuilder.Setup(service => service.BuildListByPostCodeRequest("E8 2LN")).Returns(request);
            PropertyActions propertyActions = new PropertyActions(fakeService.Object, fakeRequestBuilder.Object, mockLogger.Object);
            await Assert.ThrowsAsync <HackneyRepairs.Actions.MissingPropertyListException>(async() => await propertyActions.FindProperty("E8 2LN"));
        }
Exemplo n.º 5
0
        public Task <PropertyInfoResponse> GetPropertyListByPostCodeAsync(ListByPostCodeRequest request)
        {
            var response = new PropertyInfoResponse()
            {
                PropertyList = new PropertySummary[2],
                Success      = true
            };
            var property1 = new PropertySummary()
            {
                ShortAddress      = "Back Office, Robert House, 6 - 15 Florfield Road",
                PostCodeValue     = "E8 1DT",
                PropertyReference = "1/525252525"
            };
            var property2 = new PropertySummary()
            {
                ShortAddress      = "Meeting room, Maurice Bishop House, 17 Reading Lane",
                PostCodeValue     = "E8 1DT",
                PropertyReference = "6/32453245   "
            };

            response.PropertyList[0] = property1;
            response.PropertyList[1] = property2;
            switch (request.PostCode)
            {
            case "E8 1DT":
                return(Task.Run(() => response));

            case "E8 2LT":
                return(Task.Run(() => new PropertyInfoResponse
                {
                    Success = false,
                    ErrorCode = 9903,
                    ErrorMessage = "Master Password is Invalid.",
                    PropertyList = null
                }));

            default:
                return(Task.Run(() => new PropertyInfoResponse
                {
                    PropertyList = new PropertySummary[0],
                    Success = true
                }));
            }
        }