Published by volkanuzun at 6:50 PM under
public ActionResult List()
public void List_Should_Only_Pass_Approved_Posts_To_View()
IPostRepository repository = new FakePostRepository();
PostsController controller = new PostsController(repository);
var view = (ViewResult) controller.List();
var posts = view.ViewData.Model as IQueryable<Post>;
posts.ToList().ForEach(c => Assert.True(c.IsApproved == true));
Let’s goto MSDN and checkout “List<T>.ForEach()”'; according to the definition; this function performs the specified action on each element of the List<T>; and the declaration of the function is:
public void ForEach(
Basically it is taking Action as a parameter; and calling this for each element of the List. In case you are not familiar with this delegate; it is basically any function that takes a single parameter and does not return anything. Going back to my test function; I should be Asserting each element and checking if IsPublished==true or not. An Action<T> delegate could easily be c=>Assert.True(c.IsApproved==true)).
Assert.True(bool condition) is a function which returns void; and takes only 1 parameter which a condition; so I can pass this to the ForEach function and test my assumption.
I work on IdM solutions and SharePoint lately :)
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
Site Admin |
WP Themes, Adapted by Chris Blankenship
Volkan Uzun © 2013 All rights reserved.