Run() private method

private Run ( dynamic, page, object controller ) : void
page dynamic,
controller object
return void
Esempio n. 1
0
    public void Default_Post()
    {
        dynamic page = new MockGet(new string[] { "/" });

        Mvc.Run(page, new PageController());
        Assert_ShowDefaultPage(page);
    }
Esempio n. 2
0
        public static Config.Config InitApp(HttpConfiguration httpConfig, Service.Config.Config config = null)
        {
            XmlConfigurator.Configure();
            GlobalContext.Properties["Version"] = typeof(MainController).Assembly.GetName().Version;

            config = config ?? ReadConfig();
            if (config.Environment == "Development")
            {
                new Development().Run(config);
            }
            else
            {
                new Production().Run(config);
            }

            //в тестах мы можем запустить две копии приложения
            if (SessionFactory == null)
            {
                var nhibernate = new Config.Initializers.NHibernate();
                nhibernate.Init();
                SessionFactory = nhibernate.Factory;
            }
            ReadDbConfig(config);
            var mvc = new Mvc();

            mvc.Run(httpConfig, SessionFactory, config);
            new Config.Initializers.SmartOrderFactory().Init(SessionFactory);

            return(config);
        }
Esempio n. 3
0
    public void Edit_Post_Update()
    {
        dynamic data = new ExpandoObject();

        data.Id = "id";

        dynamic model = new Mock();

        model.Setup("Update", new object[] { It.Is <dynamic>(item => item.Id == "id") }, model);
        model.SetupGet("Value", data);
        model.SetupGet("HasError", false); //this bypasses validation

        var form = new NameValueCollection();

        form["OldId"] = "id";

        dynamic page = new MockPost(new string[] { "Pages", "Edit" }, form);

        page.Response.Setup("Redirect", new object[] { "~/Pages/List", false });

        var controller = new PageController();

        controller.Model = model;

        Mvc.Run(page, controller);

        Assert.AreEqual("~/Pages/id", page.Page.Redirect); // redirect
        model.Verify();
    }
Esempio n. 4
0
    public void Create_Post()
    {
        dynamic data = new ExpandoObject();

        data.Id = "new-page";

        dynamic model = new Mock();

        model.Setup("Create", new object[] { It.Is <dynamic>(item => item.Title == "new page") }, model);
        model.SetupGet("Value", data);
        model.SetupGet("HasError", false);

        var form = new NameValueCollection();

        form["title"] = "new page";

        dynamic page       = new MockPost(new string[] { "Pages", "Create" }, form);
        var     controller = new PageController();

        controller.Model = model;

        Mvc.Run(page, controller);

        Assert.AreEqual("~/Pages/new-page", page.Page.Redirect);
        model.Verify();
    }
Esempio n. 5
0
    public void Create_Post_Should_Handle_Error()
    {
        dynamic data = new ExpandoObject();

        data.Id = "id";

        dynamic model = new Mock();

        model.Setup("Create", new object[] { It.Is <dynamic>(item => item.Title == "new page") }, model);
        model.SetupGet("Value", data);
        model.SetupGet("HasError", true); // this raises validation error
        model.SetupGet("Errors", "x");

        var form = new NameValueCollection();

        form["title"] = "new page";

        dynamic page       = new MockPost(new string[] { "Pages", "Create" }, form);
        var     controller = new PageController();

        controller.Model = model;

        Mvc.Run(page, controller);

        Assert.AreEqual("~/Views/Pages/_Page_Create.cshtml", page.Page.View); // stayed on create page
        Assert.AreEqual("x", page.Page.Model.Errors);                         // pushed error messages
        model.Verify();
    }
Esempio n. 6
0
    public void Edit_Post_Should_Handle_Error()
    {
        dynamic data = new ExpandoObject();

        data.Id = "id";

        dynamic model = new Mock();

        model.Setup("Update", new object[] { It.Is <dynamic>(item => item.Id == "id") }, model);
        model.SetupGet("Value", data);
        model.SetupGet("HasError", true); // this raises validation error
        model.SetupGet("Errors", "x");

        var form = new NameValueCollection();

        form["OldId"] = "id";

        dynamic page       = new MockPost(new string[] { "Pages", "Edit", "id" }, form);
        var     controller = new PageController();

        controller.Model = model;

        Mvc.Run(page, controller);

        var view = SiteEngine.RunHook("GET_Pages_Page_Edit_View", page.Page.View) as string;

        Assert.AreEqual(view, page.Page.View);        //stayed on edit page
        Assert.AreEqual("x", page.Page.Model.Errors); // pushed error message
        model.Verify();
    }
Esempio n. 7
0
    public void Edit_Post_SaveAs()
    {
        dynamic data = new ExpandoObject();

        data.Id = "new-id";

        dynamic model = new Mock();

        model.Setup("SaveAs", new object[] { It.Is <dynamic>(item => item.Id == "old-id"), "new-id" }, model);
        model.SetupGet("Value", data);
        model.SetupGet("HasError", false); //this bypasses validation
        model.Setup("Load", new object[] { It.Is <dynamic>(item => item.Id == "new-id") }, model);
        model.SetupGet("Value", data);

        var form = new NameValueCollection();

        form["OldId"] = "old-id";
        form["Id"]    = "new-id";

        dynamic page       = new MockPost(new string[] { "Pages", "Edit", "id" }, form);
        var     controller = new PageController();

        controller.Model = model;

        Mvc.Run(page, controller);
        Assert.AreEqual("~/Pages/new-id", page.Page.Redirect);
    }
