This project is read-only.

Why local variables are reset after every scenario step?

Feb 16, 2011 at 4:19 PM
Edited Feb 16, 2011 at 5:22 PM

This is my code      

using System.Web.Mvc;
        public void ShowTheListOfCategories()
            FakeCategoryRepository repo = new FakeCategoryRepository();
            List<string> startingList = new List<string>() { 
                "Category 1", "Category 2", "Category 3" };

            ViewResult result = new ViewResult(); 

            new Story("Category Specs")
                .InOrderTo("use Categories")
                .IWant("to get Category list")
                    .WithScenario("Show the list of Categories")
                               repo, startingList)
                        .When(IGoToTheWebPage___, "/Category", repo, result)
                        .Then(IMustGetTheFollowingElements__, startingList, result)

        private void IGoToTheWebPage___(
            string webPage, FakeCategoryRepository r, ViewResult result)
            CategoryController controller =
                new CategoryController(r);

            result = controller.Index() as ViewResult;
            Assert.IsNotNull(result, "Should have returned a ViewResult");
            Assert.IsNotNull(result.Model, "Model must not be null");

        private void IMustGetTheFollowingElements__(List<string> expected, ViewResult result)
            List<Category> model = result.Model as List<Category>;

            foreach (var d in expected)
                Assert.IsNotNull(model.First(c => c.Description == d));

Why after returning from IGoToTheWebPage__ method, result variable is set to new ViewResult()?
I've noticed strange thing, this resetting happens only to ViewResult variables, variables of other types aren't reset.