Beispiel #1
0
        private KinesisTapServiceManager Setup(out MockRepository repo, out MemoryLogger memLogger, out Mock <IEventSink> sink, out Mock <IEventSource <string> > source, bool setupSink = true, bool setupSource = true)
        {
            var logger = new MemoryLogger("UnitTest");

            repo = new MockRepository(MockBehavior.Loose);

            sink = repo.Create <IEventSink>();
            sink.SetupProperty(i => i.Id, "MockSink");

            // If setupSink is true, set up default Start and Stop implementations.
            if (setupSink)
            {
                sink.Setup(i => i.Start())
                .Callback(() => logger.LogDebug("MockSink started"))
                .Verifiable();
                sink.Setup(i => i.Stop())
                .Callback(() => logger.LogDebug("MockSink stopped"))
                .Verifiable();
            }

            source = repo.Create <IEventSource <string> >();
            source.SetupProperty(i => i.Id, "MockSource");

            // If setupSource is true, set up default Start and Stop implementations.
            if (setupSource)
            {
                source.Setup(i => i.Start())
                .Callback(() => logger.LogDebug("MockSource started"))
                .Verifiable();
                source.Setup(i => i.Stop())
                .Callback(() => logger.LogDebug("MockSource stopped"))
                .Verifiable();
            }

            var sourceFactory = repo.Create <IFactory <ISource> >();

            sourceFactory.Setup(i => i.CreateInstance(It.IsAny <string>(), It.IsAny <IPlugInContext>()))
            .Returns(source.Object)
            .Verifiable();
            sourceFactory.Setup(i => i.RegisterFactory(It.IsAny <IFactoryCatalog <ISource> >()))
            .Callback((IFactoryCatalog <ISource> catalog) => catalog.RegisterFactory("Mock", sourceFactory.Object))
            .Verifiable();

            var sinkFactory = repo.Create <IFactory <IEventSink> >();

            sinkFactory.Setup(i => i.CreateInstance(It.IsAny <string>(), It.IsAny <IPlugInContext>()))
            .Returns(sink.Object)
            .Verifiable();
            sinkFactory.Setup(i => i.RegisterFactory(It.IsAny <IFactoryCatalog <IEventSink> >()))
            .Callback((IFactoryCatalog <IEventSink> catalog) => catalog.RegisterFactory("Mock", sinkFactory.Object))
            .Verifiable();

            var parStore   = repo.Create <IParameterStore>();
            var typeLoader = repo.Create <ITypeLoader>();

            typeLoader.Setup(i => i.LoadTypes <IFactory <IEventSink> >())
            .Returns(new List <IFactory <IEventSink> > {
                sinkFactory.Object
            })
            .Verifiable();

            typeLoader.Setup(i => i.LoadTypes <IFactory <ISource> >())
            .Returns(new List <IFactory <ISource> > {
                sourceFactory.Object
            })
            .Verifiable();

            memLogger = logger;

            // Set the ConfigConstants.KINESISTAP_CONFIG_PATH environment variable to null.
            // If any other test has set this variable, these tests will fail.
            Environment.SetEnvironmentVariable(ConfigConstants.KINESISTAP_CONFIG_PATH, null);
            return(new KinesisTapServiceManager(typeLoader.Object, parStore.Object, logger));
        }