예제 #1
0
        public async Task get_property_details_by_reference()
        {
            var mockLogger = new Mock <ILoggerAdapter <PropertyActions> >();
            var request    = new ByPropertyRefRequest();
            var response   = new PropertyGetResponse()
            {
                Success  = true,
                Property = new PropertyDto()
                {
                    ShortAddress  = "Front Office, Robert House, 6 - 15 Florfield Road",
                    PostCodeValue = "E8 1DT",
                    Reference     = "43453543"
                }
            };

            var fakeService = new Mock <IHackneyPropertyService>();

            fakeService.Setup(service => service.GetPropertyByRefAsync(request))
            .ReturnsAsync(response);
            var fakeRequestBuilder = new Mock <IHackneyPropertyServiceRequestBuilder>();

            fakeRequestBuilder.Setup(service => service.BuildByPropertyRefRequest("43453543")).Returns(request);
            PropertyActions propertyActions = new PropertyActions(fakeService.Object, fakeRequestBuilder.Object, mockLogger.Object);
            var             results         = await propertyActions.FindPropertyDetailsByRef("43453543");

            var property = new
            {
                address           = "Front Office, Robert House, 6 - 15 Florfield Road",
                postcode          = "E8 1DT",
                propertyReference = "43453543",
                maintainable      = false
            };

            Assert.Equal(property, results);
        }
 public async Task <JsonResult> GetByReference(string reference)
 {
     try
     {
         PropertyActions actions = new PropertyActions(_propertyService, _propertyServiceRequestBuilder, _loggerAdapter);
         var             json    = Json(await actions.FindPropertyDetailsByRef(reference));
         json.StatusCode  = 200;
         json.ContentType = "application/json";
         return(json);
     }
     catch (MissingPropertyException ex)
     {
         var errors = new List <ApiErrorMessage>()
         {
             new ApiErrorMessage
             {
                 developerMessage = ex.Message,
                 userMessage      = "Resource identification error"
             }
         };
         var jsonResponse = Json(errors);
         jsonResponse.StatusCode = 404;
         return(jsonResponse);
     }
     catch (Exception e)
     {
         var errors = new List <ApiErrorMessage>()
         {
             new ApiErrorMessage
             {
                 developerMessage = e.Message,
                 userMessage      = "Internal Error"
             }
         };
         var jsonResponse = Json(errors);
         jsonResponse.StatusCode = 500;
         return(jsonResponse);
     }
 }
예제 #3
0
        public async Task get_property_details_by_reference_raises_an_exception_if_the_service_responds_with_an_error()
        {
            var mockLogger = new Mock <ILoggerAdapter <PropertyActions> >();
            var request    = new ByPropertyRefRequest();
            var response   = new PropertyGetResponse {
                Success = false, Property = new PropertyDto()
            };
            var fakeService = new Mock <IHackneyPropertyService>();

            fakeService.Setup(service => service.GetPropertyByRefAsync(It.IsAny <ByPropertyRefRequest>()))
            .ReturnsAsync(response);

            var fakeRequestBuilder = new Mock <IHackneyPropertyServiceRequestBuilder>();

            fakeRequestBuilder.Setup(service => service.BuildByPropertyRefRequest("525252525")).Returns(request);
            PropertyActions propertyActions = new PropertyActions(fakeService.Object, fakeRequestBuilder.Object, mockLogger.Object);
            await Assert.ThrowsAsync <HackneyRepairs.Actions.PropertyServiceException>(async() => await propertyActions.FindPropertyDetailsByRef("525252525"));
        }