public void ProcessCommand_CustomerNotExists()
 {
     StringWriter output = new StringWriter();
     ModelStore model = ModelMockup();
     Viewer view = new Viewer(output);
     Controller control = new Controller(model, view);
     try {
         control.ProcessCommand("GET 5 http://www.nezarka.net/Books");
         Assert.Fail("Expected exception was not thrown.");
     }
     catch(Exception ex) {
         Assert.AreEqual("Customer doesn't exists.", ex.Message);
     }
 }
 public void ProcessCommand_HTTPBooksDetailIsWrong2()
 {
     StringWriter output = new StringWriter();
     ModelStore model = ModelMockup();
     Viewer view = new Viewer(output);
     Controller control = new Controller(model, view);
     try {
         control.ProcessCommand("GET 1 http://www.nezarka.net/Books/Detaill/1");
         Assert.Fail("Expected exception was not thrown.");
     }
     catch(Exception ex) {
         Assert.AreEqual("Books HTTP address is wrong.", ex.Message);
     }
 }
        public void AddBook_NewBook()
        {
            StringWriter output = new StringWriter();
            ModelStore model = ModelMockup();
            Viewer view = new Viewer(output);
            Controller control = new Controller(model, view);

            Customer c = model.GetCustomer(2);
            Book b = model.GetBook(2);

            control.AddBook(c, b);

            Assert.AreEqual(model.GetCustomer(2).ShoppingCart.Items.Find(itm => itm.BookId == b.Id).Count, 1);
        }
        public void RemoveBook_NotExistingBook()
        {
            StringWriter output = new StringWriter();
            ModelStore model = ModelMockup();
            Viewer view = new Viewer(output);
            Controller control = new Controller(model, view);

            Customer c = model.GetCustomer(2);
            Book b = model.GetBook(2);

            try {
                control.RemoveBook(c, b);
                Assert.Fail("Expected exception was not thrown.");
            }
            catch(Exception ex) {
                Assert.AreEqual("Book doesn't exist in Customers ShoppingCart.", ex.Message);
            }
        }
 public void ProcessCommand_NotGet()
 {
     StringWriter output = new StringWriter();
     ModelStore model = ModelMockup();
     Viewer view = new Viewer(output);
     Controller control = new Controller(model, view);
     try {
         control.ProcessCommand("POST 1 http://www.nezarka.net/Books");
         Assert.Fail("Expected exception was not thrown.");
     }
     catch(Exception ex) {
         Assert.AreEqual("Not a GET request.", ex.Message);
     }
 }
 public void ProcessCommand_IncorrectLength()
 {
     StringWriter output = new StringWriter();
     ModelStore model = ModelMockup();
     Viewer view = new Viewer(output);
     Controller control = new Controller(model,view);
     try {
         control.ProcessCommand("GET http://www.nezarka.net/Books");
         Assert.Fail("Expected exception was not thrown.");
     }
     catch(Exception ex) {
         Assert.AreEqual("Command length wrong.", ex.Message);
     }
 }
Esempio n. 7
0
        /// <summary> Main function which handles Loading from input and processing to output </summary>
        /// <param name="args">Program arguments.</param>
        /// <param name="stdIn">Input stream object.</param>
        /// <param name="stdOut">Output stream object.</param>
        public static void Run(string[] args, TextReader stdIn, TextWriter stdOut)
        {
            ModelStore store = ModelStore.LoadFrom(stdIn);

            if(store == null) {
                stdOut.Write("Data error.");
                return;
            }

            Viewer view = new Viewer(stdOut);
            Controller controller = new Controller(store, view);
            controller.ProcessAllCommands(stdIn);
        }