本文整理汇总了C#中Config.RootOf方法的典型用法代码示例。如果您正苦于以下问题:C# Config.RootOf方法的具体用法?C# Config.RootOf怎么用?C# Config.RootOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Config
的用法示例。
在下文中一共展示了Config.RootOf方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestRootOfNonExistantPropertyReturnsNotNull
public void TestRootOfNonExistantPropertyReturnsNotNull() {
IConfig config = new Config().Create<MockSimpleConcrete>();
var root = config.RootOf<TestRootOf>();
Assert.IsNotNull(root);
}
示例2: TestExplicitTypeRootOfSingleProperty
public void TestExplicitTypeRootOfSingleProperty() {
IConfig config = new Config().Create<MockSimpleConcrete>();
var root = config.RootOf(typeof(MockSimpleConcrete));
Assert.AreEqual("Potato.Core.Shared.Test.TestConfig.Mocks.MockSimpleConcrete", ((JProperty)root.Parent).Name);
}
示例3: TestRootOfNotCreatedForProperty
public void TestRootOfNotCreatedForProperty() {
IConfig config = new Config().Create<MockSimpleConcrete>();
config.Document.Add(new JProperty("Potato.Core.Shared.Test.TestConfig.TestRootOf", new JArray()));
var root = config.RootOf<TestRootOf>();
Assert.AreEqual("Potato.Core.Shared.Test.TestConfig.TestRootOf", ((JProperty)root.Parent).Name);
}
示例4: TestRootOfMultipleProperties
public void TestRootOfMultipleProperties() {
IConfig config = new Config().Create<MockSimpleConcrete>();
config.Document.Add(new JProperty("Potato.Core.Shared.Test.TestConfig.Mocks.DoesNotExist", new JArray()));
var root = config.RootOf<MockSimpleConcrete>();
Assert.AreEqual("Potato.Core.Shared.Test.TestConfig.Mocks.MockSimpleConcrete", ((JProperty)root.Parent).Name);
}
示例5: TestPotatoConfigWritten
public void TestPotatoConfigWritten() {
var instance = (PotatoController)new PotatoController() {
Shared = {
Variables = new VariableController().Execute() as VariableController,
Security = new SecurityController().Execute() as SecurityController,
Events = new EventsController().Execute() as EventsController,
Languages = new LanguageController().Execute() as LanguageController
}
}.Execute();
instance.Shared.Variables.Tunnel(CommandBuilder.VariablesSet(CommonVariableNames.PotatoConfigPassword, "PotatoConfigurationPassword").SetOrigin(CommandOrigin.Local));
instance.Connections.Add(new ConnectionController() {
ConnectionModel = new ConnectionModel() {
ProtocolType = new ProtocolType() {
Name = "Mock Protocol",
Provider = "Myrcon",
Type = "MockProtocol"
},
Hostname = "1.1.1.1",
Port = 27516,
Arguments = "",
Password = "password"
}
});
instance.WriteConfig();
var loadConfig = new Config();
loadConfig.Load(ConfigFileInfo);
var configCommand = loadConfig.RootOf<PotatoController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList().Last();
configCommand.Decrypt("PotatoConfigurationPassword");
Assert.AreEqual("PotatoAddConnection", configCommand.Command.Name);
Assert.AreEqual("Myrcon", configCommand.Command.Parameters[0].First<String>());
Assert.AreEqual("MockProtocol", configCommand.Command.Parameters[1].First<String>());
Assert.AreEqual("1.1.1.1", configCommand.Command.Parameters[2].First<String>());
Assert.AreEqual("27516", configCommand.Command.Parameters[3].First<String>());
Assert.AreEqual("password", configCommand.Command.Parameters[4].First<String>());
Assert.AreEqual("", configCommand.Command.Parameters[5].First<String>());
instance.Dispose();
}
示例6: TestEnabledPluginSavedToConfig
public void TestEnabledPluginSavedToConfig() {
Guid connectionGuid = Guid.NewGuid();
Guid onePluginGuid = Guid.NewGuid();
Guid twoPluginGuid = Guid.NewGuid();
ICorePluginController plugins = new CorePluginController() {
Connection = new ConnectionController() {
ConnectionModel = new ConnectionModel() {
ConnectionGuid = connectionGuid
}
},
LoadedPlugins = new List<PluginModel>() {
new PluginModel() {
Name = "One",
IsEnabled = false,
PluginGuid = onePluginGuid
},
new PluginModel() {
Name = "Two",
IsEnabled = true,
PluginGuid = twoPluginGuid
}
}
};
IConfig config = new Config().Create<CorePluginController>();
plugins.WriteConfig(config);
config.Save(this.ConfigFile);
// Now load up the config and ensure it saved what we wanted it too.
var loadConfig = new Config();
loadConfig.Load(this.ConfigFile);
var commands = loadConfig.RootOf<CorePluginController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList();
Assert.AreEqual("PluginsEnable", commands[0].Command.Name);
Assert.AreEqual(connectionGuid, commands[0].Command.Scope.ConnectionGuid);
Assert.AreEqual(twoPluginGuid, commands[0].Command.Scope.PluginGuid);
}
示例7: TestSecurityWriteConfig
public void TestSecurityWriteConfig() {
var security = new SecurityController();
security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityAddGroup,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"GroupName"
})
});
security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityGroupSetPermission,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"GroupName",
"CustomPermission",
22
})
});
security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityGroupSetPermission,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"GroupName",
CommandType.VariablesSet,
77
})
});
security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityGroupSetPermission,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"GroupName",
CommandType.VariablesSetA,
88
})
});
security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityGroupAddAccount,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"GroupName",
"Phogue"
})
});
security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityAccountSetPassword,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"Phogue",
"password"
})
});
security.Tunnel(CommandBuilder.SecurityAccountAppendAccessToken("Phogue", Guid.Parse("f380eb1e-1438-48c0-8c3d-ad55f2d40538"), "Token Hash", DateTime.Parse("2024-04-14 20:51:00 PM")).SetOrigin(CommandOrigin.Local));
security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityAccountSetPreferredLanguageCode,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"Phogue",
"de-DE"
})
});
security.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.SecurityAccountAddPlayer,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"Phogue",
CommonProtocolType.DiceBattlefield3,
"ABCDEF"
})
});
// Save a config of the language controller
var saveConfig = new Config();
saveConfig.Create(typeof(SecurityController));
security.WriteConfig(saveConfig);
saveConfig.Save(ConfigFileInfo);
// Load the config in a new config.
var loadConfig = new Config();
loadConfig.Load(ConfigFileInfo);
var commands = loadConfig.RootOf<SecurityController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList();
Assert.AreEqual("SecurityAddGroup", commands[0].Command.Name);
Assert.AreEqual("Guest", commands[0].Command.Parameters[0].First<String>());
Assert.AreEqual("SecurityAddGroup", commands[1].Command.Name);
Assert.AreEqual("GroupName", commands[1].Command.Parameters[0].First<String>());
Assert.AreEqual("SecurityGroupSetPermission", commands[2].Command.Name);
Assert.AreEqual("GroupName", commands[2].Command.Parameters[0].First<String>());
Assert.AreEqual(CommandType.VariablesSet.ToString(), commands[2].Command.Parameters[1].First<String>());
Assert.AreEqual("77", commands[2].Command.Parameters[2].First<String>());
Assert.AreEqual("SecurityGroupSetPermission", commands[3].Command.Name);
Assert.AreEqual("GroupName", commands[3].Command.Parameters[0].First<String>());
Assert.AreEqual(CommandType.VariablesSetA.ToString(), commands[3].Command.Parameters[1].First<String>());
Assert.AreEqual("88", commands[3].Command.Parameters[2].First<String>());
//.........这里部分代码省略.........
示例8: TestWriteConfig
public void TestWriteConfig() {
var variables = (VariableController)new VariableController().Execute();
variables.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.VariablesSetA,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"NameToWriteString",
"this is a string"
})
});
variables.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.VariablesSetA,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"NameToWriteInteger",
1
})
});
// Empty strings should not be written. No point saving nothing.
variables.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.VariablesSetA,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"NameToignore",
""
})
});
variables.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.VariablesSet,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
"NameToNotWrite",
"This shouldn't appear in the saved file."
})
});
variables.Tunnel(new Command() {
Origin = CommandOrigin.Local,
CommandType = CommandType.VariablesSetA,
Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
CommonVariableNames.MaximumProtocolConnections,
10
})
});
// Save a config of the variables controller
var saveConfig = new Config();
saveConfig.Create(typeof (VariableController));
variables.WriteConfig(saveConfig);
saveConfig.Save(ConfigFileInfo);
// Load the config in a new config.
var loadConfig = new Config();
loadConfig.Load(ConfigFileInfo);
var commands = loadConfig.RootOf<VariableController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList();
// Order is not maintained so we can only check that the values in some disorder are output.
// Nope, not perfect.
foreach (var command in commands) {
Assert.AreEqual("VariablesSetA", command.Command.Name);
Assert.IsTrue(new List<String>() { "NameToWriteString", "NameToWriteInteger", "MaximumProtocolConnections" }.Contains(command.Command.Parameters[0].First<String>()));
Assert.IsTrue(new List<String>() { "this is a string", "1", "10" }.Contains(command.Command.Parameters[1].First<String>()));
}
}