示例#1
0
        public static async Task CachedValueIsReturnedAgainAfterExpiry()
        {
            var mockInner = new Mock <IPEndPointSource>();

            mockInner.Setup(x => x.GetEndpoint()).Returns(MakeTestIpEndPoint());

            var cachedEndpoint = new CachedIpEndpointSource(mockInner.Object, TimeSpan.FromSeconds(1));

            var value1 = cachedEndpoint.GetEndpoint();
            var value2 = cachedEndpoint.GetEndpoint();

            await Task.Delay(1500);

            var value3 = cachedEndpoint.GetEndpoint();
            var value4 = cachedEndpoint.GetEndpoint();

            mockInner.Verify(x => x.GetEndpoint(), Times.Exactly(2));
        }
示例#2
0
        public static void CachedValueIsReturnedOnce()
        {
            var mockInner = new Mock <IPEndPointSource>();

            mockInner.Setup(x => x.GetEndpoint()).Returns(MakeTestIpEndPoint());

            var cachedEndpoint = new CachedIpEndpointSource(mockInner.Object, TimeSpan.FromMinutes(5));

            var value1 = cachedEndpoint.GetEndpoint();
            var value2 = cachedEndpoint.GetEndpoint();
            var value3 = cachedEndpoint.GetEndpoint();

            value1.ShouldNotBeNull();
            value1.ShouldBe(value2);
            value1.ShouldBe(value3);

            mockInner.Verify(x => x.GetEndpoint(), Times.Exactly(1));
        }