public void HoldInstanceWithNull() { // Setup var lifespan = new CacheLifespan(); // Execute lifespan.Hold(a_instance: null); }
public void ConstructCacheLifespanWithTimespan() { // Setup var timeout = TimeSpan.FromMinutes(1); // Execute var lifespan = new CacheLifespan(timeout); // Assert Assert.AreEqual(timeout, lifespan.Timeout); }
public void HoldInstance() { // Setup var lifespan = new CacheLifespan(); var instance = new object(); // Execute lifespan.Hold(instance); // Assert Assert.AreSame(instance, lifespan.Instance); }
public void KillInstanceWithNoInstanceHeld() { // Setup var lifespan = new CacheLifespan(); var instance = new object(); lifespan.Hold(instance); // Execute lifespan.Kill(); // Assert Assert.IsNull(lifespan.Instance); }
public void ResolveServiceTwiceWithCacheLifespan() { // Setup var lifespan = new CacheLifespan(TimeSpan.FromMinutes(5)); var container = new Container(); var service = new Service(container, typeof(ServiceWithDefaultConstructor), typeof(ServiceBase), a_lifespan: lifespan); // Execute var serviceInstance1 = service.Resolve(); var serviceInstance2 = service.Resolve(); // Assert Assert.AreSame(serviceInstance1, serviceInstance2); }
public async Task WaitPastTimeout() { // Setup var lifespan = new CacheLifespan(TimeSpan.FromMilliseconds(500)); var instance = new object(); lifespan.Hold(instance); // Execute await Task.Delay(1000); // Assert Assert.IsNull(lifespan.Instance); }