internal UnitTestFramework(
     ISutCreator sutCreator,
     ITellChildWaiter childTeller,
     IChildWaiter childWaiter,
     IDependencyResolverAdder resolverAdder,
     ITestProbeDependencyResolverAdder testProbeDependencyResolverAdder,
     ITestProbeCreator testProbeCreator,
     IResolvedTestProbeStore resolvedProbeStore,
     ITestProbeActorCreator testProbeActorCreator,
     ITestProbeHandlersMapper handlersMapper,
     ISutSupervisorStrategyGetter sutSupervisorStrategyGetter,
     ImmutableDictionary <(Type, Type), Func <object, object> > handlers,
Example #2
0
        public TestBase() : base(AkkaConfig.Config)
        {
            Func <Type> generateType = TestUtils.RandomTypeGenerator();

            // Create mocks
            SutCreatorMock                       = new Mock <ISutCreator>();
            ChildTellerMock                      = new Mock <ITellChildWaiter>();
            ChildWaiterMock                      = new Mock <IChildWaiter>();
            DependencyResolverAdderMock          = new Mock <IDependencyResolverAdder>();
            TestProbeDependencyResolverAdderMock = new Mock <ITestProbeDependencyResolverAdder>();
            ResolvedTestProbeStoreMock           = new Mock <IResolvedTestProbeStore>();
            TestProbeActorCreatorMock            = new Mock <ITestProbeActorCreator>();
            TestProbeCreatorMock                 = new Mock <ITestProbeCreator>();
            TestProbeHandlersMapperMock          = new Mock <ITestProbeHandlersMapper>();
            TestProbeActorMock                   = new Mock <ITestProbeActor>();
            SutSupervisorStrategyGetterMock      = new Mock <ISutSupervisorStrategyGetter>();

            // Create objects passed into sut constructor
            SutCreator                       = SutCreatorMock.Object;
            ChildTeller                      = ChildTellerMock.Object;
            ChildWaiter                      = ChildWaiterMock.Object;
            DependencyResolverAdder          = DependencyResolverAdderMock.Object;
            TestProbeDependencyResolverAdder = TestProbeDependencyResolverAdderMock.Object;
            TestProbeCreator                 = TestProbeCreatorMock.Object;
            ResolvedTestProbeStore           = ResolvedTestProbeStoreMock.Object;
            TestProbeActorCreator            = TestProbeActorCreatorMock.Object;
            TestProbeHandlersMapper          = TestProbeHandlersMapperMock.Object;
            SutSupervisorStrategyGetter      = SutSupervisorStrategyGetterMock.Object;
            Handlers = ImmutableDictionary <(Type, Type), Func <object, object> >
                       .Empty
                       .Add((generateType(), generateType()), message => TestUtils.Create <object>());

            Props = Props.Create <DummyActor>();
            PropsWithSupervisorStrategy = Props
                                          .Create <DummyActor>()
                                          .WithSupervisorStrategy(new AllForOneStrategy(
                                                                      TestUtils.Create <int>(),
                                                                      TestUtils.Create <int>(),
                                                                      exception => TestUtils.Create <Directive>()));
            ExpectedChildCount = TestUtils.Create <int>();

            // Create objects passed into sut methods
            Message   = TestUtils.Create <object>();
            ChildName = TestUtils.Create <string>();
            ChildNameWithoutSupervisor = TestUtils.Create <string>();
            Sender = new Mock <IActorRef>().Object;

            // Create objects returned by mocks
            MappedHandlers = ImmutableDictionary <Type, ImmutableDictionary <Type, Func <object, object> > >
                             .Empty
                             .Add(generateType(), ImmutableDictionary <Type, Func <object, object> >
                                  .Empty
                                  .Add(generateType(), mess => TestUtils.Create <object>()));

            Supervisor                 = CreateTestProbe();
            SutActor                   = ActorOfAsTestActorRef <DummyActor>();
            ResolvedType               = generateType();
            ResolvedTestProbe          = CreateTestProbe();
            ResolvedSupervisorStrategy = new AllForOneStrategy(
                TestUtils.Create <int>(),
                TestUtils.Create <int>(),
                exception => TestUtils.Create <Directive>());
            SutSupervisorStrategy = new OneForOneStrategy(
                TestUtils.Create <int>(),
                TestUtils.Create <int>(),
                exception => TestUtils.Create <Directive>());

            // Set up mocks
            TestProbeCreatorMock
            .SetupSequence(creator => creator.Create(this))
            .Returns(Supervisor)
            .Returns(CreateTestProbe());

            SutCreatorMock
            .Setup(creator => creator.Create <DummyActor>(
                       ChildWaiterMock.Object,
                       this,
                       Props,
                       ExpectedChildCount,
                       Supervisor))
            .Returns(() => SutActor);

            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedType(SutActor, ChildName))
            .Returns(() => ResolvedType);
            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedTestProbe(SutActor, ChildName))
            .Returns(() => ResolvedTestProbe);
            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedSupervisorStrategy(SutActor, ChildName))
            .Returns(() => ResolvedSupervisorStrategy);
            ResolvedTestProbeStoreMock
            .Setup(store => store.FindResolvedSupervisorStrategy(SutActor, ChildNameWithoutSupervisor))
            .Returns(() => null);

            TestProbeHandlersMapperMock
            .Setup(mapper => mapper.Map(Handlers))
            .Returns(() => MappedHandlers);

            SutSupervisorStrategyGetterMock
            .Setup(getter => getter.Get(SutActor.UnderlyingActor))
            .Returns(() => SutSupervisorStrategy);
        }
        public TestBase() : base(AkkaConfig.Config)
        {
            // Create values passed into sut
            TestKitPassedIntoSut  = this;
            HandlersPassedIntoSut = ImmutableDictionary <(Type, Type), Func <object, object> >
                                    .Empty
                                    .Add((typeof(DummyActor1), typeof(Message1)), message1 => new Reply1())
                                    .Add((typeof(DummyActor1), typeof(Message2)), message1 => new Reply2())
                                    .Add((typeof(DummyActor2), typeof(Message1)), message1 => new Reply1());

            PropsPassedIntoSut      = Props.Create <DummyActor1>();
            NumberOfChildrenIntoSut = TestUtils.Create <int>();

            // Create shims
            _shimContext = ShimsContext.Create();

            // Set up shims
            ShimSutCreator.Constructor = @this =>
            {
                SutCreatorConstructorCount++;
                ConstructedSutCreator = @this;
            };

            ShimTellChildWaiter.Constructor = @this =>
            {
                TellChildWaiterConstructorCount++;
                ConstructedTellChildWaiter = @this;
            };

            ShimChildWaiter.Constructor = @this =>
            {
                ChildWaiterConstructorCount++;
                ConstructedChildWaiter = @this;
            };

            ShimDependencyResolverAdder.Constructor = @this =>
            {
                DependencyResolverAdderConstructorCount++;
                ConstructedDependencyResolverAdder = @this;
            };

            ShimTestProbeDependencyResolverAdder.Constructor = @this =>
            {
                TestProbeDependencyResolverAdderConstructorCount++;
                ConstructedTestProbeDependencyResolverAdder = @this;
            };

            ShimTestProbeCreator.Constructor = @this =>
            {
                TestProbeCreatorConstructorCount++;
                ConstructedTestProbeCreator = @this;
            };

            ShimResolvedTestProbeStore.Constructor = @this =>
            {
                ResolvedTestProbeStoreConstructorCount++;
                ConstructedResolvedTestProbeStore = @this;
            };

            ShimTestProbeActorCreator.Constructor = @this =>
            {
                TestProbeActorCreatorConstructorCount++;
                ConstructedTestProbeActorCreator = @this;
            };

            ShimTestProbeHandlersMapper.Constructor = @this =>
            {
                TestProbeHandlersMapperConstructorCount++;
                ConstructedTestProbeHandlersMapper = @this;
            };

            ShimSutSupervisorStrategyGetter.Constructor = @this =>
            {
                SutSupervisorStrategyGetterConstructorCount++;
                ConstructedSutSupervisorStrategyGetter = @this;
            };

            ShimUnitTestFramework <DummyActor1> .ConstructorISutCreatorITellChildWaiterIChildWaiterIDependencyResolverAdderITestProbeDependencyResolverAdderITestProbeCreatorIResolvedTestProbeStoreITestProbeActorCreatorITestProbeHandlersMapperISutSupervisorStrategyGetterImmutableDictionaryOfValueTupleOfTy =
                (@this, sutCreator, tellChildWaiter, childWaiter, dependencyResolverAdder, testProbeDependencyResolverAdder, testProbeCreator, resolvedTestProbeStore, testProbeActorCreator, testProbeHandlersMapper, sutSupervisorStrategyGetter, handlers, testKit, props, numberOfChildren) =>
            {
                UnitTestFrameworkConstructorCount++;
                ConstructedUnitTestFramework                   = @this;
                SutCreatorPassedIntoShim                       = sutCreator;
                TellChildWaiterPassedIntoShim                  = tellChildWaiter;
                ChildWaiterPassedIntoShim                      = childWaiter;
                DependencyResolverAdderPassedIntoShim          = dependencyResolverAdder;
                TestProbeDependencyResolverAdderPassedIntoShim = testProbeDependencyResolverAdder;
                TestProbeCreatorPassedIntoShim                 = testProbeCreator;
                ResolvedTestProbeStorePassedIntoShim           = resolvedTestProbeStore;
                TestProbeActorCreatorPassedIntoShim            = testProbeActorCreator;
                TestProbeHandlersMapperPassedIntoShim          = testProbeHandlersMapper;
                SutSupervisorStrategyGetterIntoShim            = sutSupervisorStrategyGetter;
                HandlersPassedIntoShim   = handlers;
                TestKitPassedIntoShim    = testKit;
                PropsPassedIntoShim      = props;
                NumberOfChildrenIntoShim = numberOfChildren;
            };
        }