public void GivenARequestContainingAListOfPropRefs_WhenIExecuteTheUseCase_ThenIGetAResponseObjectContainingListOfPropertiesBack(string propertyReference, string propertyReference2)
        {
            //arrange
            var propertyReferences = new List <string> {
                propertyReference, propertyReference2
            };
            var request = new GetMultiplePropertiesUseCaseRequest(propertyReferences);

            var listOfProperties = new List <Property> {
                new Property {
                    PropRef = propertyReference
                }, new Property {
                    PropRef = propertyReference2
                }
            };

            _mockGetMultiplePropertiesGateway
            .Setup(g => g.GetMultiplePropertiesByPropertyListOfReferences(It.Is <List <string> >(arg => arg[0] == propertyReferences[0] && arg[1] == propertyReferences[1])))
            .Returns(listOfProperties);

            //act
            GetMultiplePropertiesUseCaseResponse response = _classUnderTest.Execute(request);

            //assert
            response.Should().NotBeNull();
            response.Should().BeOfType <GetMultiplePropertiesUseCaseResponse>();

            response.Properties.Should().NotBeNull();
            response.Properties.Should().BeOfType <List <Property> >();

            Assert.AreSame(propertyReferences[0], response.Properties[0].PropRef);
            Assert.AreSame(propertyReferences[1], response.Properties[1].PropRef);
        }
Ejemplo n.º 2
0
        public void GivenTooMannyPropRefs_ItShouldReturnBadInput()
        {
            //arrange
            List <string> propertyReferences = new List <string>();

            foreach (var i in Enumerable.Range(0, 201))
            {
                propertyReferences.Add(i.ToString());
            }

            var getMultiplePropertiesUseCaseRequest = new GetMultiplePropertiesUseCaseRequest(propertyReferences);
            //act
            var actionResult = _classUnderTest.GetMultipleByReference(getMultiplePropertiesUseCaseRequest);

            //assert
            actionResult.Should().BeOfType <BadRequestObjectResult>();

            Assert.AreEqual(400, ((BadRequestObjectResult)actionResult).StatusCode);

            var json = JsonConvert.SerializeObject(((BadRequestObjectResult)actionResult).Value);

            Assert.AreEqual(JsonConvert.SerializeObject(new Dictionary <string, object>
            {
                { "validRequest", false },
                { "errors", new [] {
                      "The number of 'PropertyReferences' given must be more than 0 and less than 200. (201 given)"
                  } },
                { "properties", new List <string>() }
            }), json);
        }
Ejemplo n.º 3
0
        public GetMultiplePropertiesUseCaseResponse Execute(GetMultiplePropertiesUseCaseRequest request)
        {
            IList <string> propertyReferences = request.PropertyReferences;

            List <Property> properties = _getMultiplePropertiesGateway.GetMultiplePropertiesByPropertyListOfReferences(propertyReferences);

            return(new GetMultiplePropertiesUseCaseResponse(properties));
        }
Ejemplo n.º 4
0
        public void GivenANullList_TheValidatorShouldReturnFalse()
        {
            //arrange
            var propertiesUseCaseRequest = new GetMultiplePropertiesUseCaseRequest(null);

            //act
            bool validationResult = _classUnderTest.Validate(propertiesUseCaseRequest).IsValid;

            //assert
            Assert.False(validationResult);
        }
Ejemplo n.º 5
0
        public void GivenAListOfMultipleProperties_WhenIExecute_ThenParametersArePassedIntoTheUseCase(string propertyReference, string propertyReference2)
        {
            //arrange
            var propertyReferences = new GetMultiplePropertiesUseCaseRequest(new List <string> {
                propertyReference, propertyReference2
            });

            //act
            _classUnderTest.GetMultipleByReference(propertyReferences);
            //assert
            _mockGetMultiplePropertiesUseCase.Verify(v => v.Execute(It.Is <GetMultiplePropertiesUseCaseRequest>(i => i.PropertyReferences[0] == propertyReference && i.PropertyReferences[1] == propertyReference2)), Times.Once);
        }
Ejemplo n.º 6
0
        public void GivenAnInvalidListofPropertyRefs_TheValidatorShouldReturnFalse(string propertyReference, string propertyReference2)
        {
            //arrange
            var propertiesUseCaseRequest = new GetMultiplePropertiesUseCaseRequest(new List <string> {
                propertyReference, propertyReference2
            });
            //act
            bool validationResult = _classUnderTest.Validate(propertiesUseCaseRequest).IsValid;

            //assert
            Assert.False(validationResult);
        }
        public void GivenARequestContainingAListOfPropRefs_WhenIExecuteTheUseCase_ThenTheListOfPropRefsGetsPassedIntoTheGateway(string propertyReference, string propertyReference2)
        {
            //arrange
            var propertyReferences = new List <string> {
                propertyReference, propertyReference2
            };
            var request = new GetMultiplePropertiesUseCaseRequest(propertyReferences);

            //act
            _classUnderTest.Execute(request);
            //assert
            _mockGetMultiplePropertiesGateway.Verify(g => g.GetMultiplePropertiesByPropertyListOfReferences(It.Is <List <string> >(arg => arg[0] == propertyReferences[0] && arg[1] == propertyReferences[1])), Times.Once);
        }
