Example #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));
        }
Example #2
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));
        }
        public async Task <JsonResult> Get([FromQuery] string postcode)
        {
            try
            {
                if (_postcodeValidator.Validate(postcode))
                {
                    PropertyActions actions = new PropertyActions(_propertyService, _propertyServiceRequestBuilder, _loggerAdapter);
                    var             json    = Json(await actions.FindProperty(postcode));
                    json.StatusCode  = 200;
                    json.ContentType = "application/json";
                    return(json);
                }
                else
                {
                    var errors = new List <ApiErrorMessage>
                    {
                        new ApiErrorMessage
                        {
                            developerMessage = "Invalid parameter - postcode",
                            userMessage      = "Please provide a valid post code"
                        }
                    };
                    var json = Json(errors);
                    json.StatusCode = 400;
                    return(json);
                }
            }

            catch (Exception e)
            {
                var errors = new List <ApiErrorMessage>
                {
                    new ApiErrorMessage
                    {
                        developerMessage = e.Message,
                        userMessage      = "We had some problems processing your request"
                    }
                };
                var json = Json(errors);
                json.StatusCode = 500;
                return(json);
            }
        }
Example #4
0
        public async Task Logs_information_When_Calling_PropertyActions_FindProperty()
        {
            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 mockLogger = new Mock <ILoggerAdapter <PropertyActions> >();

            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 1DT")).Returns(new ListByPostCodeRequest());
            PropertyActions propertyActions = new PropertyActions(fakeService.Object, fakeRequestBuilder.Object, mockLogger.Object);

            var result = await propertyActions.FindProperty("E8 1DT");

            mockLogger.Verify(l => l.LogInformation(It.IsAny <string>()));
        }
Example #5
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"));
        }