コード例 #1
0
 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,
コード例 #2
0
 internal UnitTestFramework(
     ISutCreator sutCreator,
     ITellWaiter tellWaiter,
     IWaiter childWaiter,
     IWaiter exceptionWaiter,
     IDependencyResolverAdder resolverAdder,
     ITestProbeDependencyResolverAdder testProbeDependencyResolverAdder,
     ITestProbeCreator testProbeCreator,
     IResolvedTestProbeStore resolvedProbeStore,
     ITestProbeChildActorCreator testProbeChildActorCreator,
     ITestProbeChildHandlersMapper testProbeChildHandlersMapper,
     ISutSupervisorStrategyGetter sutSupervisorStrategyGetter,
     ITestProbeParentActorCreator testProbeParentActorCreator,
     IDelayer delayer,
     ImmutableDictionary <Type, Func <object, object> > parentHandlers,
     ImmutableDictionary <(Type, Type), Func <object, object> > childHandlers,
コード例 #3
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);
        }
コード例 #4
0
        public TestBase() : base(AkkaConfig.Config)
        {
            Func <Type> generateType = TestHelper.GetRandomTypeGenerator();

            // Create mocks
            SutCreatorMock                       = new Mock <ISutCreator>();
            TellWaiterMock                       = new Mock <ITellWaiter>();
            ChildWaiterMock                      = new Mock <IWaiter>();
            ExceptionWaiterMock                  = new Mock <IWaiter>();
            DependencyResolverAdderMock          = new Mock <IDependencyResolverAdder>();
            TestProbeDependencyResolverAdderMock = new Mock <ITestProbeDependencyResolverAdder>();
            ResolvedTestProbeStoreMock           = new Mock <IResolvedTestProbeStore>();
            TestProbeChildActorCreatorMock       = new Mock <ITestProbeChildActorCreator>();
            TestProbeCreatorMock                 = new Mock <ITestProbeCreator>();
            TestProbeHandlersMapperMock          = new Mock <ITestProbeChildHandlersMapper>();
            TestProbeChildActorMock              = new Mock <ITestProbeChildActor>();
            SutSupervisorStrategyGetterMock      = new Mock <ISutSupervisorStrategyGetter>();
            TestProbeParentActorCreatorMock      = new Mock <ITestProbeParentActorCreator>();
            TestProbeParentActorMock             = new Mock <ITestProbeParentActor>();
            DelayerMock = new Mock <IDelayer>();

            // Create objects passed into sut constructor
            SutCreator                       = SutCreatorMock.Object;
            TellWaiter                       = TellWaiterMock.Object;
            ChildWaiter                      = ChildWaiterMock.Object;
            ExceptionWaiter                  = ChildWaiterMock.Object;
            DependencyResolverAdder          = DependencyResolverAdderMock.Object;
            TestProbeDependencyResolverAdder = TestProbeDependencyResolverAdderMock.Object;
            TestProbeCreator                 = TestProbeCreatorMock.Object;
            ResolvedTestProbeStore           = ResolvedTestProbeStoreMock.Object;
            TestProbeChildActorCreator       = TestProbeChildActorCreatorMock.Object;
            TestProbeHandlersMapper          = TestProbeHandlersMapperMock.Object;
            SutSupervisorStrategyGetter      = SutSupervisorStrategyGetterMock.Object;
            TestProbeParentActorCreator      = TestProbeParentActorCreatorMock.Object;
            Delayer        = DelayerMock.Object;
            ParentHandlers = ImmutableDictionary <Type, Func <object, object> >
                             .Empty
                             .Add((generateType()), message => TestHelper.Generate <object>());

            ChildHandlers = ImmutableDictionary <(Type, Type), Func <object, object> >
                            .Empty
                            .Add((generateType(), generateType()), message => TestHelper.Generate <object>());

            Decider = exception => TestHelper.GenerateEnum <Directive>();
            Props   = Props.Create <DummyActor>();
            PropsWithSupervisorStrategy = Props
                                          .Create <DummyActor>()
                                          .WithSupervisorStrategy(new AllForOneStrategy(
                                                                      TestHelper.GenerateNumber(),
                                                                      TestHelper.GenerateNumber(),
                                                                      exception => TestHelper.Generate <Directive>()));
            ExpectedChildCount     = TestHelper.GenerateNumber();
            ExpectedExceptionCount = TestHelper.GenerateNumber();

            // Create objects passed into sut methods
            Message   = TestHelper.Generate <object>();
            ChildName = TestHelper.GenerateString();
            ChildNameWithoutSupervisor = TestHelper.GenerateString();
            Sender        = new Mock <IActorRef>().Object;
            DelayDuration = TestHelper.Generate <TimeSpan>();

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

            SutActor                   = ActorOfAsTestActorRef <DummyActor>();
            ResolvedType               = generateType();
            ResolvedTestProbe          = CreateTestProbe();
            ResolvedSupervisorStrategy = new AllForOneStrategy(
                TestHelper.GenerateNumber(),
                TestHelper.GenerateNumber(),
                exception => TestHelper.Generate <Directive>());
            SutSupervisorStrategy = new OneForOneStrategy(
                TestHelper.GenerateNumber(),
                TestHelper.GenerateNumber(),
                exception => TestHelper.Generate <Directive>());
            TestProbeParentActor                    = TestProbeParentActorMock.Object;
            TestProbeParentActorTestProbe           = CreateTestProbe();
            TestProbeParentActorRef                 = TestProbeParentActorTestProbe.Ref;
            TestProbeParentActorUnhandledExceptions = TestHelper.GenerateMany <Exception>(() => TestHelper.GenerateException());

            // Set up mocks
            TestProbeParentActorMock
            .SetupGet(actor => actor.Ref)
            .Returns(TestProbeParentActorRef);
            TestProbeParentActorMock
            .SetupGet(actor => actor.TestProbe)
            .Returns(TestProbeParentActorTestProbe);
            TestProbeParentActorMock
            .SetupGet(actor => actor.UnhandledExceptions)
            .Returns(TestProbeParentActorUnhandledExceptions);

            TestProbeParentActorCreatorMock
            .SetupSequence(creator => creator.Create(TestProbeCreator, ExceptionWaiter, this, Decider, ParentHandlers))
            .Returns(TestProbeParentActor)
            .Returns(Mock.Of <ITestProbeParentActor>());

            SutCreatorMock
            .Setup(creator => creator.Create <DummyActor>(
                       ChildWaiterMock.Object,
                       this,
                       Props,
                       ExpectedChildCount,
                       TestProbeParentActorRef))
            .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(ChildHandlers))
            .Returns(() => MappedChildHandlers);

            SutSupervisorStrategyGetterMock
            .Setup(getter => getter.Get(SutActor.UnderlyingActor))
            .Returns(() => SutSupervisorStrategy);
        }
コード例 #5
0
        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;
            };
        }