Ejemplo n.º 1
0
        public void AddOne()
        {
            Catalog catalog = new Catalog();
            string[] entryParams = { "Intro C#", "S.Nakov", "12763892", "http://www.introprogramming.info" };
            CatalogEntry entry = new CatalogEntry(Content.Book, entryParams);
            catalog.Add(entry);
            IEnumerable<IContent> searchResult = catalog.GetListContent("Intro C#", 1);

            int actualCount = searchResult.Count();

            Assert.AreEqual(1, actualCount);
        }
Ejemplo n.º 2
0
        public void Add_ExecutesOKOnDuplicates()
        {
            Catalog catalog = new Catalog();

            string commandStr = "Add movie: One; James Wong (2001); 969763002; http://www.imdb.com/title/tt0267804/";
            ICommand command = new Command(commandStr);
            ICommandExecutor executor = new CommandExecutor();

            for (int i = 0; i < 3; i++)
            {
                executor.ExecuteCommand(catalog, command, new System.Text.StringBuilder());
            }
        }
Ejemplo n.º 3
0
        public static void Main()
        {
            StringBuilder output = new StringBuilder();
            Catalog catalog = new Catalog();
            ICommandExecutor commandExecutor = new CommandExecutor();

            foreach (ICommand item in GetCommands())
            {
                commandExecutor.ExecuteCommand(catalog, item, output);
            }

            Console.Write(output);
        }
Ejemplo n.º 4
0
        public static void Main()
        {
            StringBuilder output = new StringBuilder();
            Catalog catalog = new Catalog();
            ICommandExecutor executor = new CommandExecutor();

            List<ICommand> commandsForExecution = Parse();

            foreach (ICommand item in commandsForExecution)
            {
                executor.ExecuteCommand(catalog, item, output);
            }

            //Console.BackgroundColor = ConsoleColor.DarkGreen;
            Console.Write(output);
        }
Ejemplo n.º 5
0
        public void GetListContent_MatchedEqualToRequested()
        {
            Catalog catalog = new Catalog();

            string commandStr = "Add movie: One; James Wong (2001); 969763002; http://www.imdb.com/title/tt0267804/";
            ICommand command = new Command(commandStr);
            ICommandExecutor executor = new CommandExecutor();

            for (int i = 0; i < 3; i++)
            {
                executor.ExecuteCommand(catalog, command, new System.Text.StringBuilder());
            }

            IEnumerable<IContent> result = catalog.GetListContent("One", 3);
            Assert.AreEqual(3, result.Count());
        }
Ejemplo n.º 6
0
        public void GetListContent_MatchedLessThanTheRequested()
        {
            string[] commandStrings = { "Add movie: One; James Wong (2001); 969763002; http://www.imdb.com/title/tt0267804/",
                                       "Add song: One; Metallica (2000); 734837437; http://sample.net",
                                       "Add application: Google Chrome; Chrome; 374837837; http://google.com"};

            Catalog catalog = new Catalog();
            ICommandExecutor executor = new CommandExecutor();

            foreach (string commandString in commandStrings)
            {
                ICommand command = new Command(commandString);
                executor.ExecuteCommand(catalog, command, new System.Text.StringBuilder());
            }

            IEnumerable<IContent> result = catalog.GetListContent("One", 6);
            Assert.AreEqual(2, result.Count());
        }
Ejemplo n.º 7
0
        public void AddMultipleEntries()
        {
            Catalog catalog = new Catalog();

            string[] entryParams = { "Intro C#", "S.Nakov", "12763892", "http://www.introprogramming.info" };
            CatalogEntry entry = new CatalogEntry(Content.Book, entryParams);
            catalog.Add(entry);

            AddSomeEntries(catalog, ref entryParams, ref entry);

            bool searchIsAccurate = true;
            IEnumerable<IContent> searchResult = catalog.GetListContent("One", 3);
            if (searchResult.Count() != 2)
            {
                searchIsAccurate = false;
            }

            searchResult = catalog.GetListContent("Angel Of Death", 3);
            if (searchResult.Count() != 1)
            {
                searchIsAccurate = false;
            }

            searchResult = catalog.GetListContent("EazFuscator.NET", 1);
            if (searchResult.Count() != 1)
            {
                searchIsAccurate = false;
            }

            searchResult = catalog.GetListContent("Intro C#", 40);
            if (searchResult.Count() != 1)
            {
                searchIsAccurate = false;
            }

            Assert.AreEqual(true, searchIsAccurate);
        }
Ejemplo n.º 8
0
 public void GetListContent_ThrowsExceptionOnEmptyTitle()
 {
     Catalog catalog = new Catalog();
     catalog.GetListContent("", 2);
 }
Ejemplo n.º 9
0
        public void SearchForMoreEntries()
        {
            Catalog catalog = new Catalog();

            string[] entryParams = { "Intro C#", "S.Nakov", "12763892", "http://www.introprogramming.info" };
            CatalogEntry entry = new CatalogEntry(Content.Book, entryParams);
            catalog.Add(entry);

            AddSomeEntries(catalog, ref entryParams, ref entry);

            catalog.Add(entry);
            catalog.Add(entry);
            catalog.Add(entry);
            catalog.Add(entry);
            catalog.Add(entry);
            catalog.Add(entry);
            catalog.Add(entry);
            catalog.Add(entry);
            catalog.Add(entry);

            bool searchIsAccurate = false;
            IEnumerable<IContent> searchResult = catalog.GetListContent("One", 300);

            if (searchResult.Count() == 11)
            {
                searchIsAccurate = true;
            }

            Assert.AreEqual(true, searchIsAccurate);
        }
