public void WhenUpdateSubscription_ThenThrowsForbidden()
 {
     Assert.That(() => client.Put(new UpdateSubscription
     {
         Id = DataFormats.CreateEntityIdentifier()
     }), ThrowsWebServiceException.WithStatusCode(HttpStatusCode.Forbidden));
 }
 public void WhenUpdateSubscriptionWithUnknownId_ThenThrowsNotFound()
 {
     Assert.That(() => client.Put(new UpdateSubscription
     {
         Id = DataFormats.CreateEntityIdentifier()
     }), ThrowsWebServiceException.WithStatusCode(HttpStatusCode.NotFound));
 }
Пример #3
0
 public void Initialize()
 {
     dto = new DeleteSubscription
     {
         Id = DataFormats.CreateEntityIdentifier()
     };
     validator = new DeleteSubscriptionValidator();
 }
 public void Initialize()
 {
     dto = new SubscriptionDeliveryResult
     {
         Id             = DataFormats.CreateEntityIdentifier(),
         SubscriptionId = DataFormats.CreateEntityIdentifier()
     };
     validator = new SubscriptionDeliveryResultValidator();
 }
 private static SubscriptionDeliveryResult CreateDeliveryResult(string subscriptionId, HttpStatusCode statusCode, string statusDescription)
 {
     return(new SubscriptionDeliveryResult
     {
         Id = DataFormats.CreateEntityIdentifier(),
         AttemptedDateUtc = SystemTime.UtcNow.ToNearestMillisecond(),
         SubscriptionId = subscriptionId,
         StatusDescription = statusDescription,
         StatusCode = statusCode
     });
 }
 public void Initialize()
 {
     dto = new UpdateSubscription
     {
         Id          = DataFormats.CreateEntityIdentifier(),
         Url         = "http://localhost",
         ContentType = MimeTypes.Json,
         Secret      = Convert.ToBase64String(Encoding.Default.GetBytes("asecret"))
     };
     validator = new UpdateSubscriptionValidator();
 }
            public void WhenUpdateSubscriptionHistory_ThenReturnsSubscriptionHistory()
            {
                appHost.LoginUser(client, "asubscriber", WebhookFeature.DefaultSubscriberRoles);
                var subscription = client.Post(new CreateSubscription
                {
                    Name   = "aname",
                    Events = new List <string> {
                        "anevent1"
                    },
                    Config = new SubscriptionConfig
                    {
                        Url = "http://localhost:3333"
                    }
                }).Subscriptions
                                   .First();

                var datum1 = SystemTime.UtcNow.ToNearestSecond();
                var datum2 = datum1.AddDays(1);

                appHost.LoginUser(client, "arelay", WebhookFeature.DefaultRelayRoles);
                client.Put(new UpdateSubscriptionHistory
                {
                    Results = new List <SubscriptionDeliveryResult>
                    {
                        new SubscriptionDeliveryResult
                        {
                            Id               = DataFormats.CreateEntityIdentifier(),
                            SubscriptionId   = subscription.Id,
                            AttemptedDateUtc = datum1
                        },
                        new SubscriptionDeliveryResult
                        {
                            Id               = DataFormats.CreateEntityIdentifier(),
                            SubscriptionId   = subscription.Id,
                            AttemptedDateUtc = datum2
                        }
                    }
                });

                appHost.LoginUser(client, "asubscriber", WebhookFeature.DefaultSubscriberRoles);
                var result = client.Get(new GetSubscription
                {
                    Id = subscription.Id
                }).History;

                Assert.That(result.Count, Is.EqualTo(2));
                Assert.That(result[0].AttemptedDateUtc, Is.EqualTo(datum2));
                Assert.That(result[1].AttemptedDateUtc, Is.EqualTo(datum1));
            }
        public string Add(WebhookSubscription subscription)
        {
            Guard.AgainstNull(() => subscription, subscription);

            var id = DataFormats.CreateEntityIdentifier();

            subscription.Id = id;

            using (var db = dbFactory.Open())
            {
                db.Insert(subscription);
            }

            return(subscription.Id);
        }
            public void WhenUpdateSubscriptionHistoryWithA4XX_ThenSubscriptionDeActivated()
            {
                appHost.LoginUser(client, "asubscriber", WebhookFeature.DefaultSubscriberRoles);
                var subscription = client.Post(new CreateSubscription
                {
                    Name   = "aname",
                    Events = new List <string> {
                        "anevent1"
                    },
                    Config = new SubscriptionConfig
                    {
                        Url = "http://localhost:3333"
                    }
                }).Subscriptions
                                   .First();

                var datum = SystemTime.UtcNow.ToNearestSecond();

                appHost.LoginUser(client, "arelay", WebhookFeature.DefaultRelayRoles);
                client.Put(new UpdateSubscriptionHistory
                {
                    Results = new List <SubscriptionDeliveryResult>
                    {
                        new SubscriptionDeliveryResult
                        {
                            Id                = DataFormats.CreateEntityIdentifier(),
                            SubscriptionId    = subscription.Id,
                            AttemptedDateUtc  = datum,
                            StatusCode        = HttpStatusCode.BadRequest,
                            StatusDescription = "adescription"
                        }
                    }
                });

                appHost.LoginUser(client, "asubscriber", WebhookFeature.DefaultSubscriberRoles);
                var result = client.Get(new GetSubscription
                {
                    Id = subscription.Id
                });

                Assert.That(result.History.Count, Is.EqualTo(1));
                Assert.That(result.History[0].AttemptedDateUtc, Is.EqualTo(datum));
                Assert.That(result.History[0].StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
                Assert.That(result.History[0].StatusDescription, Is.EqualTo("adescription"));
                Assert.That(result.Subscription.IsActive, Is.False);
            }
            public void WhenCreate_ThenQueuesEvent()
            {
                var id    = DataFormats.CreateEntityIdentifier();
                var datum = SystemTime.UtcNow.ToNearestMillisecond();
                var data  = new TestData();

                sink.Write(new WebhookEvent
                {
                    CreatedDateUtc = datum,
                    EventName      = "aneventname",
                    Data           = data,
                    Id             = id
                });

                var result = sink.Peek();

                Assert.That(result.Count, Is.EqualTo(1));
                Assert.That(result[0].CreatedDateUtc, Is.EqualTo(datum));
                Assert.That(result[0].EventName, Is.EqualTo("aneventname"));
                Assert.That(result[0].Data, Is.EqualTo(new TestData().ToJson()));
                Assert.That(result[0].Id, Is.EqualTo(id));
            }