public void ShouldKnowHowToAddStaticPagesToTheViewBag() { var documentSession = new Mock <IDocumentSession>(); documentSession.Setup(session => session.SaveChanges()); var documentStore = new Mock <IDocumentStore>(); documentStore.Setup(store => store.OpenSession()).Returns(documentSession.Object); var repository = new Mock <Repository>(); var savedPages = new List <StaticPage> { new StaticPage { Id = 1, Title = "test title", Content = "Hello\n=====\nWorld" }, new StaticPage { Id = 2, Title = "test title2", Content = "Hello\n=====\nAnother World" } }; repository.Setup(repo => repo.List <StaticPage>()).Returns(savedPages); var controller = new TestBaseController(repository.Object, documentStore.Object); repository.Verify(repo => repo.List <StaticPage>(), Times.Never()); controller.OnActionExecuting(null); var _actual = (List <StaticPage>)controller.ViewBag.StaticPages; Assert.AreEqual(savedPages.Count(), _actual.Count()); Assert.AreEqual(savedPages.First(), _actual.First()); Assert.AreEqual(savedPages.Last(), _actual.Last()); repository.Verify(repo => repo.List <StaticPage>(), Times.Once()); }
public void ShouldKnowToOpenSessionOnActionExecuting() { var documentSession = new Mock <IDocumentSession>(); documentSession.Setup(session => session.SaveChanges()); var documentStore = new Mock <IDocumentStore>(); documentStore.Setup(store => store.OpenSession()).Returns(documentSession.Object); var testBaseController = new TestBaseController(null, documentStore.Object); testBaseController.OnActionExecuting(null); documentStore.Verify(store => store.OpenSession(), Times.Once()); }
public void ShouldKnowToSaveChangesOnActionExecuted() { var documentSession = new Mock <IDocumentSession>(); var documentStore = new Mock <IDocumentStore>(); documentStore.Setup(store => store.OpenSession()).Returns(documentSession.Object); var testBaseController = new TestBaseController(null, documentStore.Object); testBaseController.OnActionExecuting(null); var actionExecutedContext = new Mock <ActionExecutedContext>(); actionExecutedContext.SetupGet(context => context.IsChildAction).Returns(false); actionExecutedContext.Object.Exception = null; testBaseController.OnActionExecuted(actionExecutedContext.Object); documentSession.Verify(session => session.SaveChanges(), Times.Once()); }