private bool ensureTimingWorksGet(Tracker t, MockGet g, bool expectB64 = true) { if (!expectB64) { Assert.Fail("non b64 mode not supported"); } t.Track(new Timing().SetCategory("category").SetVariable("variable").SetTiming(5).SetLabel("label").Build()); t.Flush(); var actual = g.Queries[0]; var expectedJsonString = @"{""schema"":""iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0"",""data"":{""schema"":""iglu:com.snowplowanalytics.snowplow/timing/jsonschema/1-0-0"",""data"":{""category"":""category"",""label"":""label"",""timing"":5,""variable"":""variable""}}}"; var expectedB64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(expectedJsonString)); var expected = new Dictionary <string, string> { { "e", "ue" }, { "ue_px", expectedB64 } }; assertQueryContainsDefaults(actual); assertQueryContainsAll(actual, expected); return(true); }
public void testSendGetRequestNon200ResponseHttps() { var getReq = new MockGet() { StatusCode = 500 }; var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, getMethod: new GetDelegate(getReq.HttpGet)); var payload = new Payload(); payload.Add("hello", "world"); payload.Add("ts", "123"); 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(getReq.Queries.Count == 1); var actual = getReq.Queries[0]; var expectedRegex = new Regex("https://somewhere\\.com/i\\?hello=world&ts=123&stm=[0-9]{13}"); Assert.IsTrue(expectedRegex.Match(actual).Success, String.Format("{0} doesn't match {1}", actual, expectedRegex.ToString())); }
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); }
public void Default_Post() { dynamic page = new MockGet(new string[] { "/" }); Mvc.Run(page, new PageController()); Assert_ShowDefaultPage(page); }
private bool ensureScreenViewWorksGet(Tracker t, MockGet g, bool expectB64 = true) { if (!expectB64) { Assert.Fail("non b64 mode not supported"); } t.Track(new ScreenView().SetName("entry screen").SetId("0001").Build()); t.Flush(); var actual = g.Queries[0]; var expectedJsonString = @"{""schema"":""iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0"",""data"":{""schema"":""iglu:com.snowplowanalytics.snowplow/screen_view/jsonschema/1-0-0"",""data"":{""name"":""entry screen"",""id"":""0001""}}}"; var expectedB64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(expectedJsonString)); var expected = new Dictionary <string, string> { { "e", "ue" }, { "ue_px", expectedB64 } }; assertQueryContainsDefaults(actual); assertQueryContainsAll(actual, expected); return(true); }
private bool ensureStructEventsWorkGet(Tracker t, MockGet g) { t.Track(new Structured() .SetCategory("myCategory") .SetAction("myAction") .SetLabel("myLabel") .SetProperty("myProperty") .SetValue(17) .Build()); t.Flush(); var expectedRegex = new Regex( String.Format(@"http://snowplowanalytics.com/i\?e=se&se_ca={0}&se_ac={1}&se_la={2}&se_pr={3}&se_va={4}&eid=[^&]+&dtm=[^&]+&tv=[^&]+&tna=testNamespace&aid=testAppId&p=pc", Regex.Escape(WebUtility.UrlEncode("myCategory")), Regex.Escape(WebUtility.UrlEncode("myAction")), Regex.Escape(WebUtility.UrlEncode("myLabel")), Regex.Escape(WebUtility.UrlEncode("myProperty")), Regex.Escape(WebUtility.UrlEncode("17")) ) ); var actual = g.Queries[0]; Assert.IsTrue(expectedRegex.Match(actual).Success, String.Format("{0} doesn't match regex {1}", actual, expectedRegex.ToString())); return(true); }
[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(); }
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(); }
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); }
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(); }
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(); }
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(); }
private bool ensureSettersWorkGet(Tracker t, MockGet g) { t.SetPlatform(Platform.Mob); t.SetUserId("malcolm"); t.SetScreenResolution(100, 200); t.SetViewport(50, 60); t.SetColorDepth(24); t.SetTimezone("Europe London"); t.SetLang("en"); t.Track(new PageView() .SetPageUrl("http://www.example.com") .SetPageTitle("title page") .SetReferrer("http://www.referrer.com") .SetTrueTimestamp(1000000000000) .Build()); t.Flush(); var actual = g.Queries[0]; var expected = new Dictionary <string, string> { { "e", "pv" }, { "url", "http://www.example.com" }, { "page", "title page" }, { "refr", "http://www.referrer.com" }, { "tv", Version.VERSION }, { "tna", "testNamespace" }, { "aid", "testAppId" }, { "p", "mob" }, { "res", "100x200" }, { "vp", "50x60" }, { "cd", "24" }, { "tz", "Europe London" }, { "lang", "en" }, { "ttm", "1000000000000" } }; foreach (var k in expected.Keys) { var matcher = new Regex("[&?]" + k + "=(?<value>[^&]+)"); var match = matcher.Match(actual); Assert.IsTrue(match.Success, "Couldn't find key " + k + " in query " + actual); var found = match.Result("${value}"); string decoded = WebUtility.UrlDecode(found); Assert.AreEqual(expected[k], decoded, "key " + k + " has the wrong value " + decoded); } return(true); }
private bool ensureContextsWorkGet(Tracker t, MockGet g, bool useb64 = true) { Assert.IsTrue(useb64); var pageContext = new GenericContext() .SetSchema("iglu:com.snowplowanalytics.snowplow/page/jsonschema/1-0-0") .Add("type", "test") .Add("public", false) .Build(); var userContext = new GenericContext() .SetSchema("iglu:com.snowplowanalytics.snowplow/user/jsonschema/1-0-0") .Add("age", 40) .Add("name", "ned") .Build(); var contexts = new List <IContext> { pageContext, userContext }; t.Track(new PageView().SetPageUrl("http://www.example.com").SetCustomContext(contexts).Build()); t.Flush(); var actual = g.Queries[0]; var expected = new Dictionary <string, string> { { "e", "pv" }, { "url", "http://www.example.com" } }; var expectedJsonString = @"{""schema"":""iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-1"",""data"":[{""schema"":""iglu:com.snowplowanalytics.snowplow/page/jsonschema/1-0-0"",""data"":{""type"":""test"",""public"":false}},{""schema"":""iglu:com.snowplowanalytics.snowplow/user/jsonschema/1-0-0"",""data"":{""age"":40,""name"":""ned""}}]}"; var expectedB64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(expectedJsonString)); var extractCx = new Regex("cx=(?<cx>[^&]+)"); Assert.IsTrue(extractCx.IsMatch(actual), "couldn't find cx in query"); var match = extractCx.Match(actual); Assert.IsTrue(match.Success); var actualCx = match.Result("${cx}"); Assert.AreEqual(expectedB64, actualCx); return(true); }
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(); }
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); }
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(); }
public void testGetIgnoreSchemePathQueryInUri() { var getReq = new MockGet(); var endpoint = new SnowplowHttpCollectorEndpoint("something://somewhere.com/things?1=1", HttpProtocol.HTTPS, getMethod: new GetDelegate(getReq.HttpGet)); var payload = new Payload(); payload.Add("sample", "value"); 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(getReq.Queries.Count == 1); var actual = getReq.Queries[0]; var expectedRegex = new Regex("https://somewhere\\.com/i\\?sample=value&stm=[0-9]{13}"); Assert.IsTrue(expectedRegex.Match(actual).Success, String.Format("{0} doesn't match {1}", actual, expectedRegex.ToString())); }
public void testGetPortIsSet() { var getReq = new MockGet(); var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, getMethod: new GetDelegate(getReq.HttpGet), port: 999); 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(getReq.Queries.Count == 1); var actual = getReq.Queries[0]; var expectedRegex = new Regex("https://somewhere\\.com:999/i\\?foo=bar&stm=[0-9]{13}"); Assert.IsTrue(expectedRegex.Match(actual).Success, String.Format("{0} doesn't match {1}", actual, expectedRegex.ToString())); }
// --- Event testers private bool ensurePageViewsWorkGet(Tracker t, MockGet g) { t.Track(new PageView() .SetPageUrl("http://www.example.com") .SetReferrer("http://www.referrer.com") .SetPageTitle("title page") .Build()); t.Flush(); var expectedRegex = new Regex( String.Format(@"http://snowplowanalytics.com/i\?e=pv&url={0}&page={1}&refr={2}&eid=[^&]+&dtm=[^&]+&tv=[^&]+&tna=testNamespace&aid=testAppId&p=pc", Regex.Escape(WebUtility.UrlEncode("http://www.example.com")), Regex.Escape(WebUtility.UrlEncode("title page")), Regex.Escape(WebUtility.UrlEncode("http://www.referrer.com")) ) ); var actual = g.Queries[0]; Assert.IsTrue(Uri.IsWellFormedUriString(actual, UriKind.Absolute)); Assert.IsTrue(expectedRegex.Match(actual).Success, String.Format("{0} doesn't match {1}", actual, expectedRegex.ToString())); return(true); }
private bool ensureUnstructEventGet(Tracker t, MockGet g, bool expectBase64 = false) { var eventJson = new SelfDescribingJson( "iglu:com.acme/test/jsonschema/1-0-0", new Dictionary <string, string> { { "page", "testpage" }, { "user", "tester" } } ); t.Track(new SelfDescribing().SetEventData(eventJson).Build()); t.Flush(); var actual = g.Queries[0]; var expectedPayload = @"{""schema"":""iglu:com.snowplowanalytics.snowplow/unstruct_event/jsonschema/1-0-0"",""data"":{""schema"":""iglu:com.acme/test/jsonschema/1-0-0"",""data"":{""page"":""testpage"",""user"":""tester""}}}"; var expected = new Dictionary <string, string> { { "e", "ue" } }; if (expectBase64) { string base64encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(expectedPayload)); expected.Add("ue_px", base64encoded); } else { expected.Add("ue_pr", expectedPayload); } assertQueryContainsDefaults(actual); assertQueryContainsAll(actual, expected); return(true); }
public void Delete_Get() { dynamic page = new MockGet(new string[] { "Pages", "Delete", "id" }); Mvc.Run(page, new PageController()); }
[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()); }
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(); }
public void Get_Delete() { dynamic webPage = new MockGet(new string[] { "Mock", "Delete", "y", "z" }); dynamic controller = new MockController(); Mvc.Run(webPage, controller); controller.Verify(); }
private bool ensureEcommerceTransactionWorksGet(Tracker t, MockGet g) { var hat = new EcommerceTransactionItem().SetSku("pbz0026").SetPrice(20).SetQuantity(1).Build(); var shirt = new EcommerceTransactionItem().SetSku("pbz0038").SetPrice(15).SetQuantity(1).SetName("shirt").SetCategory("clothing").Build(); var items = new List <EcommerceTransactionItem> { hat, shirt }; t.Track(new EcommerceTransaction() .SetOrderId("6a8078be") .SetTotalValue(35) .SetAffiliation("affiliation") .SetTaxValue(3) .SetShipping(0) .SetCity("Phoenix") .SetState("Arizona") .SetCountry("US") .SetCurrency("USD") .SetItems(items) .Build()); t.Flush(); // other events may exist - lets find our best guesses for each var transactionActual = (from item in g.Queries where item.Contains("Phoenix") select item).ToList()[0]; var hatActual = (from item in g.Queries where item.Contains("pbz0026") select item).ToList()[0]; var shirtActual = (from item in g.Queries where item.Contains("pbz0038") select item).ToList()[0]; var expectedTransaction = new Dictionary <string, string> { { "e", "tr" }, { "tr_id", "6a8078be" }, { "tr_tt", "35.00" }, { "tr_af", "affiliation" }, { "tr_tx", "3.00" }, { "tr_sh", "0.00" }, { "tr_ci", "Phoenix" }, { "tr_st", "Arizona" }, { "tr_co", "US" }, { "tr_cu", "USD" } }; assertQueryContainsDefaults(transactionActual); assertQueryContainsAll(transactionActual, expectedTransaction); var expectedHat = new Dictionary <string, string> { { "e", "ti" }, { "ti_id", "6a8078be" }, { "ti_sk", "pbz0026" }, { "ti_pr", "20.00" }, { "ti_qu", "1" }, { "ti_cu", "USD" } }; assertQueryContainsDefaults(hatActual); assertQueryContainsAll(hatActual, expectedHat); var expectedShirt = new Dictionary <string, string> { { "e", "ti" }, { "ti_id", "6a8078be" }, { "ti_sk", "pbz0038" }, { "ti_nm", "shirt" }, { "ti_ca", "clothing" }, { "ti_pr", "15.00" }, { "ti_qu", "1" }, { "ti_cu", "USD" }, }; assertQueryContainsDefaults(shirtActual); assertQueryContainsAll(shirtActual, expectedShirt); return(true); }