[Test] // For new Contact Details API
        public void WhenContactDetailsExist_ReturnsContactDetails()
        {
            // Arrange
            ApiGateway client = new ApiGateway(new HttpClientFactoryWrapper(Client));

            var assetResponse = _fixture.Create <AssetResponseObject>();

            MockApiGateway.SetAssetApiResponse(assetResponse);

            var tenureResponse = _fixture.Create <TenureResponseObject>();

            MockApiGateway.SetTenureInformationApiResponse(tenureResponse);

            var propertyReference = _fixture.Create <string>();

            var contactDetailsResponse = new ContactDetailsResponse
            {
                Results = _fixture.CreateMany <ContactDetailsResponseObject>(3)
            };

            MockApiGateway.SetContactDetailsApiResponse(contactDetailsResponse);

            // Act
            var response = client.ExecuteRequest <PropertyResponse>("dummy", new Uri($"/api/v2/properties/{propertyReference}", UriKind.Relative)).Result;

            // Assert
            response.IsSuccess.Should().BeTrue();
            response.Status.Should().Be(HttpStatusCode.OK);

            response.Content.ContactDetails.Should().NotBeNull();
            response.Content.ContactDetails.Should().HaveCount(contactDetailsResponse.Results.Count());
        }
        public void WhenTenureExists_ReturnsTenureInformation()
        {
            // Arrange
            ApiGateway client = new ApiGateway(new HttpClientFactoryWrapper(Client));

            var assetResponse = _fixture.Create <AssetResponseObject>();

            MockApiGateway.SetAssetApiResponse(assetResponse);

            var tenureResponse = _fixture.Create <TenureResponseObject>();

            MockApiGateway.SetTenureInformationApiResponse(tenureResponse);

            var propertyReference = _fixture.Create <string>();

            // Act
            var response = client.ExecuteRequest <PropertyResponse>("dummy", new Uri($"/api/v2/properties/{propertyReference}", UriKind.Relative)).Result;

            // Assert
            response.IsSuccess.Should().BeTrue();
            response.Status.Should().Be(HttpStatusCode.OK);

            response.Content.Tenure.TypeCode.Should().Be(tenureResponse.TenureType.Code);
            response.Content.Tenure.TypeDescription.Should().Be(tenureResponse.TenureType.Description);
        }
        public void GetPropertyWithAlerts(int propertyAlertCount, int personAlertCount, bool canRaiseRepair)
        {
            // Arrange
            var legacyReferenceValue = new Faker().Random.String2(10) + "/01";

            var assetResponse  = GenerateAssetResponse(canRaiseRepair);
            var tenureResponse = GenerateTenure(canRaiseRepair, legacyReferenceValue);

            MockApiGateway.SetAssetApiResponse(assetResponse);

            MockApiGateway.SetTenureInformationApiResponse(tenureResponse);

            MockApiGateway.AddPropertyAlerts(propertyAlertCount, assetResponse.AssetId);
            MockApiGateway.AddPersonAlerts(personAlertCount, legacyReferenceValue);
            MockApiGateway.AddResidentContacts();

            ApiGateway client = new ApiGateway(new HttpClientFactoryWrapper(Client));

            // Act
            var response = client.ExecuteRequest <PropertyResponse>("dummy", new Uri($"/api/v2/properties/{assetResponse.AssetId}", UriKind.Relative)).Result;

            // Assert
            response.IsSuccess.Should().BeTrue();
            response.Status.Should().Be(HttpStatusCode.OK);

            response.Content.Property.Should().BeEquivalentTo(assetResponse.ToDomain().ToResponse(tenureResponse.ToDomain()));
            response.Content.Alerts.LocationAlert.Should().HaveCount(propertyAlertCount);
            response.Content.Alerts.PersonAlert.Should().HaveCount(personAlertCount);
            response.Content.Property.CanRaiseRepair.Should().Be(canRaiseRepair);
        }
        public void GetAlerts(int expectedPropertyAlertCount, int expectedPersonAlertCount)
        {
            // Arrange
            var legacyReferenceValue = new Faker().Random.String2(10) + "/01";
            var tenureResponse       = GenerateTenure(legacyReferenceValue);

            var expectedProperty = _fixture.Create <AssetResponseObject>();

            expectedProperty.Tenure.Id = tenureResponse.Id.ToString();

            MockApiGateway.SetAssetApiResponse(expectedProperty);

            MockApiGateway.SetTenureInformationApiResponse(tenureResponse);

            MockApiGateway.AddPropertyAlerts(expectedPropertyAlertCount, expectedProperty.AssetId);
            MockApiGateway.AddTenantInformation(legacyReferenceValue, expectedProperty.AssetId);
            MockApiGateway.AddPersonAlerts(expectedPersonAlertCount, legacyReferenceValue);

            ApiGateway client = new ApiGateway(new HttpClientFactoryWrapper(Client));

            // Act
            var response = client.ExecuteRequest <CautionaryAlertResponseList>("dummy", new Uri($"/api/v2/properties/{expectedProperty.AssetId}/alerts", UriKind.Relative)).Result;

            // Assert
            response.IsSuccess.Should().BeTrue();
            response.Status.Should().Be(HttpStatusCode.OK);
            response.Content.PropertyReference.Should().Be(expectedProperty.AssetId);
            response.Content.LocationAlert.Should().HaveCount(expectedPropertyAlertCount);
            response.Content.PersonAlert.Should().HaveCount(expectedPersonAlertCount);
        }
        public void Search_WhenAPIFails_ReturnsBadRequest()
        {
            // Arrange
            var apiResponse = GenerateApiResponse(0);

            MockApiGateway.SetHousingSearchApiResponse(apiResponse);
            MockApiGateway.ForcedCode = HttpStatusCode.BadRequest;

            // Act
            var response = _mockGateway.ExecuteRequest <HousingSearchAPIResponse>("dummy", new Uri($"/api/v2/properties/search?searchText={SearchText}", UriKind.Relative)).Result;

            // Assert
            response.IsSuccess.Should().BeFalse();
            response.Status.Should().Be(HttpStatusCode.BadGateway);
        }
        public void AlertListForwardsErrorWhenPlatformApiFails()
        {
            // Arrange
            MockApiGateway.ForcedCode = HttpStatusCode.BadGateway;

            var        expectedProperty = MockApiGateway.NewProperty();
            ApiGateway client           = new ApiGateway(new HttpClientFactoryWrapper(Client));

            // Act
            var response = client.ExecuteRequest <CautionaryAlertResponseList>("dummy", new Uri($"/api/v2/properties/{expectedProperty.PropRef}/alerts", UriKind.Relative)).Result;

            // Assert
            response.IsSuccess.Should().BeFalse();
            response.Status.Should().Be(HttpStatusCode.BadGateway);
        }
        public void WhenAssetDoesntExist_ReturnsNotFound()
        {
            // Arrange
            ApiGateway client = new ApiGateway(new HttpClientFactoryWrapper(Client));

            MockApiGateway.SetAssetApiResponse(null);

            var propertyReference = _fixture.Create <string>();

            // Act
            var response = client.ExecuteRequest <PropertyResponse>("dummy", new Uri($"/api/v2/properties/{propertyReference}", UriKind.Relative)).Result;

            // Assert
            response.IsSuccess.Should().BeFalse();
            response.Status.Should().Be(HttpStatusCode.NotFound);
        }
        public void Search_WhenNoResults_ReturnsEmptyResponseObject()
        {
            // Arrange
            var apiResponse = GenerateApiResponse(0);

            MockApiGateway.SetHousingSearchApiResponse(apiResponse);
            MockApiGateway.ForcedCode = null;

            // Act
            var response = _mockGateway.ExecuteRequest <SearchForPropertiesResponse>("dummy", new Uri($"/api/v2/properties/search?searchText={SearchText}", UriKind.Relative)).Result;

            // Assert
            response.IsSuccess.Should().BeTrue();
            response.Status.Should().Be(HttpStatusCode.OK);

            response.Content.Total.Should().Be(0);
            response.Content.Properties.Should().HaveCount(0);
        }
        public void WhenAssetExists_ReturnsAsset()
        {
            // Arrange
            ApiGateway client = new ApiGateway(new HttpClientFactoryWrapper(Client));

            var assetResponse = _fixture.Create <AssetResponseObject>();

            MockApiGateway.SetAssetApiResponse(assetResponse);

            MockApiGateway.SetTenureInformationApiResponse(null);

            var propertyReference = _fixture.Create <string>();

            // Act
            var response = client.ExecuteRequest <PropertyResponse>("dummy", new Uri($"/api/v2/properties/{propertyReference}", UriKind.Relative)).Result;

            // Assert
            response.IsSuccess.Should().BeTrue();
            response.Status.Should().Be(HttpStatusCode.OK);

            var tenure = _fixture.Create <RepairsApi.V2.Domain.TenureInformation>();

            response.Content.Property.Should().BeEquivalentTo(assetResponse.ToDomain().ToResponse(tenure));
        }