public void DisableAFCache() { AFGlobalSettings.CacheMaxObjects = 0; AFGlobalSettings.CacheTime = 0; PISystems systems = new PISystems(true); AFElement element1 = systems.Find <AFElement>(elementPath); AFElement element2 = systems.Find <AFElement>(elementPath); Assert.Same(element1, element2); }
public void ObserveGarbageCollectorBehavior() { #region Case One AFGlobalSettings.CacheMaxObjects = 100; PISystems systems = new PISystems(true); AFElement myElement = systems.Find <AFElement>(elementPath); WeakReference <AFElement> myRef = new WeakReference <AFElement>(myElement); myElement = null; GC.Collect(); Assert.True(myRef.TryGetTarget(out myElement)); #endregion #region Case Two AFGlobalSettings.CacheMaxObjects = 0; systems = new PISystems(true); myElement = systems.Find <AFElement>(elementPath); myRef = new WeakReference <AFElement>(myElement); myElement = null; GC.Collect(); Assert.False(myRef.TryGetTarget(out myElement)); #endregion }
public void ForceNewInstance() { PISystems systems1 = new PISystems(true); AFElement element1 = AFObject.FindObject(elementPath, systems1.DefaultPISystem) as AFElement; PISystems systems2 = new PISystems(true); AFElement element2 = AFObject.FindObject(elementPath, systems2.DefaultPISystem) as AFElement; Assert.NotSame(element1, element2); #region Shorthand // In shorthand (using an extension method) element1 = systems1.Find <AFElement>(elementPath); element2 = systems2.Find <AFElement>(elementPath); Assert.NotSame(element1, element2); #endregion }