Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AlfredSpeechConsole" /> class.
        /// </summary>
        /// <param name="console">The console that events should be logged to.</param>
        /// <param name="factory">The event factory.</param>
        public AlfredSpeechConsole([CanBeNull] IConsole console, [CanBeNull] ConsoleEventFactory factory)
        {
            // This class can decorate other consoles, but for an empty implementation it can rely on an internal collection
            if (console == null)
            {
                console = new SimpleConsole();
            }
            _console = console;

            // Set up the event factory
            if (factory == null) { factory = new ConsoleEventFactory(); }
            EventFactory = factory;

            // Tell it what log levels we care about
            _speechEnabledLogLevels = new HashSet<LogLevel> { LogLevel.ChatResponse, LogLevel.Warning, LogLevel.Error };

            try
            {
                // Give the speech provider the existing console and not this console since it won't be online yet
                _speech = new AlfredSpeechProvider(console);
            }
            catch (InvalidOperationException ex)
            {
                // On failure creating the speech provider, just have speech be null and we'll just be a decorator
                _speech = null;
                Log("Init.Console", $"Speech could not be initialized: {ex.Message}", LogLevel.Error);
            }
        }
Esempio n. 2
0
        public void TimeModuleDoesNotLogWhenTheHourDoesNotChange()
        {
            var console = new SimpleConsole();
            _alfred.Console = console;
            _alfred.Initialize();

            // This is a bit of a testing hack - since initialize causes the module to update, it'll update based on the current time.
            // This is what it should do, but we want to force updates given specific times so we'll just clear out the
            // stored value from the initial run
            _module.ClearLastTimeRun();

            _module.Update(new DateTime(1980, 9, 10, 9, 0, 0));
            _module.Update(new DateTime(1980, 9, 10, 9, 0, 30));
            _module.Update(new DateTime(1980, 9, 10, 9, 1, 0));

            // This will error if 0 or > 1 events are logged
            Assert.IsFalse(
                           console.Events.Any(e => e.Title == AlfredTimeModule.HourAlertEventTitle),
                           "Updating to times not in a new hour should not have logged");
        }
Esempio n. 3
0
        /// <summary>
        ///     Registers the default Alfred <paramref name="container" /> with good default testing
        ///     values.
        /// </summary>
        /// <exception cref="ArgumentNullException"> <paramref name="container" /> </exception>
        /// <param name="container"> The container. </param>
        public static void RegisterDefaultAlfredMappings([NotNull] this IObjectContainer container)
        {
            if (container == null) { throw new ArgumentNullException(nameof(container)); }

            var console = new SimpleConsole(container);
            console.RegisterAsProvidedInstance(typeof(IConsole), container);

            // Register mappings for promised types
            container.Register(typeof(IConsoleEvent), typeof(ConsoleEvent));
            container.Register(typeof(MetricProviderBase), typeof(ValueMetricProvider));

            // We'll want to get at the same factory any time we request a factory for test purposes
            var factory = new ValueMetricProviderFactory();
            factory.RegisterAsProvidedInstance(typeof(IMetricProviderFactory), container);
            factory.RegisterAsProvidedInstance(typeof(ValueMetricProviderFactory), container);
        }