Inheritance: MockWebPage
示例#1
0
        public void AdditionalQueryFiltersResults()
        {
            using (var store = GetDocumentStore())
            {
                store.ExecuteIndex(new Posts_ByPostCategory());

                using (var session = store.OpenSession())
                {
                    var dataQueriedFor = new MockPost {
                        Id = "posts/123", Body = "This is a test. Isn't it great? I hope I pass my test!", Category = "IT"
                    };

                    var someData = new List <MockPost>
                    {
                        dataQueriedFor,
                        new MockPost {
                            Id = "posts/234", Body = "I have a test tomorrow. I hate having a test", Category = "School"
                        },
                        new MockPost {
                            Id = "posts/3456", Body = "Cake is great.", Category = "Cooking"
                        },
                        new MockPost {
                            Id = "posts/3457", Body = "This document has the word test only once", Category = "Marketing"
                        },
                        new MockPost {
                            Id = "posts/3458", Body = "test", Category = "Test"
                        },
                        new MockPost {
                            Id = "posts/3459", Body = "test", Category = "Test"
                        }
                    };
                    someData.ForEach(session.Store);

                    session.SaveChanges();
                }

                WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    var indexName = new Posts_ByPostCategory().IndexName;

                    Assert.NotEmpty(session.Advanced
                                    .MoreLikeThis <MockPost>(new MoreLikeThisQuery
                    {
                        Query      = $"FROM INDEX '{indexName}'",
                        DocumentId = "posts/123",
                        Fields     = new[] { "Body" }
                    }).ToList());

                    Assert.Empty(session.Advanced
                                 .MoreLikeThis <MockPost>(new MoreLikeThisQuery
                    {
                        Query      = $"FROM INDEX '{indexName}' WHERE Category = 'IT'",
                        DocumentId = "posts/123",
                        Fields     = new[] { "Body" }
                    }).ToList());
                }
            }
        }
示例#2
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);
    }
示例#3
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();
    }
示例#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();
    }
示例#5
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();
    }
示例#6
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();
    }
示例#7
0
        public void AdditionalQueryFiltersResults()
        {
            using (var store = GetDocumentStore())
            {
                store.ExecuteIndex(new Posts_ByPostCategory());

                using (var session = store.OpenSession())
                {
                    var dataQueriedFor = new MockPost {
                        Id = "posts/123", Body = "This is a test. Isn't it great? I hope I pass my test!", Category = "IT"
                    };

                    var someData = new List <MockPost>
                    {
                        dataQueriedFor,
                        new MockPost {
                            Id = "posts/234", Body = "I have a test tomorrow. I hate having a test", Category = "School"
                        },
                        new MockPost {
                            Id = "posts/3456", Body = "Cake is great.", Category = "Cooking"
                        },
                        new MockPost {
                            Id = "posts/3457", Body = "This document has the word test only once", Category = "Marketing"
                        },
                        new MockPost {
                            Id = "posts/3458", Body = "test", Category = "Test"
                        },
                        new MockPost {
                            Id = "posts/3459", Body = "test", Category = "Test"
                        }
                    };
                    someData.ForEach(session.Store);

                    session.SaveChanges();
                }

                Indexes.WaitForIndexing(store);

                using (var session = store.OpenSession())
                {
                    Assert.NotEmpty(session.Query <MockPost, Posts_ByPostCategory>()
                                    .MoreLikeThis(f => f.UsingDocument(x => x.Id == "posts/123").WithOptions(new MoreLikeThisOptions
                    {
                        Fields = new[] { "Body" }
                    }))
                                    .ToList());

                    Assert.Empty(session.Query <MockPost, Posts_ByPostCategory>()
                                 .MoreLikeThis(f => f.UsingDocument(x => x.Id == "posts/123").WithOptions(new MoreLikeThisOptions
                    {
                        Fields = new[] { "Body" }
                    }))
                                 .Where(x => x.Category == "IT")
                                 .ToList());
                }
            }
        }
示例#8
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();
    }
示例#9
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();
    }
示例#10
0
        public void Can_Generate_Archive_Collection_With_Required_Month_And_Years()
        {
            IPost post              = new MockPost();
            var   mockArchives      = GetTestArchives();
            var   archiveCollection = new MockArchiveCollection(post.GetPosts());

            foreach (var archive in mockArchives)
            {
                var archiveFromCollection = archiveCollection.Single(archive);
                Assert.IsNotNull(archiveFromCollection);
            }
        }
示例#11
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);
    }
