Пример #1
0
        public void Given_OneNote_When_ViewingIndex_Then_OneNoteIsDisplayed()
        {
            db.Setup(x => x.Notes).Returns(new MockDbSet<Note>()
                { new Note()
                });
            var noteController = new NoteController(db.Object);

            var viewResult = (ViewResult)noteController.Index();

            var model = (IEnumerable<Note>)viewResult.Model;
            Assert.AreEqual(1, model.Count());
        }
Пример #2
0
        public void Given_TwoNotes_When_ViewingIndex_Then_NotesAreOrderedByDateDescending()
        {
            db.Setup(x => x.Notes).Returns(new MockDbSet<Note>()
                { new Note() { CreateDate = new DateTime(2011, 01, 01) },
                  new Note() { CreateDate = new DateTime(2011, 02, 02) }
                });
            var noteController = new NoteController(db.Object);

            var viewResult = (ViewResult)noteController.Index();

            var model = (IEnumerable<Note>)viewResult.Model;
            Assert.AreEqual(2, model.Count());
            Assert.AreEqual(new DateTime(2011, 02, 02), model.First().CreateDate);
            Assert.AreEqual(new DateTime(2011, 01, 01), model.ElementAt(1).CreateDate);
        }