Exemplo n.º 1
0
 public void Should_Add_Todo_Item()
 {
     var todo = new Todo {Title = "Learn mbout MVC Controller"};
     var redirectToRoutResult = (RedirectToRouteResult) new TodoController().Create(todo);
     Assert.Contains(todo, TodoSource.ThingsToBeDone);
     Assert.AreEqual("Index", redirectToRoutResult.RouteValues["action"]);
 }
Exemplo n.º 2
0
 public void Should_Edit_Todo_Item()
 {
     var editedTodo = new Todo {Title = "Get Organized"};
     var redirectToroutResult = (RedirectToRouteResult) new TodoController().Edit("Get Mike", editedTodo);
     Assert.Contains(editedTodo, TodoSource.ThingsToBeDone);
     Assert.AreEqual("Index", redirectToroutResult.RouteValues["action"]);
 }
 public ActionResult Create(Todo todo)
 {
     try
     {
         // TODO: Add insert logic here
         Todo.ThingsToBeDone.Add(todo);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Exemplo n.º 4
0
        public void Should_Add_Todo_Item()
        {
            var todo = new Todo {Title = "Learn MVC Controllers"};

            var sessionSummary = new SessionSummary();
            sessionSummary.AddedTodos.Add(todo);

            todoRepository.SaveOrUpdate(todo);
            LastCall.Repeat.Once();

            todoController.Create(todo).AssertActionRedirect().ToAction("Index");
            Assert.AreEqual(sessionSummary, todoController.Session["SessionSummary"]);
        }
Exemplo n.º 5
0
 public ActionResult Convert(Thought thought, string p)
 {
     var newTodo = new Todo
     {
         Title = thought.Name,
         Outcome = p,
         Topic = TopicSource.Topics.Find(topic=>topic.ID==thought.Topic.ID)
     };
     CreateTodo(newTodo);
     ThoughtSuroce.Thoughts.RemoveAll(thoughtToRemove =>
                                      thoughtToRemove.Name == thought.Name);
     return RedirectToAction("Process", "Thought");
 }
        public ActionResult Edit(string oldTitle, Todo item)
        {
            //try
            //{
                // TODO: Add update logic here
                Todo.ThingsToBeDone.RemoveAll(aTodo => aTodo.Title == oldTitle);
                Todo.ThingsToBeDone.Add(item);

                return RedirectToAction("Index");
            //}
            //catch
            //{
                //return View();
            //}
        }
Exemplo n.º 7
0
        public void Should_Convert_A_Thought_A_Todo()
        {
            var exeptedTodo = new Todo
                {
                    Title = "Bulid a killer web site",
                    Outcome = "Site has 100 visitors per day",
                    Topic = TopicSource.Topics[0]
                };
            var thought = new Thought {Name = "Bulid a killer web site", Topic = TopicSource.Topics[0]};

            var result = (RedirectToRouteResult) new TodoController().Convert(thought, "Site has 100 visitors per day");
            Assert.Contains(exeptedTodo, TodoSource.ThingsToBeDone);
            Assert.IsFalse(ThoughtSuroce.Thoughts.Contains(thought));
            Assert.AreEqual("Process", result.RouteValues["action"]);
            Assert.AreEqual("Thought", result.RouteValues["controller"]);
        }
Exemplo n.º 8
0
        public ActionResult Convert(Thought thought, string outcome)
        {
            var newTodo = new Todo
                              {
                                  Title = thought.Name,
                                  Outcome = outcome,
                                  Topic = topicRepository.GetAll().
                                  Where(topic => topic.Id == thought.Topic.Id).First()
                              };
            CreateTodo(newTodo);

            var loadedThought = thoughtRepository.GetAll().Where(x => x.Id == thought.Id).First();

            thoughtRepository.Delete(loadedThought);

            return RedirectToAction("Process", "Thought");
        }
Exemplo n.º 9
0
        public void PublishAsDraft(Todo todo, string token)
        {
            string xml = string.Format(
                @"<entry xmlns='http://www.w3.org/2005/Atom'>
                  <title type='text'>{0}</title>
                  <content type='xhtml'>
                  <p>Empty</p>
                  </content>
                  <app:control xmlns:app='http://purl.org/atom/app#'>
                  <app:draft>yes</app:draft>
                  </app:control>
                  </entry>", todo.Title);

            string blogFeedUri = "http://www.blogger.com/feeds/" +
                                 blogId + "/posts/default";

            HttpWebResponse response =
                WebServiceUtil.SendWebRequestWithAuthToken(blogFeedUri, xml,
                   "application/atom+xml", token);

            if (response.StatusCode != HttpStatusCode.Created)
                throw new WebException(response.StatusCode.ToString());
        }
Exemplo n.º 10
0
        public void Should_Convert_A_Thought_Into_A_Todo_And_Redirect_To_Process_Thought()
        {
            var homeTopic = new Topic { Name = "Home" };

            var todo = new Todo
                           {
                               Title = "Do Laundry",
                               Outcome = "Laundry is clean and put away",
                               Topic = homeTopic
                           };

            var thought = new Thought { Id= 22, Name = "Do Laundry", Topic = homeTopic };

            Expect.Call(topicRepository.GetAll()).Return(new List<Topic> {homeTopic});
            Expect.Call(thoughtRepository.GetAll()).Return(new List<Thought> { thought });

            todoRepository.SaveOrUpdate(todo);
            LastCall.IgnoreArguments();;

            thoughtRepository.Delete(thought);
            LastCall.IgnoreArguments();

            mocks.ReplayAll();

            var result = (RedirectToRouteResult)
                         todoController.Convert(thought, "Laundry is clean and put away");

            Assert.AreEqual("Process", result.RouteValues["action"]);
            Assert.AreEqual("Thought", result.RouteValues["controller"]);

            mocks.VerifyAll();
        }
Exemplo n.º 11
0
 private void CreateTodo(Todo newTodo)
 {
     TodoSource.ThingsToBeDone.Add(newTodo);
 }
Exemplo n.º 12
0
        private void CreateTodo(Todo todo)
        {
            repository.SaveOrUpdate(todo);
            if (Session["SessionSummary"] == null)
                Session["SessionSummary"] = new SessionSummary();

            var summary = ((SessionSummary) Session["SessionSummary"]);
            summary.AddedTodos.Add(todo);
        }
Exemplo n.º 13
0
        public void Should_Display_Errors_When_Todo_Is_Not_Valid()
        {
            var invalidTodo =
                new Todo {Title = "123456789ABCDEF123456789ABCDEF"};

            var modelState = todoController.Create(invalidTodo).AssertViewRendered().ViewData.ModelState;

            Assert.IsTrue(modelState.ContainsKey("Title length must be between 0 and 25"));
        }
Exemplo n.º 14
0
        public void Should_Create_Todo_When_Making_Ajax_Call()
        {
            var todo = new Todo {Title = "get ajax working"};

            builder.HttpContext.Request.Expect(x => x["X-Requested-With"]).Return("XMLHttpRequest");
            todoRepository.Expect(x => x.SaveOrUpdate(todo));
            mocks.ReplayAll();

            var jsonResult = (JsonResult) todoController.Create(todo);

            Assert.AreEqual(todo, jsonResult.Data);
            mocks.VerifyAll();
        }
Exemplo n.º 15
0
        public ActionResult Edit(string title, Todo todo)
        {
            try
            {
                int model = TodoSource.ThingsToBeDone.RemoveAll(x => x.Title == title);
                TodoSource.ThingsToBeDone.Add(todo);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 16
0
        public ActionResult Edit(string oldTitle, Todo item)
        {
            try
            {
                Todo itemToEdit = repository.GetAll().Where(todo => todo.Title == oldTitle).First();

                itemToEdit = item;
                repository.SaveOrUpdate(itemToEdit);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 17
0
        public void Should_Edit_Todo_Item()
        {
            var todo = new Todo { Title = "toEdit" };

            Expect.Call(todoRepository.GetAll()).Return(new List<Todo> { todo });
            Expect.Call(() => todoRepository.SaveOrUpdate(todo));
            mocks.ReplayAll();

            var redirectToRouteResult = (RedirectToRouteResult) todoController.Edit(todo.Title, todo);

            Assert.AreEqual("Index", redirectToRouteResult.RouteValues["action"]);
            mocks.VerifyAll();
        }
Exemplo n.º 18
0
        public void Should_Load_A_Todo_Item_For_Editing()
        {
            var todo = new Todo { Title = "toEdit" };

            Expect.Call(todoRepository.GetAll()).Return(new List<Todo> { todo });
            mocks.ReplayAll();

            var viewResult = (ViewResult) todoController.Edit(todo.Title);

            Assert.AreEqual(todo, viewResult.ViewData.Model);

            mocks.VerifyAll();
        }
Exemplo n.º 19
0
 public virtual bool Equals(Todo other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Completed.Equals(Completed) && Equals(other.Title, Title) && Equals(other.Outcome, Outcome) && Equals(other.Topic, Topic) && other.Id == Id;
 }