コード例 #1
0
ファイル: ServiceTest.cs プロジェクト: hajimen/flowerflower
        public void TestSimple()
        {
            TService s = new TService(true, SecureConstant.P12File, SecureConstant.P12FilePassword);

            Payload p = new Payload();
            p.Badge = 1;
            p.Message = "test";

            Notification n = new TNotification(int.MaxValue, p, "44F5AE40CC0FFC100A4984D2D949A337B3633B6B266F03674439B2F776A49FD3"); // valid token
            s.Enqueue(n);

            Thread.Sleep(5000);
            Expect(s.isAborted, Is.EqualTo(false));

            Notification n2 = new TNotification(int.MaxValue, p, "D4D9B50237423A48633F05F74FED2132BB49A1833565EE580E321E5A6A18DE95"); // invalid token
            p.Message = "test2";
            Notification n3 = new TNotification(int.MaxValue, p, "44F5AE40CC0FFC100A4984D2D949A337B3633B6B266F03674439B2F776A49FD3");
            s.Enqueue(n2);
            s.Enqueue(n3);

            Thread.Sleep(5000);
            Expect(s.isAborted, Is.EqualTo(true));

            s.Close();
        }
コード例 #2
0
ファイル: Notification.cs プロジェクト: hajimen/flowerflower
 public Notification(int expiry, Payload payload, string deviceTokenStr)
 {
     if (deviceTokenStr.Length != tokenLength * 2)
     {
         throw new ArgumentException("deviceToken is bad length");
     }
     deviceToken = new byte[tokenLength];
     for (int i = 0; i < tokenLength; i++)
     {
         deviceToken[i] = byte.Parse(deviceTokenStr.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber);
     }
     this.expiry = expiry;
     this.payload = payload;
 }
コード例 #3
0
 public NotificationImpl(int expiry, Payload payload, string deviceTokenStr, long apnsId)
     : base(expiry, payload, deviceTokenStr)
 {
     this.apnsId = apnsId;
 }
コード例 #4
-2
ファイル: PayloadTest.cs プロジェクト: hajimen/flowerflower
        public void TestSimple()
        {
            Payload p = new Payload();
            Expect(p.ToJsonString(), Is.EqualTo("{}"));

            p.Badge = 1;
            p.Message = "test";
            p.Sound = "sound.wav";
            Expect(p.ToJsonString(), Is.EqualTo("{\"aps\":{\"alert\":\"test\",\"badge\":1,\"sound\":\"sound.wav\"}}"));

            p.Custom["custom"] = "custom value";
            Expect(p.ToJsonString(), Is.EqualTo("{\"custom\":\"custom value\",\"aps\":{\"alert\":\"test\",\"badge\":1,\"sound\":\"sound.wav\"}}"));

            Payload p2 = new Payload();
            p2.Custom["custom"] = "custom value";
            Expect(p2.ToJsonString(), Is.EqualTo("{\"custom\":\"custom value\"}"));

            string t = "";
            for (int i = 0; i < 16; i++)
            {
                t += "abcdefghabcdefgh";
            }
            p.Custom["toolong"] = t;
            try
            {
                p.ToBytes();
            }
            catch (TooLongPayloadException)
            {
                // ok
                return;
            }
            Assert.Fail("should be exception");
        }