Esempio n. 1
0
        public void Should_Convert_A_Thought_To_A_Someday()
        {
            var writeACompiler = new Thought { Name = "Write a Compiler" };

            Expect.Call(() => thoughtRepository.SaveOrUpdate(writeACompiler));
            mocks.ReplayAll();

            thoughtController.MakeASomeday(writeACompiler).AssertActionRedirect().ToAction("Process");
            mocks.VerifyAll();
        }
Esempio n. 2
0
        public ActionResult Create(Thought thoughts)
        {
            try
            {

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Esempio n. 3
0
        private Thought CreateThought()
        {
            var thought = new Thought
                              {
                                  Name = "A Thought Provoking Thought",
                                  ImageAttachment = "image1.jpg"
                              };
            repository.SaveOrUpdate(thought);

            session.Flush();
            return thought;
        }
Esempio n. 4
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 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"]);
        }
Esempio n. 6
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");
        }
        public void Should_Provide_A_List_Of_Topic_For_Creating_New_Thoughts()
        {
            List<SelectListItem> expectedListItem =
                TopicSource.Topics.ConvertAll(topic => new SelectListItem
                    {
                        Text = topic.Name,
                        Value = topic.ID.ToString()
                    });

            var thoughts = new Thought();
            var result = (ViewResult)new ThoughtController().Create();
            var redirectToRoutResult = (RedirectToRouteResult)new ThoughtController().Create(thoughts);
            //var firstTopic = ((List<SelectListItem>)result.ViewData["Topics"])[0];

            //Assert.AreEqual(expectedListItem[0].Value, firstTopic.Value);
            //Assert.AreEqual(expectedListItem[0].Text, firstTopic.Text);
            Assert.AreEqual("Index", redirectToRoutResult.RouteValues["action"]);
        }
Esempio n. 8
0
        public ActionResult Create(Thought newThought)
        {
            var topics = topicRepository.GetAll();
            newThought.Topic = topics.
                Where(topic => topic.Id == newThought.Topic.Id).First();

            if (Request != null)
            {
                HttpPostedFileBase file = Request.Files["ImageAttachment"];
                if (file.ContentLength != 0)
                {
                    int randomNumber = new Random().Next(100000, Int32.MaxValue);
                    string imgUrl = "UserContent/" + randomNumber + "-" + file.FileName;
                    file.SaveAs(Server.MapPath("~/UserContent") + "/" + randomNumber + "-" + file.FileName);
                    newThought.ImageAttachment = imgUrl;
                }
            }

            thoughtRepository.SaveOrUpdate(newThought);

            return RedirectToAction("Index");
        }
Esempio n. 9
0
        public ActionResult MakeASomeday(Thought aThoughtToDoSomeday)
        {
            aThoughtToDoSomeday.IsASomeday = true;
            thoughtRepository.SaveOrUpdate(aThoughtToDoSomeday);

            return RedirectToAction("Process");
        }
Esempio 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();
        }
Esempio n. 11
0
 public virtual bool Equals(Thought other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other.Id == Id && Equals(other.Topic, Topic) && Equals(other.Name, Name) && Equals(other.ImageAttachment, ImageAttachment) && other.IsASomeday.Equals(IsASomeday);
 }
Esempio n. 12
0
        public void Should_Download_A_File_With_Random_Number_Removed_From_Name()
        {
            var expectedThought = new Thought { ImageAttachment = "UserContent/23923-picture.jpg" };

            Expect.Call(thoughtRepository.GetAll()).Return(new List<Thought> {expectedThought});
            mocks.ReplayAll();

            var fileresult = thoughtController.Download(expectedThought.Id).
                AssertResultIs<FilePathResult>();

            //actual filename on web server
            Assert.AreEqual("~/UserContent/23923-picture.jpg", fileresult.FileName);

            //file name that user downloads
            Assert.AreEqual("picture.jpg", fileresult.FileDownloadName);
            mocks.VerifyAll();
        }
Esempio n. 13
0
        public void Should_Find_Thought_By_Name_And_Redirect_To_Details_View()
        {
            var learnCSharp = new Thought { Id = 1, Name = "Learn C# 3.5" };

            Expect.Call(thoughtRepository.GetAll()).Return(new List<Thought> { learnCSharp });
            mocks.ReplayAll();

            var routeValueDictionary = thoughtController.FindDetails("Learn C# 3.5").
                AssertActionRedirect().RouteValues;

            Assert.AreEqual("Details", routeValueDictionary["action"]);
            Assert.AreEqual(1, routeValueDictionary["id"]);
            mocks.VerifyAll();
        }
Esempio n. 14
0
        public void Should_Find_Thoughts_By_Text_Match_Case_Insensitive()
        {
            var learnCSharp = new Thought {Name = "Learn C#"};

               Expect.Call(thoughtRepository.GetAll()).Return(new List<Thought> { learnCSharp});
               mocks.ReplayAll();

               var contentResult = (ContentResult) thoughtController.Search("learn");

               Assert.AreEqual(learnCSharp.Name, contentResult.Content);

               mocks.VerifyAll();
        }