Exemplo n.º 1
0
        public void Ctor_ShouldCreateSubscriptionRequestSuccesfully_WithAllParameters()
        {
            const string callbackUri = "callBackUri";
            const SubscriptionMode subscriptionMode = SubscriptionMode.Subscribe;
            const string topic = "topic";
            const string verify = "verify";
            var leaseSeconds = new TimeSpan(1, 0, 0, 0);
            const string secret = "secret";
            const string verifyToken = "verifyToken";

            var subscriptionRequest = new SubscriptionRequest
                (
                callbackUri,
                topic,
                verify,
                leaseSeconds,
                secret,
                verifyToken
                );

            Assert.AreEqual(callbackUri, subscriptionRequest.CallbackUri);
            Assert.AreEqual(subscriptionMode, subscriptionRequest.SubscriptionMode);
            Assert.AreEqual(topic, subscriptionRequest.Topic);
            Assert.AreEqual(verify, subscriptionRequest.Verify);
            Assert.AreEqual(leaseSeconds, subscriptionRequest.LeaseSeconds);
            Assert.AreEqual(secret, subscriptionRequest.Secret);
            Assert.AreEqual(verifyToken, subscriptionRequest.VerifyToken);
        }
Exemplo n.º 2
0
        public void BuildRequestParameterString_ShouldCreateCorrectParameters()
        {
            const string callbackUri = "callBackUri";
            const string subscriptionModeStr = "subscribe";
            const string topic = "topic";
            const string verify = "verify";
            var leaseSeconds = new TimeSpan(1, 0, 0, 0);
            const string secret = "secret";
            const string verifyToken = "verifyToken";
            const string parameterPattern = "hub.callback={0}&hub.mode={1}&hub.topic={2}&hub.verify={3}&hub.lease_seconds={4}&hub.secret={5}&hub.verify_token={6}";

            var expectedParameterString = string.Format(parameterPattern,
                callbackUri, subscriptionModeStr, topic, verify, leaseSeconds.TotalSeconds, secret, verifyToken);

            var subscriptionRequest = new SubscriptionRequest
                (
                callbackUri,
                topic,
                verify,
                leaseSeconds,
                secret,
                verifyToken
                );
            var result = subscriptionRequest.BuildRequestParameterString();

            Assert.AreEqual(result, expectedParameterString);
        }
Exemplo n.º 3
0
        public void Add_ShouldPersist()
        {
            var subscriptionRequest = new SubscriptionRequest("callBackUri", "topic", "verify", new TimeSpan(1, 0, 0, 0), "secret", "verifyToken");

            var subscriptionRepository = new SubscriptionRepository();
            subscriptionRepository.Add(subscriptionRequest);
            Assert.AreEqual(1, subscriptionRepository.Count);
        }
Exemplo n.º 4
0
        public void Subscribe_ShouldSuccessfullySubscribe()
        {
            var subscriptionRequest = new SubscriptionRequest("callbackUri", "topic", "12345", _oneDayTimeSpan, "secret",
                                                              "verifyToken");
            var actualRequestBody = "";
            _mockHttpClient.Setup(x => x.Post(It.IsAny<string>()))
                .Callback(delegate(string requestData) { actualRequestBody = requestData; });

            var subscriberClient = new SubscriberClient(_mockHttpClient.Object, _mockSubscriptionRepository.Object);
            subscriberClient.MakeRequest(subscriptionRequest);

            Assert.AreEqual(subscriptionRequest.BuildRequestParameterString(), actualRequestBody);
        }
Exemplo n.º 5
0
        public void Subscribe_ShouldPersistSubsciptionRequest()
        {
            var addedCount = 0;
            var subscriptionRequest = new SubscriptionRequest("callbackUri", "topic", "12345", _oneDayTimeSpan, "secret",
                                                              "verifyToken");
            _mockSubscriptionRepository.Setup(x => x.Add(It.IsAny<SubscriptionRequestBase>()))
                .Callback(delegate(SubscriptionRequestBase subscriptionRequestBase) { addedCount += 1; }
                );

            var subscriberClient = new SubscriberClient(_mockHttpClient.Object, _mockSubscriptionRepository.Object);
            subscriberClient.MakeRequest(subscriptionRequest);

            Assert.AreEqual(1, addedCount);
        }
Exemplo n.º 6
0
        public void Ctor_ShouldCreateSubscriptionRequestSuccesfully_WithRequiredParameters()
        {
            const string callbackUri = "callBackUri";
            const SubscriptionMode subscriptionMode = SubscriptionMode.Subscribe;
            const string topic = "topic";
            const string verify = "verify";

            var subscriptionRequest = new SubscriptionRequest
                (
                callbackUri,
                topic,
                verify
                );

            Assert.AreEqual(callbackUri, subscriptionRequest.CallbackUri);
            Assert.AreEqual(subscriptionMode, subscriptionRequest.SubscriptionMode);
            Assert.AreEqual(topic, subscriptionRequest.Topic);
            Assert.AreEqual(verify, subscriptionRequest.Verify);
        }
Exemplo n.º 7
0
 public void MakeRequest(SubscriptionRequest subscriptionRequest)
 {
     var requestData = subscriptionRequest.BuildRequestParameterString();
     _httpClient.Post(requestData);
     _subscriptionRepository.Add(subscriptionRequest);
 }