public bool Equals(SessionSummary other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; //This Equals makes sure what's in the lists is // compared, not the reference // ReSharper disable EqualExpressionComparison if (other.AddedTodos.Count != other.AddedTodos.Count) // ReSharper restore EqualExpressionComparison return false; for (int i = 0; i < other.AddedTodos.Count; i++) { if (!other.AddedTodos[i].Equals(AddedTodos[i])) return false; } return true; }
public void Should_Add_Todo_Item() { var todo = new Todo { Title = "Learn to Use Alt-Enter" }; var sessionSummary = new SessionSummary(); sessionSummary.AddedTodos.Add(todo); var todoController = new TodoController(); var builder = new TestControllerBuilder(); builder.InitializeController(todoController); todoController.Create(todo). AssertActionRedirect().ToAction("Index"); Assert.Contains(todo, Todo.ThingsToBeDone); Assert.AreEqual(sessionSummary, todoController.Session["SessionSummary"]); var redirectToResult = (RedirectToRouteResult)new TodoController().Create(todo); Assert.Contains(todo, Todo.ThingsToBeDone); Assert.AreEqual("Index", redirectToResult.RouteValues["action"]); }
private void CreateTodo(Todo todo) { Todo.ThingsToBeDone.Add(todo); if (Session["SessionSummary"] == null) Session["SessionSummar"] = new SessionSummary(); var summary = ((SessionSummary)Session["SessionSummary"]); summary.AddedTodos.Add(todo); }