Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var path = args.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x));

            System.Console.WriteLine($"Processing file {path}");
            if (File.Exists(path))
            {
                using (var context = new AppDataContext(path))
                {
                    var contactDomain = new ContactDomain();
                    var addressDomain = new AddressDomain();
                    IEnumerable <KeyValuePair <int, string> > contacts = contactDomain.GetSortedListByNamesAndFrequency(context);
                    IEnumerable <string> addresses = addressDomain.SortByStreetAndFrequency(context);

                    System.Console.WriteLine($"{contacts.Count()} Names extracted");
                    System.Console.WriteLine($"{addresses.Count()} Addresses extracted");
                    System.Console.WriteLine($"Exporting to {Path.GetDirectoryName(path)}");

                    contactDomain.ExportToFile(contacts, Path.Combine(Path.GetFullPath(path), "contacts.txt"));
                    addressDomain.ExportToFile(addresses, Path.Combine(Path.GetFullPath(path), "addresses.txt"));
                    System.Console.WriteLine($"Exporting done, press any key");
                    System.Console.ReadKey();
                }
            }
        }
Exemplo n.º 2
0
        public void TestGetSortedListByNamesAndFrequency()
        {
            var domain  = new ContactDomain();
            var context = new Mock <AppDataContext>();

            context.SetupGet(x => x.Contacts)
            .Returns(() =>
            {
                return(new Repository <Contact>(new List <Contact>()
                {
                    new Contact {
                        FirstName = "John", LastName = "Doe"
                    },
                    new Contact {
                        FirstName = "Peter", LastName = "Botha"
                    },
                    new Contact {
                        FirstName = "Sarie", LastName = "Coetzee"
                    },
                    new Contact {
                        FirstName = "Gerrit", LastName = "de Bruin"
                    },
                    new Contact {
                        FirstName = "Jan", LastName = "vd Merwe"
                    },
                    new Contact {
                        FirstName = "Sarel", LastName = "Doe"
                    },
                    new Contact {
                        FirstName = "Koos", LastName = "Smith"
                    },
                    new Contact {
                        FirstName = "Sannie", LastName = "Smith"
                    }
                }));
            });
            IEnumerable <KeyValuePair <int, string> > result = domain.GetSortedListByNamesAndFrequency(context.Object);

            Assert.IsNotNull(result);
            CollectionAssert.AllItemsAreUnique(result.ToList());
            Assert.IsTrue(result.Any(), "Returned No Resultes");
            Assert.IsTrue(result.Count() == 14, "Result count mismatch");
            Assert.IsTrue(result.First().Key == 2, "First element count mismatch");
            Assert.IsTrue(result.First().Value == "Doe", "First element last name mismatch");
            Assert.IsTrue(result.Last().Key == 1, "Last element count mismatch");
            Assert.IsTrue(result.Last().Value == "vd Merwe", "Last element last name mismatch");
        }