コード例 #1
0
 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);
     }
 }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: L-S-ONG/MFF-Csharp-1
 public Controller(ModelStore model, Viewer view)
 {
     this.model = model;
     this.view  = view;
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: jakubsuchybio/MFF-Csharp
 public Controller(ModelStore model, Viewer view)
 {
     this.model = model;
     this.view = view;
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: jakubsuchybio/MFF-Csharp
        /// <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);
        }