Exemplo n.º 1
0
        public void CalculateLinkAuthorizationRefreshIntervalRespectsTheMinimumDuration()
        {
            var credential        = new Mock <ServiceBusTokenCredential>(Mock.Of <TokenCredential>(), "{namespace}.servicebus.windows.net");
            var mockScope         = new MockConnectionMockScope(new Uri("sb://mine.hubs.com"), credential.Object, ServiceBusTransportType.AmqpTcp, null);
            var currentTime       = new DateTime(2015, 10, 27, 00, 00, 00);
            var minimumRefresh    = GetMinimumAuthorizationRefresh();
            var expireTime        = currentTime.Add(minimumRefresh.Subtract(TimeSpan.FromMilliseconds(500)));
            var calculatedRefresh = mockScope.InvokeCalculateLinkAuthorizationRefreshInterval(expireTime, currentTime);

            Assert.That(calculatedRefresh, Is.EqualTo(minimumRefresh), "The minimum refresh duration should have been used.");
        }
Exemplo n.º 2
0
        public void CalculateLinkAuthorizationRefreshIntervalRespectsTheRefreshBuffer()
        {
            var credential        = new Mock <ServiceBusTokenCredential>(Mock.Of <TokenCredential>(), "{namespace}.servicebus.windows.net");
            var mockScope         = new MockConnectionMockScope(new Uri("sb://mine.hubs.com"), credential.Object, ServiceBusTransportType.AmqpTcp, null);
            var currentTime       = new DateTime(2015, 10, 27, 00, 00, 00);
            var expireTime        = currentTime.AddHours(1);
            var buffer            = GetAuthorizationRefreshBuffer();
            var calculatedRefresh = mockScope.InvokeCalculateLinkAuthorizationRefreshInterval(expireTime, currentTime);
            var calculatedExpire  = currentTime.Add(calculatedRefresh);

            Assert.That(calculatedExpire, Is.LessThan(expireTime), "The refresh should be account for the buffer and be earlier than expiration.");
            Assert.That(calculatedExpire, Is.EqualTo(expireTime.Subtract(buffer)).Within(TimeSpan.FromSeconds(2)), "The authorization buffer should have been used for buffering.");
        }