示例#1
0
        public async Task Ensure_Client_Caching_Works_With_Jwt()
        {
            var service = BoostrapApnsService();
            var jwtOpt1 = new ApnsJwtOptions()
            {
                KeyId       = "1234567890",
                TeamId      = "1234567890",
                BundleId    = "bundleid1",
                CertContent = _certs.P8CertData
            };
            var jwtOpt2 = new ApnsJwtOptions()
            {
                KeyId       = "1234567890",
                TeamId      = "1234567890",
                BundleId    = "bundleid2",
                CertContent = _certs.P8CertData
            };
            var firstPush  = ApplePush.CreateContentAvailable().AddToken("token");
            var secondPush = ApplePush.CreateAlert(new ApplePushAlert(null, "body")).AddToken("token");
            var thirdPush  = ApplePush.CreateAlert(new ApplePushAlert(null, "body")).AddToken("token");
            var fourthPush = ApplePush.CreateContentAvailable().AddToken("token");

            await service.SendPush(firstPush, jwtOpt1);

            await service.SendPush(secondPush, jwtOpt1);

            await service.SendPush(thirdPush, jwtOpt2);

            await service.SendPush(fourthPush, jwtOpt2);

            Assert.Equal(2, ((IDictionary)service.GetType().GetField("_cachedJwtClients", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service)).Count);
        }
示例#2
0
        public void Adding_ContentAvailable_To_Push_With_Badge_or_Sound_Fails()
        {
            var pushWithContentAvailable = ApplePush.CreateContentAvailable();

            Assert.Throws <InvalidOperationException>(() => pushWithContentAvailable.AddBadge(0));
            Assert.Throws <InvalidOperationException>(() => pushWithContentAvailable.AddSound("sound"));
        }
示例#3
0
        public void Adding_Voip_To_NonVoip_Type_Throws_InvalidOperationException()
        {
            var backgroundPush = ApplePush.CreateContentAvailable();
            var alert          = ApplePush.CreateContentAvailable();

            Assert.Throws <InvalidOperationException>(() => backgroundPush.AddVoipToken("voip"));
        }
示例#4
0
        public void Ensure_Priority_Corresponds_To_Payload()
        {
            var pushWithContentAvailable = ApplePush.CreateContentAvailable();
            var pushWithAlert            = ApplePush.CreateAlert(new ApplePushAlert("title", "body"));

            Assert.Equal(5, pushWithContentAvailable.Priority);
            Assert.Equal(10, pushWithAlert.Priority);
        }
示例#5
0
        public void Ensure_Type_Correspond_To_Payload()
        {
            var pushWithContentAvailable = ApplePush.CreateContentAvailable();
            var pushWithAlert            = ApplePush.CreateAlert(new ApplePushAlert("title", "body"));

            Assert.Equal(ApplePushType.Background, pushWithContentAvailable.Type);
            Assert.Equal(ApplePushType.Alert, pushWithAlert.Type);
        }
示例#6
0
        public void Setting_Custom_Priority()
        {
            var push = ApplePush.CreateContentAvailable();

            Assert.Equal(5, push.Priority);
            push.SetPriority(10);
            Assert.Equal(10, push.Priority);
        }
示例#7
0
        public void Adding_Token_and_VoipToken_Together_Fails()
        {
            var pushWithToken      = ApplePush.CreateContentAvailable().AddToken("token");
            var pushWithVoipToken  = ApplePush.CreateContentAvailable(true).AddVoipToken("voip");
            var alertPushWithToken = ApplePush.CreateAlert(new ApplePushAlert("title", "body")).AddToken("token");

            Assert.Throws <InvalidOperationException>(() => pushWithToken.AddVoipToken("voip"));
            Assert.Throws <InvalidOperationException>(() => pushWithVoipToken.AddToken("token"));
            Assert.Throws <InvalidOperationException>(() => alertPushWithToken.AddVoipToken("voip"));
        }
示例#8
0
        //[Fact] cert uses real handler. Can't test until refactored.
        public async Task Ensure_Client_Caching_Works_With_Cert()
        {
            var service    = BoostrapApnsService();
            var firstPush  = ApplePush.CreateContentAvailable().AddToken("token");
            var secondPush = ApplePush.CreateAlert(new ApplePushAlert(null, "body")).AddToken("token");

            await service.SendPush(firstPush, _certs.P12Cert);

            await service.SendPush(secondPush, _certs.P12Cert);

            Assert.Single((IDictionary)service.GetType().GetField("_cachedJwtClients", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(service));
        }
示例#9
0
        public void CreateContentAvailableAsVoip_Has_Voip_Type()
        {
            var voipPush = ApplePush.CreateContentAvailable(true);

            Assert.Equal(ApplePushType.Voip, voipPush.Type);
        }
示例#10
0
        public void CreateContentAvailable_Has_Background_Type()
        {
            var voipPush = ApplePush.CreateContentAvailable();

            Assert.Equal(ApplePushType.Background, voipPush.Type);
        }
示例#11
0
        public void Adding_Token_To_Voip_Type_Throws_InvalidOperationException()
        {
            var backgroundPush = ApplePush.CreateContentAvailable(true);

            Assert.Throws <InvalidOperationException>(() => backgroundPush.AddToken("token"));
        }