Beispiel #1
0
        public void TestMethod1()
        {
            var db = new Mock <IDataBase>();

            db
            .Setup(z => z.GetDepartments())
            .Returns(new List <Department>
            {
                new Department {
                    Name = "a"
                },
                new Department {
                    Name = "b"
                },
                new Department {
                    Name = "ab"
                }
            });

            var index = new TestableController(db.Object);
            var list  = ((index.Index("a") as ViewResult).Model as IEnumerable <Department>).ToArray();

            Assert.AreEqual(2, list.Length);
            Assert.AreEqual("a", list[0].Name);
            Assert.AreEqual("ab", list[1].Name);
        }
Beispiel #2
0
        public void TestMethod1()
        {
            var db         = new TestDataBase();
            var index      = new TestableController(db);
            var viewResult = index.Index("a");

            Assert.IsInstanceOfType(viewResult, typeof(ViewResult));
            var view = viewResult as ViewResult;

            Assert.IsInstanceOfType(view.Model, typeof(IEnumerable <Department>));
            var model = view.Model as IEnumerable <Department>;
            var list  = model.ToArray();

            Assert.AreEqual(2, list.Length);
            Assert.AreEqual("a", list[0].Name);
            Assert.AreEqual("ab", list[1].Name);
        }