public void Setup()
        {
            _applicationHost = new TestApplicationHost();
            var applicationPaths = _applicationHost.Resolve <IApplicationPaths>();

            var plugin = new Plugin(applicationPaths,
                                    _applicationHost.Resolve <IXmlSerializer>());

            plugin.SetConfiguration(new PluginConfiguration
            {
                TvDbApiKey = Secrets.TvDbApiKey
            });

            // pre-populate the cache to avoid spamming sources with requests when the tests run
            // (and for static test data)
            FileCacheHelper.SetupCachedFile(applicationPaths.CachePath, @"\AniDb\titles.xml",
                                            @"\anidb\titles\titles.xml");

            FileCacheHelper.SetupCachedFile(applicationPaths.CachePath, @"\AniDb\959.xml",
                                            @"\anidb\series\959\series.xml");

            FileCacheHelper.SetupCachedFile(applicationPaths.CachePath, @"\Mappings\anime-list.xml",
                                            @"\anime-list.xml");

            FileCacheHelper.SetupCachedFile(applicationPaths.CachePath, @"\TvDb\78914.json", @"\anidb\tvdb\78914.json");

            FileCacheHelper.SetupCachedFile(applicationPaths.CachePath, @"\TvDb\78914_Episodes.json",
                                            @"\anidb\tvdb\78914_Episodes.json");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an instance of corresponding class.
        /// </summary>
        /// <param name="testType">Type of the test to instantiate.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>Instance of the class.</returns>
        public static LiveTest Instantiate(Type testType, params object[] arguments)
        {
            if (HostingEnvironment.IsHosted)
            {
                return(CreateUninitializedInstance(testType));
            }

            if (InstantiatedByProxy(testType, arguments))
            {
                return(Intercept(testType, null));
            }

            MethodInfo getDefaultTestApplicationManagerMethod = Utility.GetInheritedMethod(testType, GetDefaultTestApplicationManagerName, new[] { typeof(Type), typeof(object[]) });
            MethodInfo getDefaultApplicationHostMethod        = Utility.GetInheritedMethod(testType, GetDefaultApplicationHostName, new[] { typeof(Type), typeof(object[]) });

            if (getDefaultTestApplicationManagerMethod == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Cannot create an instance of type '{0}' because there is no '{1}' static method defined in its inheritance hierarchy. See '{2}' methods for an example of corresponding method signature.", testType.AssemblyQualifiedName, GetDefaultTestApplicationManagerName, typeof(LiveTest).AssemblyQualifiedName));
            }

            if (getDefaultApplicationHostMethod == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Cannot create an instance of type '{0}' because there is no '{1}' static method defined in its inheritance hierarchy. See '{2}' methods for an example of corresponding method signature.", testType.AssemblyQualifiedName, GetDefaultApplicationHostName, typeof(LiveTest).AssemblyQualifiedName));
            }

            object[] allArguments = { testType, arguments };

            TestApplicationManager testApplicationManager = (TestApplicationManager)getDefaultTestApplicationManagerMethod.Invoke(null, allArguments);

            if (testApplicationManager == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Failed to get an instance of '{0}'.", typeof(TestApplicationManager).AssemblyQualifiedName));
            }

            TestApplicationHost host = (TestApplicationHost)getDefaultApplicationHostMethod.Invoke(null, allArguments);

            if (host == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Failed to get an instance of '{0}'.", typeof(TestApplicationHost).AssemblyQualifiedName));
            }

            TestApplication testApplication = testApplicationManager.StartApplication(host);

            if (testApplication == null)
            {
                throw new InvalidOperationException("Failed to get application to execute tests in.");
            }

            return((LiveTest)testApplication.CreateObject(testType, arguments));
        }
Exemplo n.º 3
0
        public void Stop()
        {
            var watcher = _host?.ServiceProvider
                          .GetServices <IHostedService>()
                          .OfType <ConsumersWatcher>()
                          .FirstOrDefault();

            watcher?.StopAsync(CancellationToken.None);

            _host?.Dispose();
            _host = null;

            _stoppingTokenSource?.Cancel();
            _stoppingTokenSource?.Dispose();
        }
Exemplo n.º 4
0
        public async Task Run()
        {
            if (_host != null)
            {
                throw new InvalidOperationException("This consumer app is already running.");
            }

            Console.CancelKeyPress += OnCancelKeyPress;

            PromptForGroupName();
            WriteHeader();

            _host = new TestApplicationHost <Startup>();
            _host.ConfigureServices(
                services => services.Configure <ConsumerGroupConfiguration>(
                    configuration => { configuration.ConsumerGroupName = _consumerGroupName; }));
            _host.Run();

            await LoopUntilStopped();
        }