public void Home_Page_With_Default_Action(string path) { // Arrange var pathData = new PathData(); var mapper = new Mock<IControllerMapper>(); var container = new Mock<IContainer>(); mapper.Setup(x => x.GetControllerName(typeof(DummyController))).Returns("Dummy"); container.Setup(x => x.GetInstance<IDocumentSession>()).Returns(_store.OpenSession()); mapper.Setup(x => x.ControllerHasAction("Dummy", "index")).Returns(true); // Act IPathData data; using (var session = _store.OpenSession()) { // create and store a new page var pageModel = new StandardPage { Parent = null }; session.Store(pageModel); session.SaveChanges(); // try to resovle the page via the path var resolver = new PathResolver(session, pathData, mapper.Object, container.Object); data = resolver.ResolvePath(new RouteData(), path); } // Assert Assert.NotNull(data); Assert.AreEqual("index", data.Action); Assert.AreEqual("Dummy", data.Controller); }
public void Page_With_Custom_Action(string virtualUrl) { // Arrange var pathData = new PathData(); var mapper = new Mock<IControllerMapper>(); var container = new Mock<IContainer>(); mapper.Setup(x => x.GetControllerName(typeof(DummyController))).Returns("Dummy"); container.Setup(x => x.GetInstance<IDocumentSession>()).Returns(_store.OpenSession()); mapper.Setup(x => x.ControllerHasAction("Dummy", "myaction")).Returns(true); // Act IPathData data; using (var session = _store.OpenSession()) { // create and store a new page var pageModel = new StandardPage { Metadata = { Url = "page" } }; session.Store(pageModel); session.SaveChanges(); var resolver = new PathResolver(session, pathData, mapper.Object, container.Object); data = resolver.ResolvePath(new RouteData(), virtualUrl); } // Assert Assert.NotNull(data); Assert.AreEqual("myaction", data.Action); Assert.AreEqual("Dummy", data.Controller); }
//[TestCase("/myaction/")] //public void Can_Lookup_Controller_Without_ControllerType_Specified(string virtualUrl) { // // Arrange // var pathData = new PathData(); // var mapper = new Mock<IControllerMapper>(); // var container = new Mock<IContainer>(); // mapper.Setup(x => x.GetControllerName(typeof(DummyModelWithoutControllerTypeController))).Returns("DummyModelWithoutControllerType"); // mapper.Setup(x => x.ControllerHasAction("DummyModelWithoutControllerType", "myaction")).Returns(true); // container.Setup(x => x.GetInstance<IDocumentSession>()).Returns(_store.OpenSession()); // mapper.Setup(m => m.ControllerHasAction("DummyModelWithoutControllerType", "myaction")).Returns(true); // // Act // IPathData data; // using (var session = _store.OpenSession()) { // // create and store a new page model // var pageModel = new DummyModelWithoutControllerType { Parent = null }; // session.Store(pageModel); // session.SaveChanges(); // var resolver = new PathResolver(session, pathData, mapper.Object, container.Object); // data = resolver.ResolvePath(new RouteData(), virtualUrl); // } // // Assert // Assert.NotNull(data); // Assert.AreEqual("myaction", data.Action); // Assert.AreEqual("DummyModelWithoutControllerType", data.Controller); //} //[TestCase("/mypage")] public void Can_Create_Model_WithOut_Inheritance(string url) { // Arrange var pathData = new PathData(); var mapper = new Mock<IControllerMapper>(); var container = new Mock<IContainer>(); mapper.Setup(x => x.GetControllerName(typeof(DummyController))).Returns("Dummy"); mapper.Setup(x => x.ControllerHasAction("Dummy", "mypage")).Returns(true); container.Setup(x => x.GetInstance<IDocumentSession>()).Returns(_store.OpenSession()); // Act IPathData data; using (var session = _store.OpenSession()) { var siteMap = new SiteMap(); session.Store(siteMap); // create and store a new page model var page = new DummyModel(); //page.Childs.Add(new DummyModel {Metadata = { Name = "Child 1"}}); var content = new StandardPage(); session.Store(content); //page.PageReference.Id = content.Id; //var pageModel = new DummyModel(); //session.Store(pageModel); //session.SaveChanges(); var resolver = new PathResolver(session, pathData, mapper.Object, container.Object); data = resolver.ResolvePath(new RouteData(), url); } // Assert Assert.NotNull(data); }