public void ReloadPreviousContext() { INamedVersionedUniqueId pluginId = new SimpleNamedVersionedUniqueId( Guid.NewGuid(), Util.EmptyVersion, "JustForTest" ); // Creates typical user configuration. { var host = new TestContextHost( "ReloadPreviousContext" ); File.Delete( host.SystemConfigAddress.LocalPath ); File.Delete( host.DefaultUserConfigAddress.LocalPath ); var ctx = host.CreateContext(); Assert.That( ctx.ConfigManager.SystemConfiguration != null ); Assert.That( ctx.ConfigManager.UserConfiguration != null, "Accessing it, creates it." ); Assert.That( ctx.ConfigManager.SystemConfiguration.UserProfiles.Current, Is.Not.Null, "It becomes the current one." ); Assert.That( !ctx.ConfigManager.Extended.Container.Contains( pluginId ), "The plugin is not known yet." ); ctx.ConfigManager.Extended.Container[ctx, pluginId, "testKey"] = "testValue"; Assert.That( ctx.ConfigManager.Extended.Container.Contains( pluginId ), "Setting a value ensures that the plugin is registered." ); host.SaveContext( GetTestFileUri( "Context" ) ); host.SaveUserConfig(); host.SaveSystemConfig(); TestBase.DumpFileToConsole( GetTestFileUri( "Context" ).LocalPath ); } // Loads existing configuration. { var host = new TestContextHost( "ReloadPreviousContext" ); var ctx = host.CreateContext(); ctx.ConfigManager.Extended.Container.Ensure( pluginId ); host.LoadContext(); Assert.That( ctx.ConfigManager.Extended.Container[ctx, pluginId, "testKey"], Is.EqualTo( "testValue" ) ); } }
private static void CheckAllDataLoaded( object rootObject, ITestObject complexObject, SimpleNamedVersionedUniqueId p1, SimpleNamedVersionedUniqueId p2, SharedDictionaryImpl dic ) { ITestObject obj = (ITestObject)dic[rootObject, p1, "complexObject"]; Assert.That( obj != null ); Assert.That( obj.Value == complexObject.Value ); string value = (string)dic[obj, p2, "subKey"]; Assert.That( value == "subValue" ); }
void TryReloadNestedSkippedFragments( ITestObject complexObject ) { object rootObject = new object(); SimpleNamedVersionedUniqueId p1 = new SimpleNamedVersionedUniqueId( Guid.NewGuid(), new Version( 1, 0, 0 ), "plugin1" ); SimpleNamedVersionedUniqueId p2 = new SimpleNamedVersionedUniqueId( Guid.NewGuid(), new Version( 1, 0, 0 ), "plugin2" ); string path = TestBase.GetTestFilePath( "SharedDic", "NestedSkippedFragments" ); // Write ! { SharedDictionaryImpl dic = new SharedDictionaryImpl( SharedDicTestContext.ServiceProvider ); dic[rootObject, p1, "complexObject"] = complexObject; dic[complexObject, p2, "subKey"] = "subValue"; SharedDicTestContext.Write( "Test", path, dic, rootObject ); TestBase.DumpFileToConsole( path ); } // Read nothing then p1 and p2 { IList<ReadElementObjectInfo> errors = new List<ReadElementObjectInfo>(); SharedDictionaryImpl dic = (SharedDictionaryImpl)SharedDicTestContext.Read( "Test", path, rootObject, out errors ); dic.Ensure( p1 ); dic.Ensure( p2 ); CheckAllDataLoaded( rootObject, complexObject, p1, p2, dic ); } // Read nothing then p2 and p1 { IList<ReadElementObjectInfo> errors = new List<ReadElementObjectInfo>(); SharedDictionaryImpl dic = (SharedDictionaryImpl)SharedDicTestContext.Read( "Test", path, rootObject, out errors ); dic.Ensure( p2 ); dic.Ensure( p1 ); CheckAllDataLoaded( rootObject, complexObject, p1, p2, dic ); } // Ensure p1 then read p2 { IList<ReadElementObjectInfo> errors = new List<ReadElementObjectInfo>(); SharedDictionaryImpl dic = (SharedDictionaryImpl)SharedDicTestContext.Read( "Test", path, rootObject, d => d.Ensure( p1 ), out errors ); dic.Ensure( p2 ); CheckAllDataLoaded( rootObject, complexObject, p1, p2, dic ); } // Ensure p2 then read p1 { IList<ReadElementObjectInfo> errors = new List<ReadElementObjectInfo>(); SharedDictionaryImpl dic = (SharedDictionaryImpl)SharedDicTestContext.Read( "Test", path, rootObject, d => d.Ensure( p2 ), out errors ); dic.Ensure( p1 ); CheckAllDataLoaded( rootObject, complexObject, p1, p2, dic ); } // Ensure p1 and p2 then read nothing { IList<ReadElementObjectInfo> errors = new List<ReadElementObjectInfo>(); SharedDictionaryImpl dic = (SharedDictionaryImpl)SharedDicTestContext.Read( "Test", path, rootObject, d => { d.Ensure( p1 ); d.Ensure( p2 ); }, out errors ); CheckAllDataLoaded( rootObject, complexObject, p1, p2, dic ); } // Ensure p2 and p1 then read nothing { IList<ReadElementObjectInfo> errors = new List<ReadElementObjectInfo>(); SharedDictionaryImpl dic = (SharedDictionaryImpl)SharedDicTestContext.Read( "Test", path, rootObject, d => { d.Ensure( p2 ); d.Ensure( p1 ); }, out errors ); CheckAllDataLoaded( rootObject, complexObject, p1, p2, dic ); } }