public static async Task CachedValueIsReturnedAgainAfterExpiry() { var mockInner = new Mock <IEndPointSource>(); mockInner.Setup(x => x.GetEndpoint()).Returns(MakeTestIpEndPoint()); var cachedEndpoint = new CachedEndpointSource(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)); }
public static void CachedValueIsReturnedOnce() { var mockInner = new Mock <IEndPointSource>(); mockInner.Setup(x => x.GetEndpoint()).Returns(MakeTestIpEndPoint()); var cachedEndpoint = new CachedEndpointSource(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)); }