예제 #1
0
 public void ExecuteCommand(ICatalog catalog, ICommand command, StringBuilder output)
 {
     switch (command.Type)
     {
         case CommandType.AddBook:
             var book = new ContentItem(ContentItemType.Book, command.Parameters);
             catalog.Add(book);
             output.AppendLine("Book Added");
             break;
         case CommandType.AddMovie:
             var movie = new ContentItem(ContentItemType.Movie, command.Parameters);
             catalog.Add(movie);
             output.AppendLine("Movie added");
             break;
         case CommandType.AddSong:
             var song = new ContentItem(ContentItemType.Song, command.Parameters);
             catalog.Add(song);
             output.AppendLine("Song added");
             break;
         case CommandType.AddApplication:
             var application = new ContentItem(ContentItemType.Application, command.Parameters);
             catalog.Add(application);
             output.AppendLine("Application added");
             break;
         case CommandType.Update:
             ProcessUpdateCommand(catalog, command, output);
             break;
         case CommandType.Find:
             ProcessFindCommand(catalog, command, output);
             break;
         default:
             throw new InvalidOperationException("Unknown command!");
     }
 }
예제 #2
0
 public void TestMethodAddSingleItem()
 {
     var catalog = new Catalog();
     string[] item = {
                        "Intro C#", 
                        "S.Nakov", 
                        "12763892", 
                        "http://www.introprogramming.info"
                        };
     var book = new ContentItem(ContentItemType.Book, item);
     catalog.Add(book);
     Assert.AreEqual(catalog.Count(), 1);
 }
예제 #3
0
 public void TestMethodAddAndCheckContent()
 {
     var catalog = new Catalog();
     string[] book = {
                        "Intro C#", 
                        "S.Nakov", 
                        "12763892", 
                        "http://www.introprogramming.info"
                        };
     var item = new ContentItem(ContentItemType.Book, book);
     catalog.Add(item);
     var restult = catalog.GetListContent("Intro C#", 1);
     Assert.AreEqual(restult.Count(), 1);
     Assert.AreSame(restult.First(), item);
 }
예제 #4
0
        public void TestMethodAddDuplicatedItemsWithSameValues()
        {
            var catalog = new Catalog();
            string[] book = {
                               "Intro C#", 
                               "S.Nakov", 
                               "12763892", 
                               "http://www.introprogramming.info"
                               };

            var item1 = new ContentItem(ContentItemType.Book, book);
            catalog.Add(item1);
            catalog.Add(item1);
            var restult = catalog.GetListContent("Intro C#", 5);
            Assert.AreEqual(restult.Count(), 2);

        }
예제 #5
0
        public void TestMethodAddMultipleItems()
        {
            var catalog = new Catalog();
            var book = new ContentItem(ContentItemType.Book, new string[] {
                               "Intro C#","S.Nakov","12763892","http://www.introprogramming.info"});


            var movie = new ContentItem(ContentItemType.Movie, new string[] {
                               "The Secret","Sean Byrne & others (2006)","832763834","http://thesecret/movies/avi"});


            var song = new ContentItem(ContentItemType.Song, new string[] {
                               "The Secret Song","Sean Byrne & others (2006)","832763834","http://thesecret/songs/mp3"});

            catalog.Add(book);
            catalog.Add(movie);
            catalog.Add(song);
            Assert.AreEqual(catalog.Count(), 3);
        }
예제 #6
0
        public void TestMethodGetListContentCheckOrder()
        {
            var catalog = new Catalog();

            var book1 = new ContentItem(ContentItemType.Book, new string[] {
                               "Intro C#" ,"S.Nakov","12763892","http://www.introprogramming.info"});
            var book2 = new ContentItem(ContentItemType.Book, new string[] {
                               "Intro C#" ,"Author","12763892","http://www.introprogramming.info"});
            var book3 = new ContentItem(ContentItemType.Book, new string[] {
                               "Intro C#" ,"Xray","12763892","http://www.introprogramming.info"});
            var book4 = new ContentItem(ContentItemType.Book, new string[] {
                               "Intro C#" ,"Author","127623892","http://www.introprogramming.info"});

            catalog.Add(book1);
            catalog.Add(book2);
            catalog.Add(book3);
            catalog.Add(book4);

            var result = catalog.GetListContent("Intro C#", 10);
            Assert.AreEqual(result.Count(), 4);

            var expected = new string[] {"Book: Intro C#; Author; 127623892; http://www.introprogramming.info",
"Book: Intro C#; Author; 12763892; http://www.introprogramming.info",
"Book: Intro C#; S.Nakov; 12763892; http://www.introprogramming.info",
"Book: Intro C#; Xray; 12763892; http://www.introprogramming.info"};

            var actual = new string[]{
                result.First().ToString(),
                result.Skip(1).First().ToString(), 
                 result.Skip(2).First().ToString(), 
                result.Skip(3).First().ToString()
            };

            CollectionAssert.AreEqual(expected, actual);
        }
예제 #7
0
        public void TestMethodGetListContentManyMatchingItemsGetFirstOnly()
        {
            var catalog = new Catalog();

            var book1 = new ContentItem(ContentItemType.Book, new string[] {
                               "Intro C#" ,"S.Nakov","12763892","http://www.introprogramming.info"});
            var book2 = new ContentItem(ContentItemType.Book, new string[] {
                               "Intro C++" ,"S.Nakov","12763892","http://www.introprogramming.info"});
            var book3 = new ContentItem(ContentItemType.Book, new string[] {
                               "Intro Java" ,"S.Nakov","12763892","http://www.introprogramming.info"});
            var book4 = new ContentItem(ContentItemType.Book, new string[] {
                               "Intro C#" ,"Author","127623892","http://www.introprogramming.info"});

            catalog.Add(book1);
            catalog.Add(book2);
            catalog.Add(book3);
            catalog.Add(book4);

            var result = catalog.GetListContent("Intro C#", 1);
            Assert.AreEqual(result.Count(), 1);
        }
예제 #8
0
        public void TestMethodAdd50kItems()
        {
            var catalog = new Catalog();
            for (int i = 0; i < 10000; i++)
            {
                var book = new ContentItem(ContentItemType.Book, new string[] {
                               "Intro C#" + i,"S.Nakov","12763892","http://www.introprogramming.info"});
                catalog.Add(book);
            }

            Assert.AreEqual(catalog.Count(), 10000);
        }