/// <summary> /// Create an <see cref="Kernel" /> instance from a given settings file name. /// </summary> /// <param name="settings">The file name in the '.\config\' folder of the settings to use during the initialization (default: 'settings.xml').</param> /// <returns></returns> public static Kernel CreateFromSettings(string settings = @"config\settings.xml") { if (string.IsNullOrWhiteSpace(settings)) { throw new ArgumentException( @"Settings file name cannot be null or whitespace (default: 'settings.xml').", nameof(settings)); } Config config = Config.Instance; Registry registry = Registry.Instance; config.Initialize(settings); if (!config.IsInitialized) { throw new InvalidOperationException( "Cannot create Kernel: couldn't correctly initialize the configuration"); } registry.Initialize(config); if (!registry.IsInitialized) { throw new InvalidOperationException( "Cannot create Kernel: couldn't correctly initialize the registry"); } var agentProvider = AgentProvider.BuildFromConfig(config, registry); return(new Kernel(agentProvider.GetAgents(), config)); }
public void ThrowsExceptionWhenBuildingAgents() { // Arrange var expected = new Exception("ignored string"); var stubRegistry = new Mock <IRegistry>(); stubRegistry.SetupGet(r => r.IsInitialized) .Returns(true); // Act / Assert var actual = Assert.Throws <Exception>( () => AgentProvider.BuildFromConfig(new SaboteurAgentConfig(expected), stubRegistry.Object)); Assert.Equal(expected, actual); }
public void AssembleAgentBaseClasses_IfTypeIsSpecified() { // Arrange // Minder agents are being created and uses the registry Registry.Instance.Initialize(StubConfig.Default); var stubRegistry = new Mock <IRegistry>(); stubRegistry.SetupGet(r => r.IsInitialized) .Returns(true); stubRegistry.SetupGet(r => r.CreateDatastoreContext) .Returns(() => (DatastoreContext)null); var sut = AgentProvider.BuildFromConfig(new SingleAgentConfig(), stubRegistry.Object); // Act IEnumerable <IAgent> agents = sut.GetAgents(); // Assert Assert.NotEmpty(agents); }