public void TestSetGcmApiKey()
        {
            var gcmAPIKey = @"teststring";

            client.SetGcmApiKey(gcmAPIKey);
            var subscription        = new PushSubscription(TestGcmEndpoint, TestPublicKey, TestPrivateKey);
            var message             = client.GenerateRequestDetails(subscription, @"test payload");
            var authorizationHeader = message.Headers.GetValues(@"Authorization").First();

            Assert.AreEqual(@"key=" + gcmAPIKey, authorizationHeader);
        }
        public void TestSetGcmApiKeyNull()
        {
            var client = new WebPushClient();

            client.SetGcmApiKey(@"somestring");
            client.SetGcmApiKey(null);

            var subscription = new PushSubscription(TestGcmEndpoint, TestPublicKey, TestPrivateKey);
            var message      = client.GenerateRequestDetails(subscription, @"test payload");

            IEnumerable <string> values;

            Assert.False(message.Headers.TryGetValues("Authorization", out values));
        }
        /// <summary>
        /// Sends a message to multiple devices.
        /// </summary>
        /// <param name="p_message">Message to send.</param>
        /// <param name="p_targetDevices">Target devices.</param>
        public Task SendMessage(MessageViewModel p_message, IEnumerable <Device> p_targetDevices)
        {
            WebPushClient v_webPushClient = new WebPushClient();

            if (this.HasVapidPublicKey())
            {
                v_webPushClient.SetVapidDetails(VapidDetails);
            }

            if (!String.IsNullOrWhiteSpace(GcmAPIKey))
            {
                v_webPushClient.SetGcmApiKey(GcmAPIKey);
            }


            List <Task> v_pending = new List <Task>();

            foreach (Device v_targetDevice in p_targetDevices)
            {
                string v_message = JsonConvert.SerializeObject(p_message);
                v_pending.Add(v_webPushClient.SendNotificationAsync(v_targetDevice, v_message));
            }

            return(Task.WhenAll(v_pending));
        }
        public void TestSetGCMAPIKeyEmptyString()
        {
            WebPushClient client = new WebPushClient();

            Assert.ThrowsException <ArgumentException>(delegate
            {
                client.SetGcmApiKey("");
            });
        }
        public void TestSetGcmApiKeyNonGcmPushService()
        {
            // Ensure that the API key doesn't get added on a service that doesn't accept it.
            var client = new WebPushClient();

            var gcmAPIKey = @"teststring";

            client.SetGcmApiKey(gcmAPIKey);
            var subscription = new PushSubscription(TestFcmEndpoint, TestPublicKey, TestPrivateKey);
            var message      = client.GenerateRequestDetails(subscription, @"test payload");

            IEnumerable <string> values;

            Assert.False(message.Headers.TryGetValues(@"Authorization", out values));
        }
        public void TestSetGcmApiKeyEmptyString()
        {
            var client = new WebPushClient();

            Assert.Throws(typeof(ArgumentException), delegate { client.SetGcmApiKey(""); });
        }