示例#1
0
        public static void CachedValueIsReturnedFromInner()
        {
            var mockInner = new Mock <IPEndPointSource>();

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

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

            var value = cachedEndpoint.GetEndpoint();

            value.ShouldNotBeNull();
            value.ShouldBe(MakeTestIpEndPoint());

            mockInner.Verify(x => x.GetEndpoint(), Times.Exactly(1));
        }
示例#2
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));
        }