Exemplo n.º 1
0
        public void OnStarting_Always_ResetsSettings()
        {
            var uut = new ProgramSettingsProvider();

            uut.OnStarting();

            uut.Settings.ManageInterval.ShouldNotBe(TimeSpan.Zero);
        }
Exemplo n.º 2
0
        public void Settings_Always_SavesValue(int manageIntervalMilliseconds)
        {
            var uut = new ProgramSettingsProvider();

            var settings = new ProgramSettings()
            {
                ManageInterval = TimeSpan.FromMilliseconds(manageIntervalMilliseconds)
            };

            uut.Settings = settings;

            uut.Settings.ShouldBe(settings);
        }
Exemplo n.º 3
0
        public void OnParsing_OptionIsUnknown_ReturnsIgnoredAndDoesNotChangeSettings(params string[] linePieces)
        {
            var configLine = new ConfigLine(linePieces);

            var uut = new ProgramSettingsProvider();

            var settings = uut.Settings;

            var result = uut.OnParsing(configLine);

            result.IsIgnored.ShouldBeTrue();

            uut.Settings.ShouldBe(settings);
        }
Exemplo n.º 4
0
        public void OnParsing_ParamsAreInvalid_ReturnsErrorAndDoesNotChangeSettings(params string[] linePieces)
        {
            var configLine = new ConfigLine(linePieces);

            var uut = new ProgramSettingsProvider();

            var settings = uut.Settings;

            var result = uut.OnParsing(configLine);

            result.IsError.ShouldBeTrue();
            result.Error.ShouldContain(configLine.Option);

            uut.Settings.ShouldBe(settings);
        }
Exemplo n.º 5
0
        public void OnCompleted_Always_DoesNothing(int manageIntervalMilliseconds)
        {
            var uut = new ProgramSettingsProvider();

            var settings = new ProgramSettings()
            {
                ManageInterval = TimeSpan.FromMilliseconds(manageIntervalMilliseconds)
            };

            uut.Settings = settings;

            uut.OnCompleted();

            uut.Settings.ShouldBe(settings);
        }
Exemplo n.º 6
0
        public void OnParsing_ParamsAreValidForBlockTag_ReturnsSuccessAndSetsBlockTag(params string[] linePieces)
        {
            var configLine = new ConfigLine(linePieces);

            var uut = new ProgramSettingsProvider();

            var settings = uut.Settings;

            settings.ManageInterval = TimeSpan.FromMilliseconds(int.Parse(configLine.GetParam(0)));

            var result = uut.OnParsing(configLine);

            result.IsSuccess.ShouldBeTrue();

            uut.Settings.ShouldBe(settings);
        }
Exemplo n.º 7
0
        public Program()
        {
            var doorManagerSettingsProvider = new DoorManagerSettingsProvider();

            var dateTimeProvider             = new DateTimeProvider();
            var loggerSettingsProvider       = new LoggerSettingsProvider();
            var managedBlockSettingsProvider = new ManagedBlockSettingsProvider();
            var managedDoorSettingsProvider  = new ManagedDoorSettingsProvider(
                doorManagerSettingsProvider);

            var logger = new Logger(
                dateTimeProvider,
                loggerSettingsProvider);
            var managedBlockConfigParseHandlers = new IManagedBlockConfigParseHandler[]
            {
                managedBlockSettingsProvider,
                managedDoorSettingsProvider
            };
            var managerSettingsProvider = new ManagerSettingsProvider()
            {
                DefaultBlockTag = "DoorManager"
            };

            var doorManager = new DoorManager(
                dateTimeProvider,
                doorManagerSettingsProvider,
                logger);
            var managedBlockConfigManager = new ManagedBlockConfigManager(
                logger,
                managedBlockConfigParseHandlers,
                managerSettingsProvider);

            var managedBlockCollectionHandler = new ManagedBlockCollectionHandler(
                managedBlockConfigManager,
                managedBlockSettingsProvider,
                managerSettingsProvider,
                Me);
            var managedDoorCollectionHandler = new ManagedDoorCollectionHandler(
                doorManager,
                logger,
                managedDoorSettingsProvider);

            var backgroundWorkerSettingsProvider = new BackgroundWorkerSettingsProvider();
            var blockCollectionHandlers          = new IBlockCollectionHandler[]
            {
                managedBlockCollectionHandler,
                managedDoorCollectionHandler
            };

            var backgroundWorker = new BackgroundWorker(
                backgroundWorkerSettingsProvider,
                dateTimeProvider,
                Runtime);
            var blockCollectionManager = new BlockCollectionManager <IMyDoor>(
                blockCollectionHandlers,
                GridTerminalSystem);
            var programSettingsProvider = new ProgramSettingsProvider();

            var programReloadHandler = new ProgramReloadHandler(
                backgroundWorker,
                blockCollectionManager,
                doorManager,
                programSettingsProvider);

            var configParseHandlers = new IConfigParseHandler[]
            {
                loggerSettingsProvider,
                backgroundWorkerSettingsProvider,
                managerSettingsProvider,
                doorManagerSettingsProvider,
                programSettingsProvider,
                programReloadHandler
            };

            var configManager = new ConfigManager(
                configParseHandlers,
                logger,
                Me);
            var echoProvider = new EchoProvider(
                Echo);

            _programManager = new ProgramManager(
                backgroundWorker,
                configManager,
                doorManager,
                echoProvider,
                Runtime,
                logger);

            _programManager.Run("reload");
        }