Ejemplo n.º 1
0
 public static void InitializeCurrentTest(TestContext testContext)
 {
     _catalog = new CatalogDictionary()
     {
         new Book("1111111111111", "A", new DateTime(2000, 10, 10)),
         new Book("2222222222222", "B", new DateTime(1990, 10, 10)),
         new Book("3333333333333", "C", new DateTime(1980, 10, 10))
     };
 }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            var alan = new Author("Alan", "Cooper");
            var bob  = new Author("Bob", "Smith");

            var authorsOfFirst = new List <Author>
            {
                alan,
                bob
            };
            var authorsOfSecond = new List <Author>
            {
                alan
            };

            var catalog = new CatalogDictionary
            {
                new Book("111-1-11-111111-1", "The catcher in the rye", DateTime.Now, authorsOfFirst),
                new Book("3333333333333", "The great Gatsby", new DateTime(1987, 05, 05), authorsOfSecond),
                new Book("1111111111111", "The catcher", DateTime.Now, authorsOfFirst),
            };

            Console.WriteLine(catalog["111-1-11-111111-1".Replace("-", "")].Name);
            Console.WriteLine(catalog["1111111111111"].Name);

            Console.WriteLine("***");
            foreach (var item in catalog.GetBookByCurrentAuthor(new Author("ALAN", "COOPER")))
            {
                Console.WriteLine(item.Name);
            }
            Console.WriteLine("***");


            foreach (var item in catalog.SortBooksDescending())
            {
                Console.WriteLine(item.PublicationDate);
            }

            Console.WriteLine();

            foreach (var(author, count) in catalog.GetStatisticsOnAuthors())
            {
                Console.Write(author.FirstName + " " + author.SecondName + " ");
                Console.WriteLine(count);
                Console.WriteLine();
            }

            Console.WriteLine(catalog[0].Equals(catalog[1]));
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public void SortBooksDescending_SortedNewCollection_SortedCollectionReturned()
        {
            var newCatalog = new CatalogDictionary()
            {
                new Book("2222222222222", "B", new DateTime(1990, 10, 10)),
                new Book("1111111111111", "A", new DateTime(2000, 10, 10)),
                new Book("3333333333333", "C", new DateTime(1980, 10, 10))
            };

            var sortedCatalog = newCatalog.SortBooksDescending();

            Assert.AreEqual(_catalog[0], sortedCatalog.ToList()[0]);
            Assert.AreEqual(_catalog[1], sortedCatalog.ToList()[1]);
            Assert.AreEqual(_catalog[2], sortedCatalog.ToList()[2]);
            // Assert.IsTrue(_catalog.SequenceEqual(newCatalog, new CatalogEqualityComparer()));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Transforms the collection into a dictionary containing collections of <see cref="ICatalog"/> elements grouped by culture.
        /// </summary>
        /// <param name="collection">The collection of <see cref="ICatalog"/> to transform.</param>
        /// <returns></returns>
        public static CatalogDictionary GroupByCulture(this IEnumerable <ICatalog> collection)
        {
            // dictionary to store all groups for the culture name
            var catalogs = new CatalogDictionary();

            // group all by catalogs by the variation of the specified culture name
            foreach (var g in collection.GroupBy(r => r.Culture.Name))
            {
                // add catalogs to a list for each language group
                var list = new List <ICatalog>();

                foreach (var cat in g)
                {
                    list.Add(cat);
                }

                catalogs.Add(g.Key, list);
            }

            return(catalogs);
        }