예제 #1
0
        public void SendEmail(FloodingRequest floodingRequest, string caseReference)
        {
            if (string.IsNullOrEmpty(floodingRequest.Reporter.EmailAddress))
            {
                return;
            }

            EMailTemplate template;
            var           templateNotFound = false;

            var value = floodingRequest.WhatDoYouWantToReport.Equals("highWaterLevels")
                ? floodingRequest.WhatDoYouWantToReport
                : floodingRequest.WhereIsTheFlood;

            switch (value)
            {
            case "pavement":
            case "road":
            case "parkOrFootpath":
                template = EMailTemplate.ReportAFloodPublicSpaces;
                break;

            case "privateLand":
            case "home":
            case "business":
                template = EMailTemplate.ReportAFloodPrivateSpaces;
                break;

            case "highWaterLevels":
                template = EMailTemplate.ReportAFloodHighWaterLevels;
                break;

            default:
                templateNotFound = true;
                template         = EMailTemplate.BaseTemplate;
                _logger.LogWarning($"MailHelper:: SendEmail:: Email not sent, no email template found for {floodingRequest.WhereIsTheFlood} journey");
                break;
            }

            if (!templateNotFound)
            {
                try
                {
                    _mailingServiceGateway.Send(new Mail
                    {
                        Payload = JsonConvert.SerializeObject(new
                        {
                            Subject          = template.Equals(EMailTemplate.ReportAFloodHighWaterLevels) ? "Thanks for reporting high water levels on a river or stream" : "Thanks for reporting a flood",
                            Reference        = caseReference,
                            RecipientAddress = floodingRequest.Reporter.EmailAddress
                        }),
                        Template = template
                    });
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        public void ToConfirmFormOptions_ShouldMapConfigOptions_WhenMapUsed_RoadJourney()
        {
            // Arrange
            var request = new FloodingRequest
            {
                WhereIsTheFlood = "road",
                WhereIsTheFloodingComingFrom = "river",
                WhatDoYouWantToReport        = "flood",
                Map = new Map
                {
                    Lat    = "lat",
                    Lng    = "lng",
                    Street = "street"
                }
            };

            // Act
            var result = request.ToConfig(_confirmAttributeFormOptions, _verintOptions);

            // Assert
            Assert.Equal("RIV", result.ConfirmIntegrationFormOptions.FloodingSourceReported);
            Assert.Equal("road", result.VerintOption.Type);
            Assert.Equal("lat", result.ConfirmIntegrationFormOptions.YCoordinate);
            Assert.Equal("lng", result.ConfirmIntegrationFormOptions.XCoordinate);
        }
        public void SendEmail_ShouldCallMailingServiceGateway_WithCorrectEmailTemplate_ForJourney(EMailTemplate emailTemplate, string journey, string whatToReport = "flood")
        {
            var callbackValue = new Mail();

            // Arrange
            _mockMailingServiceGateway.Setup(_ => _.Send(It.IsAny <Mail>()))
            .Callback <Mail>(a => callbackValue = a);

            var floodingRequest = new FloodingRequest
            {
                WhereIsTheFlood       = journey,
                WhatDoYouWantToReport = whatToReport,
                Reporter = new ContactDetails
                {
                    EmailAddress = "EmailAddress"
                }
            };

            // Act
            _mailHelper.SendEmail(floodingRequest, "123456");

            // Assert
            _mockMailingServiceGateway.Verify(_ => _.Send(It.IsAny <Mail>()), Times.Once);
            Assert.Equal(emailTemplate, callbackValue.Template);
        }
예제 #4
0
        public async Task CreateCase_ShouldCallStreetHelper_GetStreetDetails_IfMapNotUsed()
        {
            // Arrange
            var floodingRequest = new FloodingRequest
            {
                HowWouldYouLikeToBeContacted = "phone",
                IsTheFloodingBlockingTheWholePavementOrCausing = "yes",
                Reporter = new ContactDetails
                {
                    FirstName    = "firstName",
                    LastName     = "lastName",
                    EmailAddress = "*****@*****.**",
                    PhoneNumber  = "01222333333",
                    Address      = new Address
                    {
                        PlaceRef        = "123",
                        SelectedAddress = "TestAddress"
                    }
                },
                TellUsABoutTheFlood            = "it is a flood",
                WhatDoYouWantToReport          = "flood",
                WhereIsTheFlood                = "home",
                WhereInThePropertyIsTheFlood   = "garage",
                IsTheGarageConnectedToYourHome = "yes",
                WhereIsTheFloodingComingFrom   = "river"
            };

            // Act
            await _floodingService.CreateCase(floodingRequest);

            // Assert
            _mockStreetHelper.Verify(_ => _.GetStreetDetails(It.IsAny <Address>()), Times.Once);
        }
        public void ToCase_ShouldMapToCase_WhenMapUsed_PavementJourney()
        {
            // Arrange
            var request = new FloodingRequest
            {
                WhereIsTheFlood = "pavement",
                WhereIsTheFloodingComingFrom = "river",
                WhatDoYouWantToReport        = "flood",
                Map = new Map
                {
                    Lat    = "lat",
                    Lng    = "lng",
                    Street = "street, place, 123456"
                },
                Reporter = new ContactDetails
                {
                    FirstName    = "FirstName",
                    LastName     = "LastName",
                    PhoneNumber  = "PhoneNumber",
                    EmailAddress = "EmailAddress"
                },
                HowWouldYouLikeToBeContacted = "phone",
                IsTheFloodingBlockingTheWholePavementOrCausing = "yes",
                TellUsABoutTheFlood = "It's a flood"
            };

            var streetResult = new FloodingAddress
            {
                UniqueId = "654321",
                USRN     = "123456",
                Name     = "street, place"
            };

            var addressResult = new StockportGovUK.NetStandard.Models.Verint.Address
            {
                USRN        = "123456",
                Reference   = "reference",
                Description = "description"
            };

            var expectedDescription =
                "Where is the flood coming from: river\r\nWhere is the flood: On a pavement\r\nBlocking the pavement: yes\r\nTell us about the flood: It's a flood\r\nHow would you like to be contacted: phone\r\n";

            // Act
            var result = request.ToCase(_floodingPavementConfiguration, streetResult, _pavementFloodingLocationConfiguration);

            // Assert
            Assert.Equal(2002592, result.EventCode);
            Assert.Equal(_floodingPavementConfiguration.VerintOption.Classification, result.Classification);
            Assert.Equal(_floodingPavementConfiguration.VerintOption.EventTitle, result.EventTitle);
            Assert.Equal(streetResult.Name, result.Street.Description);
            Assert.Equal(streetResult.USRN, result.Street.USRN);
            Assert.Equal(streetResult.UniqueId, result.Street.Reference);
            Assert.Equal(expectedDescription, result.Description);
        }
예제 #6
0
        public static FloodingConfiguration ToConfig(this FloodingRequest request, ConfirmAttributeFormOptions attributesFormOptions, VerintOptions verintOptions)
        {
            var verintConfigValue = request.WhatDoYouWantToReport.Equals("flood") ? request.WhereIsTheFlood : request.WhatDoYouWantToReport;
            var verintConfig      = verintOptions.Options.First(_ => _.Type.Equals(verintConfigValue));

            var formOptions = new ConfirmFloodingIntegrationFormOptions
            {
                EventId     = verintConfig.EventCode,
                ClassCode   = verintConfig.ClassCode,
                ServiceCode = verintConfig.ServiceCode,
                SubjectCode = verintConfig.SubjectCode
            };

            formOptions.FloodingSourceReported = attributesFormOptions.FloodingSourceReported.FirstOrDefault(_ => _.Type.Equals(request.WhereIsTheFloodingComingFrom))?.Value ?? string.Empty;
            formOptions.DomesticOrCommercial   = attributesFormOptions.CommercialOrDomestic.FirstOrDefault(_ => _.Type.Equals(request.WhereIsTheFlood))?.Value ?? string.Empty;

            if (request.WhereIsTheFlood.Equals("home"))
            {
                if (request.WhereInThePropertyIsTheFlood.Equals("garage"))
                {
                    formOptions.LocationOfFlooding =
                        attributesFormOptions.FloodLocationInProperty.First(_ =>
                                                                            _.Type.Equals(request.IsTheGarageConnectedToYourHome)).Value;
                }
                else
                {
                    formOptions.LocationOfFlooding = attributesFormOptions.FloodLocationInProperty
                                                     .First(_ => _.Type.Equals(request.WhereInThePropertyIsTheFlood)).Value;
                }
            }

            if (request.WhereIsTheFlood.Equals("business"))
            {
                if (request.IsTheFloodInsideOrOutsideProperty.Equals("inside"))
                {
                    formOptions.LocationOfFlooding = attributesFormOptions.FloodLocationInProperty
                                                     .First(_ => _.Type.Equals(request.WhereInThePropertyIsTheFlood)).Value;
                }
                else
                {
                    formOptions.LocationOfFlooding = attributesFormOptions.FloodLocationInProperty
                                                     .First(_ => _.Type.Equals("garden")).Value;
                }
            }

            formOptions.XCoordinate = request.Map?.Lng;
            formOptions.YCoordinate = request.Map?.Lat;

            return(new FloodingConfiguration
            {
                ConfirmIntegrationFormOptions = formOptions,
                VerintOption = verintConfig
            });
        }
예제 #7
0
        public async Task <IActionResult> Post([FromBody] FloodingRequest model)
        {
            try
            {
                var result = await _floodingService.CreateCase(model);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                _logger.LogError($"FloodingService:: Post:: Error message: {ex.Message}");
                return(StatusCode(500, ex.Message));
            }
        }
예제 #8
0
        private static string DescriptionBuilder(FloodingRequest floodingRequest)
        {
            var description = new StringBuilder();

            if (floodingRequest.WhatDoYouWantToReport.Equals("flood") && !floodingRequest.WhereIsTheFloodingComingFrom.Equals("other"))
            {
                description.Append($"Where is the flood coming from: {floodingRequest.WhereIsTheFloodingComingFrom.WhereIsTheFloodingComingFromToReadableText()}{Environment.NewLine}");
            }

            if (floodingRequest.WhereIsTheFloodingComingFrom.Equals("other"))
            {
                description.Append($"Tell us where the flood is coming from (optional): {floodingRequest.TellUsWhereTheFloodIsComingFrom}{Environment.NewLine}");
            }

            if (!string.IsNullOrWhiteSpace(floodingRequest.WhereIsTheFlood))
            {
                description.Append($"Where is the flood: {floodingRequest.WhereIsTheFlood.WhereIsTheFloodToReadableText()}{Environment.NewLine}");
            }

            if (!string.IsNullOrWhiteSpace(floodingRequest.IsTheFloodInsideOrOutsideProperty))
            {
                description.Append($"Is the flood inside or outside the property: {floodingRequest.IsTheFloodInsideOrOutsideProperty}{Environment.NewLine}");
            }

            if (!string.IsNullOrWhiteSpace(floodingRequest.WhereInThePropertyIsTheFlood))
            {
                description.Append($"Where in the property is the flood: {floodingRequest.WhereInThePropertyIsTheFlood.WhereInThePropertyIsTheFloodToReadableText()}{Environment.NewLine}");
            }

            if (!string.IsNullOrWhiteSpace(floodingRequest.IsTheGarageConnectedToYourHome))
            {
                description.Append($"Is the garage connected to your home: {floodingRequest.IsTheGarageConnectedToYourHome}{Environment.NewLine}");
            }

            if (!string.IsNullOrWhiteSpace(floodingRequest.IsTheFloodingBlockingTheWholePavementOrCausing))
            {
                description.Append($"Blocking the pavement: {floodingRequest.IsTheFloodingBlockingTheWholePavementOrCausing}{Environment.NewLine}");
            }

            if (!string.IsNullOrWhiteSpace(floodingRequest.IsTheFloodingBlockingTheWholeRoadOrCausing))
            {
                description.Append($"Blocking the road: {floodingRequest.IsTheFloodingBlockingTheWholeRoadOrCausing}{Environment.NewLine}");
            }

            description.Append($"Tell us about the flood: {floodingRequest.TellUsABoutTheFlood}{Environment.NewLine}")
            .Append($"How would you like to be contacted: {floodingRequest.HowWouldYouLikeToBeContacted}{Environment.NewLine}");

            return(description.ToString());
        }
        public void ToCase_ShouldMapToCase_WhenMapNotUsed()
        {
            // Arrange
            var request = new FloodingRequest
            {
                WhereIsTheFlood = "home",
                WhereIsTheFloodingComingFrom = "river",
                WhatDoYouWantToReport        = "flood",
                Reporter = new ContactDetails
                {
                    FirstName    = "FirstName",
                    LastName     = "LastName",
                    PhoneNumber  = "PhoneNumber",
                    EmailAddress = "EmailAddress",
                    Address      = new StockportGovUK.NetStandard.Models.Addresses.Address
                    {
                        PlaceRef        = "123456",
                        SelectedAddress = "SelectedAddress"
                    }
                },
                HowWouldYouLikeToBeContacted = "phone",
                TellUsABoutTheFlood          = "It's a flood"
            };

            var streetResult = new FloodingAddress
            {
                USRN     = "123456",
                UniqueId = "reference",
                Name     = "description"
            };

            var expectedDescription =
                "Where is the flood coming from: river\r\nWhere is the flood: In a home\r\nTell us about the flood: It's a flood\r\nHow would you like to be contacted: phone\r\n";

            // Act
            var result = request.ToCase(_floodingHomeConfiguration, streetResult, null);

            // Assert
            Assert.Equal(2009484, result.EventCode);
            Assert.Equal(_floodingHomeConfiguration.VerintOption.Classification, result.Classification);
            Assert.Equal(_floodingHomeConfiguration.VerintOption.EventTitle, result.EventTitle);
            Assert.Equal(request.Reporter.Address.SelectedAddress, result.Street.Description);
            Assert.Equal(request.Reporter.Address.PlaceRef, result.Street.USRN);
            Assert.Equal(expectedDescription, result.Description);
        }
        public void SendEmail_ShouldNotCallMailingServiceGateway_IfTemplateNotFoundForJourneyType()
        {
            // Arrange
            var floodingRequest = new FloodingRequest
            {
                WhereIsTheFlood       = "non-existant journey",
                WhatDoYouWantToReport = "flood",
                Reporter = new ContactDetails
                {
                    EmailAddress = "EmailAddress"
                }
            };

            // Act
            _mailHelper.SendEmail(floodingRequest, "123456");

            // Assert
            _mockMailingServiceGateway.Verify(_ => _.Send(It.IsAny <Mail>()), Times.Never);
        }
        public void ToConfirmFormOptions_ShouldMapConfigOptions_WhenMapNotUsed()
        {
            // Arrange
            var request = new FloodingRequest
            {
                WhereIsTheFlood = "home",
                WhereIsTheFloodingComingFrom = "river",
                WhatDoYouWantToReport        = "flood",
                WhereInThePropertyIsTheFlood = "cellarOrBasement",
            };

            // Act
            var result = request.ToConfig(_confirmAttributeFormOptions, _verintOptions);

            // Assert
            Assert.Equal("RIV", result.ConfirmIntegrationFormOptions.FloodingSourceReported);
            Assert.Equal("home", result.VerintOption.Type);
            Assert.Null(result.ConfirmIntegrationFormOptions.XCoordinate);
            Assert.Null(result.ConfirmIntegrationFormOptions.YCoordinate);
        }
        public void ToConfirmFormOptions_ShouldMapConfigOptions_WhenBusinessJourney_Outside()
        {
            // Arrange
            var request = new FloodingRequest
            {
                WhereIsTheFlood = "business",
                WhereIsTheFloodingComingFrom      = "river",
                WhatDoYouWantToReport             = "flood",
                IsTheFloodInsideOrOutsideProperty = "outside",
            };

            // Act
            var result = request.ToConfig(_confirmAttributeFormOptions, _verintOptions);

            // Assert
            Assert.Equal("RIV", result.ConfirmIntegrationFormOptions.FloodingSourceReported);
            Assert.Equal("GAR", result.ConfirmIntegrationFormOptions.LocationOfFlooding);
            Assert.Equal("COM", result.ConfirmIntegrationFormOptions.DomesticOrCommercial);
            Assert.Equal("business", result.VerintOption.Type);
            Assert.Null(result.ConfirmIntegrationFormOptions.XCoordinate);
            Assert.Null(result.ConfirmIntegrationFormOptions.YCoordinate);
        }
        public void ToConfirmFormOptions_ShouldMapConfigOptions_WhenHomeJourney_AndNotInGarage()
        {
            // Arrange
            var request = new FloodingRequest
            {
                WhereIsTheFlood = "home",
                WhereIsTheFloodingComingFrom = "river",
                WhatDoYouWantToReport        = "flood",
                WhereInThePropertyIsTheFlood = "driveway"
            };

            // Act
            var result = request.ToConfig(_confirmAttributeFormOptions, _verintOptions);

            // Assert
            Assert.Equal("RIV", result.ConfirmIntegrationFormOptions.FloodingSourceReported);
            Assert.Equal("DRV", result.ConfirmIntegrationFormOptions.LocationOfFlooding);
            Assert.Equal("DOM", result.ConfirmIntegrationFormOptions.DomesticOrCommercial);
            Assert.Equal("home", result.VerintOption.Type);
            Assert.Null(result.ConfirmIntegrationFormOptions.XCoordinate);
            Assert.Null(result.ConfirmIntegrationFormOptions.YCoordinate);
        }
예제 #14
0
        public async Task <string> CreateCase(FloodingRequest request)
        {
            try
            {
                var streetResult = request.DidNotUseMap
                    ? await _streetHelper.GetStreetDetails(request.Reporter.Address)
                    : await _streetHelper.GetStreetUniqueId(request.Map);

                if (!request.DidNotUseMap)
                {
                    request.Map = await ConvertLatLng(request.Map);
                }
                else
                {
                    request.Map = new Map {
                        Lng = streetResult.Easting,
                        Lat = streetResult.Northing
                    };
                }

                var floodingLocationConfig =
                    string.IsNullOrEmpty(request.WhereIsTheFlood) ?
                    _verintOptions.Value.FloodingLocations.FirstOrDefault(_ => _.Type.Equals(request.WhatDoYouWantToReport)) :
                    _verintOptions.Value.FloodingLocations.FirstOrDefault(_ => _.Type.Equals(request.WhereIsTheFlood));
                var configuration = request.ToConfig(_confirmAttributeFormOptions.Value, _verintOptions.Value);
                var crmCase       = request.ToCase(configuration, streetResult, floodingLocationConfig);
                var verintRequest = crmCase.ToConfirmFloodingIntegrationFormCase(configuration.ConfirmIntegrationFormOptions);

                var caseResult = await _verintServiceGateway.CreateVerintOnlineFormCase(verintRequest);

                _mailHelper.SendEmail(request, caseResult.ResponseContent.VerintCaseReference);

                return(caseResult.ResponseContent.VerintCaseReference);
            }
            catch (Exception ex)
            {
                throw new Exception($"FloodingService:: CreateCase, Failed to create case, exception: {ex.Message}");
            }
        }
예제 #15
0
        public static Case ToCase(
            this FloodingRequest floodingRequest,
            FloodingConfiguration floodingConfiguration,
            FloodingAddress streetResult,
            Config floodingLocationConfig
            )
        {
            var crmCase = new Case
            {
                EventCode      = floodingConfiguration.VerintOption.EventCode,
                Classification = floodingConfiguration.VerintOption.Classification,
                EventTitle     = floodingConfiguration.VerintOption.EventTitle,
                Customer       = new Customer
                {
                    Forename  = floodingRequest.Reporter.FirstName,
                    Surname   = floodingRequest.Reporter.LastName,
                    Email     = floodingRequest.Reporter.EmailAddress,
                    Telephone = floodingRequest.Reporter.PhoneNumber
                },
                Description       = DescriptionBuilder(floodingRequest),
                RaisedByBehaviour = RaisedByBehaviourEnum.Individual,
            };

            if (floodingRequest.DidNotUseMap)
            {
                crmCase.AssociatedWithBehaviour = AssociatedWithBehaviourEnum.Street;
                crmCase.Street = new Street
                {
                    USRN        = streetResult.USRN,
                    Reference   = streetResult.UniqueId,
                    Description = floodingRequest.Reporter.Address.SelectedAddress
                };

                crmCase.FurtherLocationInformation = floodingRequest.Reporter.Address.SelectedAddress;
            }
            else
            {
                if (string.IsNullOrEmpty(floodingRequest.Map.Street))
                {
                    crmCase.Street = new Street
                    {
                        USRN        = ConfirmConstants.USRN,
                        Description = ConfirmConstants.Description,
                        Reference   = ConfirmConstants.USRN
                    };
                }
                else
                {
                    crmCase.AssociatedWithBehaviour = AssociatedWithBehaviourEnum.Street;
                    crmCase.Street = new Street
                    {
                        USRN        = streetResult.USRN,
                        Description = streetResult.Name,
                        Reference   = string.IsNullOrEmpty(streetResult.UniqueId) ? null : streetResult.UniqueId
                    };
                }

                crmCase.FurtherLocationInformation = floodingLocationConfig.Value;
            }

            return(crmCase);
        }