Esempio n. 8
0
    public void Edit_Wrong_Id_Shoud_Goto_Create()
    {
        dynamic page = new MockGet(new string[] { "Pages", "Edit", "id" });

        Mvc.Run(page, new PageController());
        Assert.AreEqual("~/Pages/Create", page.Page.Redirect);
    }
Esempio n. 9
0
    [ExpectedException(typeof(Exception))] //delete through GET should not be allowed
    public void Get_Delete()
    {
        dynamic webPage    = new MockGet(new string[] { "Mock", "Delete", "y", "z" });
        dynamic controller = new MockController();

        Mvc.Run(webPage, controller);
        controller.Verify();
    }
Esempio n. 10
0
    public void Post_Delete()
    {
        dynamic webPage    = new MockPost(new string[] { "Mock", "Delete", "y", "z" }, null);
        dynamic controller = new MockController();

        Mvc.Run(webPage, controller);
        Assert.AreEqual("y/z", controller.Id);
        controller.Verify();
    }
Esempio n. 11
0
    public void Routing_Post()
    {
        dynamic webPage    = new MockPost(new string[] { "Mock", "a", "b", "c" }, null);
        dynamic controller = new MockController();

        Mvc.Run(webPage, controller);
        Assert.IsTrue(controller.Post_Called);
        controller.Verify();
    }
Esempio n. 12
0
    public void Get_Edit_Pass_String()
    {
        dynamic webPage    = new MockGet(new string[] { "Mock", "Edit", "y", "z" });
        dynamic controller = new MockController();

        Mvc.Run(webPage, controller);
        Assert.AreEqual("y/z", controller.Id);
        controller.Verify();
    }
Esempio n. 13
0
    public void Routing_Get()
    {
        dynamic webPage    = new MockGet(new string[] { "Mock", "a", "1", "2" });
        dynamic controller = new MockController();

        Mvc.Run(webPage, controller);
        Assert.IsTrue(controller.Get_Called);
        controller.Verify();
    }
Esempio n. 14
0
    public void Create_Get()
    {
        dynamic page = new MockGet(new string[] { "Pages", "Create", "id" });

        Mvc.Run(page, new PageController());

        Assert.AreEqual("~/Views/Pages/_Page_Create.cshtml", page.Page.View);
        Assert.IsTrue(page.Page.Model.Id == null);
        Assert.AreEqual("[New Page]", page.Page.Model.Title);
    }
Esempio n. 15
0
    public void Routing_All()
    {
        dynamic webPage    = new MockGet(new string[] { "Mock", "x", "y", "z" });
        dynamic controller = new MockController();

        Mvc.Run(webPage, controller);
        Assert.IsTrue(controller.All_Called);
        Assert.AreEqual("y", controller.UrlData[1]);
        Assert.AreEqual("z", controller.UrlData[2]);
        controller.Verify();
    }
Esempio n. 16
0
    public void RenderView_Should_Get_Calling_Function_Name_As_View()
    {
        var webPage = new MockGet(new string[] { "Test", "List" });

        var controller = new TestController();

        Mvc.Run(webPage, controller);

        Assert.AreEqual("~/Views//__List.cshtml", webPage.Page.View);

        webPage.Verify();
    }
Esempio n. 17
0
    public void Delete_Post()
    {
        dynamic model = new Mock();

        model.Setup("Delete", new object[] { It.Is <dynamic>(item => item.Id == "id") }, null);
        dynamic page       = new MockPost(new string[] { "Pages", "Delete", "id" }, null); //get id from url
        var     controller = new PageController();

        controller.Model = model;
        Mvc.Run(page, controller);
        model.Verify();
        Assert.AreEqual("~/Pages/List", page.Page.Redirect);
    }
Esempio n. 18
0
    public void Post_Edit_Pass_Form()
    {
        dynamic webPage = new MockPost(new string[] { "Mock", "Edit", "y", "z" }, null);

        webPage.Request.TestValue = -20.3m;

        dynamic controller = new MockController();

        Mvc.Run(webPage, controller);

        Assert.AreEqual("y/z", controller.Id);
        Assert.AreEqual(-20.3m, controller.TestValue);

        controller.Verify();
    }
Esempio n. 19
0
    public void List_Should_Use_PageSize()
    {
        dynamic model = new Mock();

        model.Setup("List", new object[] { 5, 30 }, model);
        model.SetupGet("Value", new ExpandoObject());

        dynamic page       = new MockGet(new string[] { "Pages", "List", "5", "30" });
        var     controller = new PageController();

        controller.Model = model;
        Mvc.Run(page, controller);
        Assert.AreEqual("~/Views/Pages/_Page_List.cshtml", page.Page.View);
        model.Verify();
    }
Esempio n. 20
0
    public void Edit_Get()
    {
        dynamic data = new ExpandoObject();

        data.Id = "id";
        dynamic model = new Mock();

        model.Setup("Load", new object[] { It.Is <dynamic>(item => item.Id == "id") }, model);
        model.SetupGet("Value", data);

        dynamic page       = new MockGet(new string[] { "Pages", "Edit", "id" });
        var     controller = new PageController();

        controller.Model = model;

        Mvc.Run(page, controller);
        var view = SiteEngine.RunHook("GET_Pages_Page_Edit_View", page.Page.View) as string;

        Assert.AreEqual(view, page.Page.View);
        Assert.AreEqual("id", page.Page.Model.Id);
        model.Verify();
    }
Esempio n. 21
0
    [ExpectedException(typeof(Exception))] // Get is not allowed
    public void Delete_Get()
    {
        dynamic page = new MockGet(new string[] { "Pages", "Delete", "id" });

        Mvc.Run(page, new PageController());
    }