public void InitalizeSettingWatchTask_InvokeCancel()
        {
            DummySettingCacheProvider2 provider = new DummySettingCacheProvider2(new DummyCacheManagerArguments()
            {
                CacheRefreshTimeout = () => TimeSpan.FromMilliseconds(0)
            });

            Assert.IsNull(SettingCacheProviderBase.LastRefreshedTime);

            provider.InitalizeSettingCacheProvider();

            Assert.IsNotNull(SettingCacheProviderBase.LastRefreshedTime);
            Assert.IsTrue(SettingCacheProviderBase.LastRefreshedTime > DateTime.MinValue);
            Assert.IsTrue(SettingCacheProviderBase.Initalized);

            SettingCacheProviderBase.CancelTask();
            SpinWait.SpinUntil(() =>
            {
                if (SettingCacheProviderBase.SettingWatchTask == null)
                {
                    return(true);
                }

                return(SettingCacheProviderBase.SettingWatchTask.IsCompleted);
            });

            Assert.IsTrue(SettingCacheProviderBase.SettingWatchTask.IsCompleted);
        }
Пример #2
0
            public static void CleanUpAfterTest()
            {
                typeof(SettingCacheProviderBase)
                .GetField("SettingDtosByKey", BindingFlags.Static | BindingFlags.NonPublic)
                .SetValue(null, new ConcurrentDictionary <string, DbAppSettingDto>());

                typeof(SettingCacheProviderBase)
                .GetField("LastRefreshedTime", BindingFlags.Static | BindingFlags.NonPublic)
                .SetValue(null, null);

                typeof(SettingCacheProviderBase)
                .GetProperty("Initalized", BindingFlags.Static | BindingFlags.NonPublic)
                .SetValue(null, false);

                SettingCacheProviderBase.CancelTask();
                SpinWait.SpinUntil(() =>
                {
                    if (SettingCacheProviderBase.SettingWatchTask == null)
                    {
                        return(true);
                    }

                    return(SettingCacheProviderBase.SettingWatchTask.IsCompleted);
                });

                typeof(SettingCacheProviderBase)
                .GetProperty("SettingWatchTask", BindingFlags.Static | BindingFlags.NonPublic)
                .SetValue(null, null);
            }