Exemple #1
0
        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()));
        }
Exemple #2
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);
        }
Exemple #3
0
        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()));
        }
Exemple #4
0
        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()));
        }
Exemple #5
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()));
        }