示例#12
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();
    }
        public void testTracker()
        {
            var storage = new LiteDBStorage(_testDbFilename);

            Assert.AreEqual(0, storage.TotalItems);

            var queue = new PersistentBlockingQueue(storage, new PayloadToJsonString());

            var getRequestMock  = new MockGet();
            var postRequestMock = new MockPost();

            var endpoint = new SnowplowHttpCollectorEndpoint("snowplowanalytics.com",
                                                             postMethod: new SnowplowHttpCollectorEndpoint.PostDelegate(postRequestMock.HttpPost),
                                                             getMethod: new SnowplowHttpCollectorEndpoint.GetDelegate(getRequestMock.HttpGet));

            Assert.IsFalse(tracker.Started);

            tracker.Start(new AsyncEmitter(endpoint, queue, sendLimit: 1), trackerNamespace: "testNamespace", appId: "testAppId", encodeBase64: false);

            Assert.IsTrue(tracker.Started);
            Assert.IsTrue(ensureSubjectSet(tracker));
            Assert.IsTrue(ensurePageViewsWorkGet(tracker, getRequestMock));
            Assert.IsTrue(ensureStructEventsWorkGet(tracker, getRequestMock));
            Assert.IsTrue(ensureEcommerceTransactionWorksGet(tracker, getRequestMock));
            Assert.IsTrue(ensureUnstructEventGet(tracker, getRequestMock));

            tracker.Stop();

            Assert.IsFalse(tracker.Started);

            // Restart with base64 on
            tracker.Start(new AsyncEmitter(endpoint, queue, sendLimit: 1), trackerNamespace: "testNamespace", appId: "testAppId", encodeBase64: true);

            Assert.IsTrue(tracker.Started);
            Assert.IsTrue(ensureUnstructEventGet(tracker, getRequestMock, true));
            Assert.IsTrue(ensureScreenViewWorksGet(tracker, getRequestMock, true));
            Assert.IsTrue(ensureTimingWorksGet(tracker, getRequestMock, true));
            Assert.IsTrue(ensureContextsWorkGet(tracker, getRequestMock, true));
            Assert.IsTrue(ensureSettersWorkGet(tracker, getRequestMock));

            tracker.Stop();

            Assert.IsFalse(tracker.Started);
        }
示例#14
0
        public void testPostHttpNon200Response()
        {
            var postReq = new MockPost()
            {
                StatusCode = 404
            };
            var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: HttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost));
            var payload  = new Payload();

            payload.Add("foo", "bar");

            var sendList = new List <Tuple <string, Payload> >();

            sendList.Add(Tuple.Create("0", payload));

            var sendResult = endpoint.Send(sendList);

            Assert.IsTrue(sendResult.FailureIds.Count == 1);
            Assert.IsTrue(postReq.Queries.Count == 1);
        }
示例#15
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();
    }
示例#16
0
        public void testPostHttpGood()
        {
            var postReq  = new MockPost();
            var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: HttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost));
            var payload  = new Payload();

            payload.Add("foo", "bar");

            var sendList = new List <Tuple <string, Payload> >();

            sendList.Add(Tuple.Create("0", payload));

            var sendResult = endpoint.Send(sendList);

            Assert.IsTrue(sendResult.SuccessIds.Count == 1);
            Assert.IsTrue(postReq.Queries.Count == 1);
            Assert.AreEqual(@"https://somewhere.com/com.snowplowanalytics.snowplow/tp2", postReq.Queries[0].Uri);

            var actual        = postReq.Queries[0].PostData;
            var expectedRegex = new Regex("{\\\"schema\\\":\\\"iglu:com\\.snowplowanalytics\\.snowplow/payload_data/jsonschema/1-0-4\\\",\\\"data\\\":\\[{\\\"foo\\\":\\\"bar\\\",\\\"stm\\\":\\\"[0-9]{13}\\\"}\\]}");

            Assert.IsTrue(expectedRegex.Match(actual).Success, String.Format("{0} doesn't match {1}", actual, expectedRegex.ToString()));
        }
示例#17
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();
    }
示例#18
0
文件: MvcTest.cs 项目: yysun/Rabbit
 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();
 }
示例#19
0
文件: MvcTest.cs 项目: yysun/Rabbit
 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();
 }
示例#20
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();
    }
示例#21
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();
    }
示例#22
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);
    }
示例#23
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);
 }
示例#24
0
文件: MvcTest.cs 项目: yysun/Rabbit
    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();
    }