コード例 #1
0
        public async Task ExecuteDeferredEvents_WhenCalled_ShouldCallAllEventHandlers()
        {
            // Arrange
            var @event = new FakeEvent {
                Id = 1
            };
            var handlerFactory = new MessageHandlerRegistry();
            var mediator       = new Mediator(handlerFactory.MultiInstanceFactory, handlerFactory.SingleInstanceFactory);

            handlerFactory.AddHandlersForEvent(new List <IEventHandler <FakeEvent> >
            {
                _autoSubstitute.SubstituteFor <HandlerDeferringMultipleEvents>(mediator),
                _autoSubstitute.SubstituteFor <HandlerDeferringSingleEvent>(mediator),
                _autoSubstitute.SubstituteFor <HandlerWithoutAdditionalEvents>()
            });

            mediator.DeferEvent(@event);

            // Act
            await mediator.ExecuteDeferredEvents();

            // Assert
            foreach (var handler in handlerFactory.GetHandlersFor <FakeEvent>())
            {
                handler.Received().Handle(Arg.Any <FakeEvent>()).FireAndForget();
            }
        }
コード例 #2
0
ファイル: ExampleFixture.cs プロジェクト: felix-v-net/Unitest
        public void Example_test_with_substitute_for_concrete()
        {
            const int val1           = 3;
            const int val2           = 2;
            const int val3           = 10;
            var       AutoSubstitute = new AutoSubstitute();

            AutoSubstitute.Resolve <IDependency2>().SomeOtherMethod().Returns(val1);
            AutoSubstitute.SubstituteFor <ConcreteClass>(val2).Add(Arg.Any <int>()).Returns(val3);

            var result = AutoSubstitute.Resolve <MyClassWithConcreteDependency>().AMethod();

            Assert.That(result, Is.EqualTo(val3));
        }
コード例 #3
0
        public virtual void before_each()
        {
            autoSubstitute = new AutoSubstitute();

            proxyableExecutor = Substitute.For <IProxyableTestExecutor>();

            remoteRunner = autoSubstitute.SubstituteFor <ICrossDomainRunner <IProxyableTestExecutor, int> >();

            progressRecorder = autoSubstitute.Resolve <IProgressRecorder>();

            logger            = autoSubstitute.Resolve <IOutputLogger>();
            crossDomainLogger = autoSubstitute.Resolve <ICrossDomainLogger>();

            executor = autoSubstitute.Resolve <BinaryTestExecutor>();
        }
コード例 #4
0
        public virtual void before_each()
        {
            autoSubstitute = new AutoSubstitute();

            proxyableDiscoverer = Substitute.For <IProxyableTestDiscoverer>();

            remoteRunner = autoSubstitute.SubstituteFor <
                ICrossDomainRunner <IProxyableTestDiscoverer, DiscoveredExample[]> >();

            fileService = autoSubstitute.Resolve <IFileService>();

            logger            = autoSubstitute.Resolve <IOutputLogger>();
            crossDomainLogger = autoSubstitute.Resolve <ICrossDomainLogger>();

            discoverer = autoSubstitute.Resolve <BinaryTestDiscoverer>();
        }
コード例 #5
0
 public RegisterTest()
 {
     _Mapper = AutoSubstitute.SubstituteFor <IMapper>();
 }
コード例 #6
0
        public void Example_test_with_substitute_for_concrete()
        {
            const int val1 = 3;
            const int val2 = 2;
            const int val3 = 10;
            var AutoSubstitute = new AutoSubstitute();
            AutoSubstitute.Resolve<IDependency2>().SomeOtherMethod().Returns(val1);
            AutoSubstitute.SubstituteFor<ConcreteClass>(val2).Add(Arg.Any<int>()).Returns(val3);

            var result = AutoSubstitute.Resolve<MyClassWithConcreteDependency>().AMethod();

            Assert.That(result, Is.EqualTo(val3));
        }