Esempio n. 1
0
        public async Task CreateDeleteSubscription()
        {
            using (var pushServer = new PushServerTestsBase().CreateServer())
            {
                var client = pushServer.CreateClient();
                client.DefaultRequestHeaders.Add("X-Forwarded-For", $"192.168.1.{_rng.Next(1, 255)}");

                StringContent       contentSubscription;
                HttpResponseMessage result;
                string  content;
                bool    isSuccess;
                dynamic response;
                string  userId;

                // W3C Subscription
                contentSubscription = new StringContent(BuildSubscriptionRequest(), Encoding.UTF8, "application/json");
                result = await client.PostAsync(PushServerTestsBase.Post.Subscriptions, contentSubscription);

                content = await result.Content.ReadAsStringAsync();

                Assert.True(result.IsSuccessStatusCode, "Unsuccessful request. Response: {0}", content);
                response  = JObject.Parse(content);
                isSuccess = response.isSuccess;
                userId    = response.data.userId.ToString();
                Assert.True(isSuccess);
                Assert.IsNotEmpty(userId);

                result = await client.DeleteAsync(PushServerTestsBase.Delete.Subscriptions.Replace("{userId}", userId));

                Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);

                // Safari subscription
                contentSubscription = new StringContent(BuildSubscriptionRequest(false), Encoding.UTF8, "application/json");
                result = await client.PostAsync(PushServerTestsBase.Post.Subscriptions, contentSubscription);

                content = await result.Content.ReadAsStringAsync();

                Assert.True(result.IsSuccessStatusCode, "Unsuccessful request. Response: {0}", content);
                response  = JObject.Parse(content);
                isSuccess = response.isSuccess;
                userId    = response.data.userId.ToString();
                Assert.True(isSuccess);
                Assert.IsNotEmpty(userId);

                //result = await client.DeleteAsync(PushServerTestsBase.Delete.Subscriptions.Replace("{userId}", userId));
                //Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            }
        }
Esempio n. 2
0
        public async Task CreateNotification()
        {
            using (var pushServer = new PushServerTestsBase().CreateServer())
            {
                var client = pushServer.CreateClient();

                var contentNotification = new StringContent(BuildNotificationRequest(), Encoding.UTF8, "application/json");
                var result = await client.PostAsync(PushServerTestsBase.Post.Notifications, contentNotification);

                var content = await result.Content.ReadAsStringAsync();

                dynamic response  = JObject.Parse(content);
                bool    isSuccess = response.isSuccess;
                Assert.True(isSuccess);
            }
        }