Ejemplo n.º 1
0
        public async Task AddSearchToDb(NearbyRestaurants nearbyRestaurants, int diner1Id, int diner2Id)
        {
            for (int i = 0; i < nearbyRestaurants.result.data.Length; i++)
            {
                PotentialMatch potentialMatch = new PotentialMatch();
                potentialMatch.Diner1Id          = diner1Id;
                potentialMatch.Diner2Id          = diner2Id;
                potentialMatch.RestaurantName    = nearbyRestaurants.result.data[i].restaurant_name;
                potentialMatch.RestaurantAddress = nearbyRestaurants.result.data[i].address.formatted;
                potentialMatch.RestaurantId      = nearbyRestaurants.result.data[i].restaurant_id;
                potentialMatch.PriceRange        = nearbyRestaurants.result.data[i].price_range;
                potentialMatch.PhoneNumber       = nearbyRestaurants.result.data[i].restaurant_phone;

                string cuisines = "";
                for (int j = 0; j < nearbyRestaurants.result.data[i].cuisines.Length; j++)
                {
                    cuisines += $"{nearbyRestaurants.result.data[i].cuisines[j]} ";
                }

                potentialMatch.Cuisines  = cuisines;
                potentialMatch.TimeStamp = DateTime.Now;
                _repo.PotentialMatch.CreateMatch(potentialMatch);
                await _repo.Save();
            }
        }
        public void Will_set_description_as_fourth_console_snippet()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings()
            };
            var console_line = new ConsoleLine {
                Description_string = "Some description"
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(console_line.Description_string, console_snippets[3].Text);
        }
        public void Will_set_amount_as_third_console_snippet()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings()
            };
            var console_line = new ConsoleLine {
                Amount_string = "�.55"
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(console_line.Amount_string + ",", console_snippets[2].Text);
        }
        public void WillSetDateTextColourAsWhite_IfRankingsAreNull()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = null
            };
            var console_line = new ConsoleLine {
                Date_string = "10/10/2018"
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(ConsoleColour.White, console_snippets[1].Text_colour);
        }
        public void Will_set_date_as_second_console_snippet()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings()
            };
            var console_line = new ConsoleLine {
                Date_string = "10/10/2018"
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(console_line.Date_string + ",", console_snippets[1].Text);
        }
        public void Will_set_index_as_first_console_snippet()
        {
            // Arrange
            var index           = 23;
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings()
            };
            var console_line = new ConsoleLine {
                Index = index
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual($"{index}. ", console_snippets[0].Text);
        }
        public void WillSetAmountTextColourAsWhite_IfRankingsAreNull()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings     = null,
                Amount_match = false // AmountMatch should be ignored - AmountRanking is used instead
            };
            var console_line = new ConsoleLine {
                Amount_string = "�.55"
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(ConsoleColour.White, console_snippets[2].Text_colour);
        }
        public void Will_set_index_text_colour_as_white()
        {
            // Arrange
            var index           = 23;
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings()
            };
            var console_line = new ConsoleLine {
                Index = index
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(ConsoleColour.White, console_snippets[0].Text_colour);
        }
        public void Will_set_date_colour_to_green_if_rankings_are_null()
        {
            // Arrange
            var index           = 23;
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings()
            };
            var console_line = new ConsoleLine {
                Index = index
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual($"{index}. ", console_snippets[0].Text);
        }
        public void WillSetDescriptionTextColourAsGreen_IfThereIsAFullTextMatch()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Full_text_match    = true,
                Partial_text_match = true,
                Rankings           = new Rankings()
            };
            var console_line = new ConsoleLine {
                Description_string = "Some description"
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(ConsoleColour.Green, console_snippets[3].Text_colour);
        }
        public void WillSetDateTextColourAsDarkYellow_IfDateRankingIsLessThanOrEqualToTwo(int date_ranking)
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings
                {
                    Date = date_ranking
                },
            };
            var console_line = new ConsoleLine {
                Date_string = "10/10/2018"
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(ConsoleColour.DarkYellow, console_snippets[1].Text_colour);
        }
        public void WillSetDateTextColourAsWhite_IfDateRankingIsGreaterThanFive(int date_ranking)
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings
                {
                    Date = date_ranking
                }
            };
            var console_line = new ConsoleLine {
                Date_string = "10/10/2018"
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(ConsoleColour.White, console_snippets[1].Text_colour);
        }
        public void WillSetDateTextColourAsGreen_IfDateRankingIsZero()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings
                {
                    Date = 0
                },
            };
            var console_line = new ConsoleLine {
                Date_string = "10/10/2018"
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(ConsoleColour.Green, console_snippets[1].Text_colour);
        }
        public void WillSetAmountTextColourAsDarkYellow_IfAmountIsAPartialMatch()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings
                {
                    Amount = 1
                },
                Amount_match = false // AmountMatch should be ignored - AmountRanking is used instead
            };
            var console_line = new ConsoleLine {
                Amount_string = "�.55"
            };

            // Act
            var console_snippets = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(ConsoleColour.DarkYellow, console_snippets[2].Text_colour);
        }
        public void Will_regenerate_console_snippet_if_description_changes()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings()
            };
            var console_line = new ConsoleLine {
                Description_string = "For Aloysius"
            };

            // This is to test for a buug which only happens if you call GetConsoleSnippets() twice, so call it once before the main action.
            console_line.Get_console_snippets(potential_match);
            var new_description = "New " + console_line.Description_string;

            console_line.Description_string = new_description;

            // Act
            var new_result = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual(new_description, new_result[3].Text, "Description text should be updated");
        }
        public void Will_regenerate_console_snippet_if_amount_changes()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings()
            };
            var console_line = new ConsoleLine {
                Amount_string = "�.34"
            };

            // This is to test for a buug which only happens if you call GetConsoleSnippets() twice, so call it once before the main action.
            console_line.Get_console_snippets(potential_match);
            var new_amount = "New " + console_line.Amount_string;

            console_line.Amount_string = new_amount;

            // Act
            var new_result = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual($"{new_amount},", new_result[2].Text, "Amount text should be updated");
        }
        public void Will_regenerate_console_snippet_if_index_changes()
        {
            // Arrange
            var potential_match = new PotentialMatch
            {
                Rankings = new Rankings()
            };
            var console_line = new ConsoleLine {
                Index = 1
            };

            // This is to test for a buug which only happens if you call GetConsoleSnippets() twice, so call it once before the main action.
            console_line.Get_console_snippets(potential_match);
            var new_index = console_line.Index + 1;

            console_line.Index = new_index;

            // Act
            var new_result = console_line.Get_console_snippets(potential_match);

            // Assert
            Assert.AreEqual($"{new_index}. ", new_result[0].Text, "Index text should be updated");
        }
        private static void Add_set_of_overlapping_matches(
            Random random_number_generator,
            ICSVFile <BankRecord> owned_file,
            List <IPotentialMatch> result,
            int num_matches)
        {
            var unmatched_records = owned_file.Records.Where(x => !x.Matched).ToList();
            var max_rand          = unmatched_records.Count - 1;

            if (max_rand >= 0)
            {
                var new_match = new PotentialMatch
                {
                    Actual_records = new List <ICSVRecord>(),
                    Console_lines  = new List <ConsoleLine>(),
                    Rankings       = new Rankings {
                        Amount = 0, Date = 0, Combined = 0
                    },
                    Amount_match       = true,
                    Full_text_match    = true,
                    Partial_text_match = true
                };
                for (int count = 1; count <= num_matches; count++)
                {
                    if (max_rand >= 0)
                    {
                        var random_index = random_number_generator.Next(0, max_rand);
                        var next_record  = unmatched_records[random_index];
                        new_match.Actual_records.Add(next_record);
                        new_match.Console_lines.Add(next_record.To_console());
                        unmatched_records.Remove(next_record);
                        max_rand--;
                    }
                }
                result.Add(new_match);
            }
        }