Пример #1
1
        public void Home_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");
            mapper.Setup(x => x.ControllerHasAction("Dummy", "myaction")).Returns(true);
            container.Setup(x => x.GetInstance<IDocumentSession>()).Returns(_store.OpenSession());

            mapper.Setup(m => m.ControllerHasAction("Content", "myaction")).Returns(true);

            // Act
            IPathData data;
            using (var session = _store.OpenSession()) {
                // create and store a new page model
                var pageModel = new DummyModel { 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("Dummy", data.Controller);
        }
Пример #2
0
        public void Home_Page_With_Custom_Action(string virtualUrl)
        {
            // Arrange
            var pathData = new PathData();
            var pageModel = new DummyModel();

            var repository = new Mock<IPageRepository>();
            var mapper = new Mock<IControllerMapper>();
            var container = new Mock<IContainer>();

            container.Setup(x => x.GetInstance<IPageRepository>()).Returns(repository.Object);
            repository.Setup(x => x.SingleOrDefault<IPageModel>(model => model.Parent == null)).Returns(pageModel);
            mapper.Setup(x => x.GetControllerName(typeof(DummyController))).Returns("Dummy");
            mapper.Setup(x => x.ControllerHasAction("Dummy", "myaction")).Returns(true);

            mapper.Setup(m => m.ControllerHasAction("Content", "myaction")).Returns(true);

            var resolver = new PathResolver(pathData, repository.Object, mapper.Object, container.Object);

            // Act
            var data = resolver.ResolvePath(virtualUrl);

            // Assert
            Assert.NotNull(data);
            Assert.AreEqual("myaction", data.Action);
            Assert.AreEqual("Dummy", data.Controller);
        }
Пример #3
0
        public void Page_With_Custom_Action(string virtualUrl)
        {
            // Arrange
            var pathData = new PathData();
            var pageModel = new DummyModel();

            var repository = new Mock<IPageRepository>();
            var mapper = new Mock<IControllerMapper>();
            var container = new Mock<IContainer>();

            container.Setup(x => x.GetInstance<IPageRepository>()).Returns(repository.Object);
            repository.Setup(r => r.GetPageByUrl<IPageModel>("page")).Returns(pageModel);
            mapper.Setup(x => x.GetControllerName(typeof(DummyController))).Returns("Dummy");

            var resolver = new PathResolver(pathData, repository.Object, mapper.Object, container.Object);

            // Act
            var data = resolver.ResolvePath(virtualUrl);

            // Assert
            Assert.NotNull(data);
            Assert.AreEqual("myaction", data.Action);
            Assert.AreEqual("Dummy", data.Controller);
        }
Пример #4
0
        public void Page_With_Default_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", "index")).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("index", 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);
        }
        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());

            // Act
            IPathData data;

            using (var session = _store.OpenSession()) {

                var content = new StandardPage();
                session.Store(content);

                // create and store a new page model
                var pageModel = new PageModel { Parent = null, ContentReference = content.Id };
                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);
        }