Ejemplo n.º 10
0
 public void Add_ThrowsExceptionOnNullParameter()
 {
     Catalog catalog = new Catalog();
     catalog.Add(null);
 }
Ejemplo n.º 11
0
 public void UpdateContent_ThrowsExceptionOnNullParameter()
 {
     Catalog catalog = new Catalog();
     catalog.UpdateContent(null, "new url");
 }
Ejemplo n.º 12
0
        public void UpdateContent_Returns0OnNonExistingKeyEntry()
        {
            Catalog catalog = new Catalog();
            int updated = catalog.UpdateContent("non-existing", "another");

            Assert.AreEqual(0, updated);
        }
Ejemplo n.º 13
0
        public void UpdateContent_Returns0OnEqualUrlParams()
        {
            Catalog catalog = new Catalog();

            string commandStr = "Add movie: One; James Wong (2001); 969763002; http://www.imdb.com/title/tt0267804/";
            ICommand command = new Command(commandStr);

            ICommandExecutor executor = new CommandExecutor();
            executor.ExecuteCommand(catalog, command, new System.Text.StringBuilder());

            int updated = catalog.UpdateContent("http://www.imdb.com/title/tt0267804/", "http://www.imdb.com/title/tt0267804/");
            Assert.AreEqual(0, updated);
        }
Ejemplo n.º 14
0
        public void UpdateWithNoMatches()
        {
            Catalog catalog = new Catalog();
            string[] entryParams = { "Intro C#", "S.Nakov", "12763892", "http://www.introprogramming.info" };
            CatalogEntry entry = new CatalogEntry(Content.Book, entryParams);
            catalog.Add(entry);
            AddSomeEntries(catalog, ref entryParams, ref entry);

            int updated = catalog.UpdateContent("http://www.lalala.info", "http://www.introprogramming.info/en/");
            Assert.AreEqual(0, updated);
        }
Ejemplo n.º 15
0
        public void UpdateContent_OnSingleMatchingElement()
        {
            string[] commandStrings = { "Add movie: One; James Wong (2001); 969763002; http://www.imdb.com/title/tt0267804/",
                                       "Add song: One; Metallica (2000); 734837437; http://sample.net",
                                       "Add application: Google Chrome; Chrome; 374837837; http://google.com"};

            Catalog catalog = new Catalog();
            ICommandExecutor executor = new CommandExecutor();

            foreach (string commandString in commandStrings)
            {
                ICommand command = new Command(commandString);
                executor.ExecuteCommand(catalog, command, new System.Text.StringBuilder());
            }

            int updated = catalog.UpdateContent("http://google.com", "http://google.bg");
            Assert.AreEqual(1, updated);
        }
Ejemplo n.º 16
0
 public void GetListContent_ThrowsExceptionOnNegativeElementsValue()
 {
     Catalog catalog = new Catalog();
     catalog.GetListContent("Some title", -23);
 }
Ejemplo n.º 17
0
 public void GetListContent_ReturnsEmptyListOnNonExisting()
 {
     Catalog catalog = new Catalog();
     IEnumerable<IContent> result = catalog.GetListContent("some title", 5);
     Assert.AreEqual(0, result.Count());
 }
Ejemplo n.º 18
0
        public void DoubleUpdateAnEntry()
        {
            Catalog catalog = new Catalog();
            string[] entryParams = { "Intro C#", "S.Nakov", "12763892", "http://www.introprogramming.info" };
            CatalogEntry entry = new CatalogEntry(Content.Book, entryParams);
            catalog.Add(entry);

            int updated = catalog.UpdateContent("http://www.introprogramming.info", "http://www.introprogramming.info/en/");
            Assert.AreEqual(1, updated);

            updated = catalog.UpdateContent("http://www.introprogramming.info", "http://www.introprogramming.info/en/");
            Assert.AreEqual(0, updated);
        }
Ejemplo n.º 19
0
        private static void AddSomeEntries(Catalog catalog, ref string[] entryParams, ref CatalogEntry entry)
        {
            entryParams = new string[] { "One", "James Wong (2001)", "969763002", "http://www.imdb.com/title/tt0267804/" };
            entry = new CatalogEntry(Content.Movie, entryParams);
            catalog.Add(entry);

            entryParams = new string[] { "Angel Of Death", "Slayer", "365763002", "http://lalala.com" };
            entry = new CatalogEntry(Content.Song, entryParams);
            catalog.Add(entry);

            entryParams = new string[] { "EazFuscator.NET", "Kharkiv", "362268542", "http://lolerskates.com" };
            entry = new CatalogEntry(Content.Application, entryParams);
            catalog.Add(entry);

            entryParams = new string[] { "One", "James Wong (2001)", "969763002", "http://www.imdb.com/title/tt0267804/" };
            entry = new CatalogEntry(Content.Movie, entryParams);
            catalog.Add(entry);

            entryParams = new string[] { "One", "James Wong (2001)", "969763002", "http://www.imdb.com/title/tt0267804/" };
            entry = new CatalogEntry(Content.Movie, entryParams);
        }