public async Task Then_The_Postcode_API_Is_Called_With_Query_And_Count(
            string query,
            PostcodeData postcode,
            [Frozen] Mock <IPostcodeApiService> postcodeApiService,
            PostcodeService postcodeService)
        {
            //Arrange
            postcodeApiService.Setup(x => x.GetPostcodeData(query))
            .ReturnsAsync(postcode);

            //Act
            var actual = await postcodeService.GetPostcodeByFullPostcode(query);

            //Assert
            actual.Should().Be(postcode);
        }
        public async Task Then_The_Postcode_Service_Is_Called(
            GetPostcodeQuery query,
            PostcodeData postcode,
            [Frozen] Mock <IPostcodeService> service,
            GetPostcodeQueryHandler handler
            )
        {
            //Arrange
            service.Setup(x => x.GetPostcodeByFullPostcode(query.Postcode)).ReturnsAsync(postcode);

            //Act
            var actual = await handler.Handle(query, CancellationToken.None);

            //Assert
            actual.Postcode.Should().Be(postcode);
        }
예제 #3
0
        public void CheckValidPostcodeData()
        {
            string postcode = Postcode.ValidPostcode;

            Console.WriteLine("Step 1. Get a request data");
            RequestData requestData = RequestData.GetRequestData(RequestType.PostcodeData, Postcode.ValidPostcode);

            Console.WriteLine($"Resource: '{ResourceUrl}/{requestData.Resource}'. Method: '{requestData.Method}'");

            Console.WriteLine($"Step 2. Send the request to check that postcode '{postcode}' is valid");
            PostcodeData response = ExecuteRequest <PostcodeData>(URL.ResourceUrl, requestData);

            Console.WriteLine($"Step 3. Check that response Status Code = {(int)ExpectedStatusCode}");
            string str = $"Expected: {(int)ExpectedStatusCode}. Actual from response: {response.Status}";

            Console.WriteLine(str);
            if ((int)ExpectedStatusCode != response.Status)
            {
                throw new Exception($"Response Status Code is incorrect. " + str);
            }

            Console.WriteLine($"Step 4. Check that details of the area are returned");
            //Get amount Of Null Or Empty Properties for response.Result
            int amountOfNullOrEmptyProperties1 = CheckResponseData(response.Result);

            //Get amount Of Null Or Empty Properties for response.Result.Codes
            int amountOfNullOrEmptyProperties2 = CheckResponseData(response.Result.Codes);

            //Verify that amount of Null or Empty field is less than 2 (or other amount allowed)
            if (amountOfNullOrEmptyProperties1 + amountOfNullOrEmptyProperties2 > 2)
            {
                throw new Exception($"{amountOfNullOrEmptyProperties1 + amountOfNullOrEmptyProperties2} fields of response are Empty or Null. " +
                                    $"Some details of the area");
            }
            else
            {
                Console.WriteLine($"Details of the area are returned in response");
            }
        }
예제 #4
0
        private void SortGeographicalGroups(List <PostcodeData> postcodeData, int gridSquareSize)
        {
            //Get Grid Size X & Y
            postcodeData = postcodeData.OrderBy(grid => grid.eastings).ToList();
            int maxX = postcodeData[postcodeData.Count - 1].eastings;

            postcodeData = postcodeData.OrderBy(grid => grid.northings).ToList();
            int maxY = postcodeData[postcodeData.Count - 1].northings;

            //Break Grid into Columns and Rows Based on Grouping Distance
            int numOfColumns = (maxX / gridSquareSize) + 1;
            int numOfRows    = (maxY / gridSquareSize) + 1;

            List <PostcodeData>[,] gridCount = new List <PostcodeData> [numOfColumns, numOfRows];

            //Cycle through the postcodes and calculates in which grid square each postcode would be placed and adds them to a 2d array containing lists of postcodes in that square area
            for (int locationIndex = 0; locationIndex < postcodeData.Count; locationIndex++)
            {
                PostcodeData result = postcodeData[locationIndex];

                int column = result.eastings / gridSquareSize;
                int row    = result.northings / gridSquareSize;

                List <PostcodeData> entries = gridCount[column, row];

                if (entries == null)
                {
                    entries = new List <PostcodeData>();
                }

                entries.Add(result);
                gridCount[column, row] = entries;
            }

            List <List <PostcodeData> > sortedPostCodes = new List <List <PostcodeData> >();

            //Adds groupings of postcodes to a new master list
            for (int x = 0; x < numOfColumns; x++)
            {
                for (int y = 0; y < numOfRows; y++)
                {
                    List <PostcodeData> ls = gridCount[x, y];

                    if (ls != null)
                    {
                        if (ls.Count > 1)
                        {
                            sortedPostCodes.Add(ls);
                        }
                    }
                }
            }

            //Sort the master list by number of postcodes within that area
            sortedPostCodes = sortedPostCodes.OrderByDescending(ls => ls.Count).ToList();

            //Grabs the id associated with the postcode from contact info table so it can then be cross referenced with the ID from the people table
            //Assumption being made here is that postcodes are unique
            List <List <int> > postCodeIDs = new List <List <int> >();

            for (int i = 0; i < sortedPostCodes.Count; i++)
            {
                postCodeIDs.Add(new List <int>());

                for (int j = 0; j < sortedPostCodes[i].Count; j++)
                {
                    SQLiteDataReader reader = m_database.GetDataFromTable("ID", "contactInfo", "postal = @postcode", "postcode", sortedPostCodes[i][j].postcode, false);

                    while (reader.Read())
                    {
                        long ID = (long)reader["ID"];
                        postCodeIDs[i].Add((int)ID);
                    }
                }
            }

            //Create worksheet
            string[] columnNames = new string[] { "First Name", "Last Name", "Post Code" };
            m_reportHandler.CreateNewWorkSheet("Geographical Groupings", columnNames);

            int excelCellRow = 0;

            //Grabs the details from the people table to put into the report alongside the associated postcodes
            for (int i = 0; i < postCodeIDs.Count; i++)
            {
                for (int j = 0; j < postCodeIDs[i].Count; j++)
                {
                    SQLiteCommand cmd = new SQLiteCommand();

                    cmd.Connection  = m_dbConnection;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = "Select first_name, last_name FROM people WHERE ID = @ID";
                    cmd.Parameters.AddWithValue("@ID", postCodeIDs[i][j]);

                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string firstName  = RemoveQuotesFromString(reader["first_name"].ToString());
                            string secondName = RemoveQuotesFromString(reader["last_name"].ToString());
                            string postCode   = sortedPostCodes[i][j].postcode;

                            m_reportHandler.WriteToCell(excelCellRow + 1, 0, firstName, "Geographical Groupings");
                            m_reportHandler.WriteToCell(excelCellRow + 1, 1, secondName, "Geographical Groupings");
                            m_reportHandler.WriteToCell(excelCellRow + 1, 2, postCode, "Geographical Groupings");
                        }
                    }

                    excelCellRow++;
                }
                excelCellRow++;
            }
        }