Ejemplo n.º 8
0
        public IActionResult GetMultipleByReference([FromQuery] GetMultiplePropertiesUseCaseRequest propertyReferencesRequest)
        {
            _logger.LogInformation("Multiple Property information was requested for " + propertyReferencesRequest.PropertyReferences?.Select(s => s + " ").ToList());

            var validationResult = _getMultiplePropertiesValidator.Validate(propertyReferencesRequest);

            if (!validationResult.IsValid)
            {
                return(BadRequest(new GetMultiplePropertiesUseCaseResponse(validationResult)));
            }

            var useCaseResponse = _getMultiplePropertiesUseCase.Execute(propertyReferencesRequest);

            return(Ok(useCaseResponse));
        }
Ejemplo n.º 9
0
        public void GivenListOfPropRefsAreProvided_WhenEndpointIsCalled_ThenItShouldReturnTheMultiplePropertiesSpecified(string propertyReference, string propertyReference2)
        {
            //arrange
            var property1 = _uhPropertyHelper.GenerateUhProperty();

            property1.PropRef = propertyReference;
            var property2 = _uhPropertyHelper.GenerateUhProperty();

            property2.PropRef = propertyReference2;

            _uhContext.UhPropertys.Add(property1);
            _uhContext.UhPropertys.Add(property2);
            _uhContext.SaveChanges();

            var propertyReferences = new GetMultiplePropertiesUseCaseRequest(new List <string> {
                propertyReference, propertyReference2
            });

            var expectedJson = JsonConvert.SerializeObject(
                new GetMultiplePropertiesUseCaseResponse(new List <Property> {
                _factory.FromUHProperty(property1),
                _factory.FromUHProperty(property2)
            })
                );
            //act
            var actual = _classUnderTest.GetMultipleByReference(propertyReferences);

            //assert
            actual.Should().NotBeNull();
            var okObjectResult = (OkObjectResult)actual;
            var response       = (GetMultiplePropertiesUseCaseResponse)okObjectResult.Value;

            response.Should().NotBeNull();
            response.Properties.Should().NotBeNullOrEmpty();

            response.Properties.Should().BeOfType <List <Property> >();
            Assert.AreSame(propertyReference, response.Properties[0].PropRef);
            Assert.AreSame(propertyReference2, response.Properties[1].PropRef);

            var actualJson = JsonConvert.SerializeObject(response);

            expectedJson.Should().BeEquivalentTo(actualJson);
        }
Ejemplo n.º 10
0
        public void GivenAnInvalidListOfMultiplePropertyRefs_ItShouldReturnBadInput(string propertyReference, string propertyReference2, string errorMessage)
        {
            //arrange
            var propertyReferencesRequest = new GetMultiplePropertiesUseCaseRequest(new List <string> {
                propertyReference, propertyReference2
            });
            //act
            var actionResult = _classUnderTest.GetMultipleByReference(propertyReferencesRequest);
            //assert
            var json = JsonConvert.SerializeObject(((BadRequestObjectResult)actionResult).Value);

            Assert.AreEqual(JsonConvert.SerializeObject(new Dictionary <string, object>
            {
                { "validRequest", false },
                { "errors", new [] {
                      errorMessage
                  } },
                { "properties", new List <string>() }
            }), json);
        }
Ejemplo n.º 11
0
        public void GivenNoPropRefs_ItShouldReturnBadInput()
        {
            //arrange
            var propertyReferences = new GetMultiplePropertiesUseCaseRequest(new List <string>());
            //act
            var actionResult = _classUnderTest.GetMultipleByReference(propertyReferences);

            //assert
            actionResult.Should().BeOfType <BadRequestObjectResult>();
            var json = JsonConvert.SerializeObject(((BadRequestObjectResult)actionResult).Value);

            Assert.AreEqual(JsonConvert.SerializeObject(new Dictionary <string, object>
            {
                { "validRequest", false },
                { "errors", new [] {
                      "'Property References' must not contain null or empty values such as whitespace"
                  } },
                { "properties", new List <string>() }
            }), json);
        }
Ejemplo n.º 12
0
        public void GivenAValidListOfMultipleProperyRefs_WhenIExecute_ThenTheUseCaseReturnsGetMultiplePropertiesUseCaseResponse(string propertyReference, string propertyReference2)
        {
            //arrange
            IList <Property> properties = new List <Property>
            {
                new Property
                {
                    PropRef = propertyReference
                },
                new Property
                {
                    PropRef = propertyReference2
                }
            };

            _mockGetMultiplePropertiesUseCase
            .Setup(v => v.Execute(It.Is <GetMultiplePropertiesUseCaseRequest>(i =>
                                                                              i.PropertyReferences[0] == propertyReference && i.PropertyReferences[1] == propertyReference2)))
            .Returns(new GetMultiplePropertiesUseCaseResponse(properties));

            var propertyReferencesRequest = new GetMultiplePropertiesUseCaseRequest(new List <string> {
                propertyReference, propertyReference2
            });
            //act
            var actionResult = _classUnderTest.GetMultipleByReference(propertyReferencesRequest);

            //assert
            actionResult.Should().NotBeNull();
            var okObjectResult = (OkObjectResult)actionResult;
            var response       = (GetMultiplePropertiesUseCaseResponse)okObjectResult.Value;

            response.Should().NotBeNull();
            response.Properties.Should().NotBeNullOrEmpty();

            response.Properties.Should().BeOfType <List <Property> >();
            Assert.AreSame(propertyReference, response.Properties[0].PropRef);
            Assert.AreSame(propertyReference2, response.Properties[1].PropRef);
        }