Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            try
            {
                var notification = new
                {
                    Aps = new
                    {
                        Alert = "Hello!"
                    }
                };

                using var api = new APNNotificationAPI(BASE_URL, CERTIFICATE_PATH);

                Console.WriteLine($"Sending notification: {Environment.NewLine}{NotificationSerializer.Serialize(notification)}");

                // change this to your device token
                var deviceToken = "420e6134164a7d3192d97ca5186f79a479725f8045e17c034930076dc8a4e8e1";

                await api.SendAsync(notification, deviceToken);

                Console.WriteLine("Send succeeded");
            }
            catch (APIException ex)
            {
                Console.WriteLine($"Sending notification failed with reason: '{ex.Reason}'");
            }
        }
        public void CanSerializeNotification()
        {
            var notification = new IDDDCommon.Notification.Notification(1, myDomainEvent);
            var actual       = NotificationSerializer.Serialize(notification);

            const string expected =
                "{\"NotificationId\":1,\"DomainEvent\":{\"EventVersion\":1,\"EventId\":\"88b0543c-e17b-4edb-a7c5-4ce8f0d8bb36\",\"OccurredOn\":\"2020-03-28T19:04:53.191488+09:00\",\"Message\":\"serialize-test\"},\"TypeName\":\"IDDDCommon.Test.NotificationSerializerFixture+MyDomainEvent, IDDDCommon.Test\",\"OccurredOn\":\"2020-03-28T19:04:53.191488+09:00\",\"Version\":1}";

            Assert.That(actual, Is.EqualTo(expected));
        }
        public async Task CanSendMessage()
        {
            const string exchangeMessage = "test-message";
            //Arrange
            var exchange = new Exchange(Exchanges.AgilePm);
            var message  =
                NotificationSerializer.Serialize(
                    new IDDDCommon.Notification.Notification(1L, new MyDomainEvent(exchangeMessage)));

            // Action
            new MessageProducer(exchange).Send(message);

            // 送信してから少し待つ。
            await Task.Delay(3000);

            // Assert
            Assert.That(NotificationMap[Exchanges.AgilePm.ToString()], Is.EqualTo(exchangeMessage));
        }