예제 #1
0
        public void MustHaveHappened(Repeated repeatConstraint)
        {
            Guard.AgainstNull(repeatConstraint, "repeatConstraint");

            this.rule.RepeatConstraint = repeatConstraint;
            this.rule.IsAssertion      = true;
        }
예제 #2
0
        /// <summary>
        /// Creates and initializes a new instance of the Button class.
        /// </summary>
        /// <param name="parent">
        /// The EvasObject to which the new Button will be attached as a child.
        /// </param>
        /// <since_tizen> preview </since_tizen>
        public Button(EvasObject parent) : base(parent)
        {
            _clicked  = new SmartEvent(this, this.RealHandle, "clicked");
            _repeated = new SmartEvent(this, this.RealHandle, "repeated");
            _pressed  = new SmartEvent(this, this.RealHandle, "pressed");
            _released = new SmartEvent(this, this.RealHandle, "unpressed");

            _clicked.On += (sender, e) =>
            {
                Clicked?.Invoke(this, EventArgs.Empty);
            };

            _repeated.On += (sender, e) =>
            {
                Repeated?.Invoke(this, EventArgs.Empty);
            };

            _pressed.On += (sender, e) =>
            {
                Pressed?.Invoke(this, EventArgs.Empty);
            };

            _released.On += (sender, e) =>
            {
                Released?.Invoke(this, EventArgs.Empty);
            };
        }
예제 #3
0
 internal UnorderedCallAssertion(FakeManager fakeManager, ICallMatcher matcher, string callDescription, Repeated repeatConstraint)
 {
     this.fakeManager      = fakeManager;
     this.matcher          = matcher;
     this.callDescription  = callDescription;
     this.repeatConstraint = repeatConstraint;
 }
예제 #4
0
 public AfterMustHaveHappenedConfiguration(FakeManager fakeManager, ICallMatcher matcher, string callDescription, Repeated repeatConstraint)
 {
     this.fakeManager      = fakeManager;
     this.matcher          = matcher;
     this.callDescription  = callDescription;
     this.repeatConstraint = repeatConstraint;
 }
예제 #5
0
 internal UnorderedCallAssertion(FakeManager fakeManager, ICallMatcher matcher, Action <IOutputWriter> callDescriber, Repeated repeatConstraint)
 {
     this.fakeManager      = fakeManager;
     this.matcher          = matcher;
     this.callDescriber    = callDescriber;
     this.repeatConstraint = repeatConstraint;
 }
        public void RabbitMQBinding_NonTransactionalOneWayDelivery()
        {
            IOneWayService channel = _channelFactory.CreateChannel();

            Data data = new Data
            {
                Id   = 1,
                Name = "Rabbit"
            };

            A.CallTo(_errorProcessorFake).DoesNothing();
            A.CallTo(() => _processorFake.Say(A <Data> .Ignored)).Invokes(() => _ev.Set());

            channel.Say(data);

            bool wait = _ev.Wait(TimeSpan.FromSeconds(10));

            Assert.IsTrue(wait, "Service were not being invoked");

            A.CallTo(() => _processorFake.Say(A <Data> ._)).WhenArgumentsMatch(collection =>
            {
                data.ShouldBeEquivalentTo(collection[0]);

                return(true);
            }).MustHaveHappened(Repeated.Like(i => i == 1));
        }
        public void MustHaveHappened(Repeated repeatConstraint)
        {
            Guard.AgainstNull(repeatConstraint, "repeatConstraint");

            this.rule.RepeatConstraint = repeatConstraint;
            this.rule.IsAssertion = true;
        }
예제 #8
0
 internal UnorderedCallAssertion(FakeManager fakeManager, ICallMatcher matcher, string callDescription, Repeated repeatConstraint)
 {
     this.fakeManager = fakeManager;
     this.matcher = matcher;
     this.callDescription = callDescription;
     this.repeatConstraint = repeatConstraint;
 }
예제 #9
0
        public void MustHaveHappened(Repeated repeatConstraint)
        {
            this.fakeObject.RemoveRule(this.RuleBeingBuilt);
            var asserter = this.asserterFactory.Invoke(this.Calls.Cast <IFakeObjectCall>());

            asserter.AssertWasCalled(this.Matcher.Matches, this.RuleBeingBuilt.ToString(), repeatConstraint.Matches, repeatConstraint.ToString());
        }
예제 #10
0
        public IAfterMustHaveHappenedConfiguration MustHaveHappened(Repeated repeatConstraint)
        {
            Guard.AgainstNull(repeatConstraint, "repeatConstraint");

            this.rule.RepeatConstraint = repeatConstraint;
            this.rule.IsAssertion      = true;
            return(new AfterMustHaveHappenedRecordedCallConfiguration(this.rule));
        }
예제 #11
0
        public UnorderedCallAssertion MustHaveHappened(Repeated repeatConstraint)
        {
            Guard.AgainstNull(repeatConstraint, nameof(repeatConstraint));

            var asserter = this.asserterFactory.Invoke(this.Calls);

            asserter.AssertWasCalled(this.Matcher.Matches, this.RuleBeingBuilt.WriteDescriptionOfValidCall, repeatConstraint);

            return(new UnorderedCallAssertion(this.manager, this.Matcher, this.RuleBeingBuilt.WriteDescriptionOfValidCall, repeatConstraint));
        }
예제 #12
0
        public bool Never_should_return_instance_that_matches_one_or_above(int expectedRepeat, int repeat)
        {
            // Arrange
            var times = Repeated.Times(expectedRepeat);

            // Act

            // Assert
            return(times.Matches(repeat));
        }
예제 #13
0
        public void Like_should_return_instance_that_has_correct_description()
        {
            // Arrange
            Expression <Func <int, bool> > repeatPredicate = repeat => repeat == 1;

            // Act
            var happened = Repeated.Like(repeatPredicate);

            // Assert
            happened.ToString().Should().Be("the number of times specified by the predicate 'repeat => (repeat == 1)'");
        }
예제 #14
0
        public void MustHaveHappened(Repeated repeatConstraint)
        {
            this.manager.RemoveRule(this.RuleBeingBuilt);
            var asserter = this.asserterFactory.Invoke(this.Calls.Cast <IFakeObjectCall>());

            var description = new StringBuilderOutputWriter();

            this.RuleBeingBuilt.WriteDescriptionOfValidCall(description);

            asserter.AssertWasCalled(this.Matcher.Matches, description.Builder.ToString(), repeatConstraint.Matches, repeatConstraint.ToString());
        }
예제 #15
0
        public void Like_should_return_instance_that_delegates_to_expression(int expected, int actual, bool expectedResult)
        {
            // Arrange
            Expression <Func <int, bool> > repeatPredicate = repeat => repeat == expected;

            // Act
            var happened = Repeated.Like(repeatPredicate);

            // Assert
            happened.Matches(actual).Should().Be(expectedResult);
        }
예제 #16
0
        public bool Like_should_return_instance_that_delegates_to_expression(int expected, int actual)
        {
            // Arrange
            Expression <Func <int, bool> > repeatPredicate = repeat => repeat == expected;

            // Act
            var happened = Repeated.Like(repeatPredicate);

            // Assert
            return(happened.Matches(actual));
        }
예제 #17
0
        public void Assert_happened_times_should_pass_when_call_has_happened_specified_number_of_times()
        {
            // Arrange
            this.foo.Bar();
            this.foo.Bar();
            this.foo.Bar();

            // Act

            // Assert
            A.CallTo(() => foo.Bar()).MustHaveHappened(Repeated.Times(3));
        }
        public void Assert_with_void_call_should_assert_on_assertions_produced_by_factory()
        {
            // Arrange
            A.CallTo(() => this.ruleProducedByFactory.ToString()).Returns("call description");

            // Act
            this.builder.MustHaveHappened(Repeated.Times(99).Exactly);

            // Assert
            var repeatMatcher = A <Func <int, bool> > .That.Matches(x => x.Invoke(99) == true);

            Fake.Assert(this.asserter)
            .WasCalled(x => x.AssertWasCalled(A <Func <IFakeObjectCall, bool> > .Ignored, "call description", repeatMatcher, "exactly #99 times"));
        }
예제 #19
0
        public IAfterMustHaveHappenedConfiguration MustHaveHappened(Repeated repeatConstraint)
        {
            Guard.AgainstNull(repeatConstraint, "repeatConstraint");

            this.manager.RemoveRule(this.RuleBeingBuilt);
            var asserter = this.asserterFactory.Invoke(this.Calls.Cast <IFakeObjectCall>());

            var description = new StringBuilderOutputWriter();

            this.RuleBeingBuilt.WriteDescriptionOfValidCall(description);

            asserter.AssertWasCalled(this.Matcher.Matches, description.Builder.ToString(), repeatConstraint.Matches, repeatConstraint.ToString());

            return(new AfterMustHaveHappenedConfiguration(this.manager, this.Matcher, description.Builder.ToString(), repeatConstraint));
        }
 private static IEnumerable <CallCountAsserter> NonMatchingAssertions()
 {
     return(new[]
     {
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.Exactly.Once), "exactly once but no calls were made"),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.Exactly.Once), "exactly once but found it twice"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.Exactly.Once), "exactly once but found it 3 times"),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.AtLeast.Once), "at least once but no calls were made"),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.NoMoreThan.Once), "no more than once but found it twice"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.NoMoreThan.Once), "no more than once but found it 3 times"),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.Exactly.Twice), "exactly twice but no calls were made"),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.Exactly.Twice), "exactly twice but found it once"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.Exactly.Twice), "exactly twice but found it 3 times"),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.AtLeast.Twice), "at least twice but no calls were made"),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.AtLeast.Twice), "at least twice but found it once"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.NoMoreThan.Twice), "no more than twice but found it 3 times"),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.Exactly.Times(0)), "exactly 0 times but found it once"),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.Exactly.Times(0)), "exactly 0 times but found it twice"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.Exactly.Times(0)), "exactly 0 times but found it 3 times"),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(0)), "no more than 0 times but found it once"),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(0)), "no more than 0 times but found it twice"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(0)), "no more than 0 times but found it 3 times"),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.Exactly.Times(1)), "exactly 1 times but no calls"),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.Exactly.Times(1)), "exactly 1 times but found it twice"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.Exactly.Times(1)), "exactly 1 times but found it 3 times"),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.AtLeast.Times(1)), "at least 1 times but no calls were made"),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(1)), "no more than 1 times but found it twice"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(1)), "no more than 1 times but found it 3 times"),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.Exactly.Times(2)), "exactly 2 times but no calls"),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.Exactly.Times(2)), "exactly 2 times but found it once"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.Exactly.Times(2)), "exactly 2 times but found it 3 times"),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.AtLeast.Times(2)), "at least 2 times but no calls were made"),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.AtLeast.Times(2)), "at least 2 times but found it once"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(2)), "no more than 2 times but found it 3 times"),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.Exactly.Times(3)), "exactly 3 times but no calls were made"),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.Exactly.Times(3)), "exactly 3 times but found it once"),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.Exactly.Times(3)), "exactly 3 times but found it twice"),
         new CallCountAsserter(4, call => call.MustHaveHappened(Repeated.Exactly.Times(3)), "exactly 3 times but found it 4 times"),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.AtLeast.Times(3)), "at least 3 times but no calls were made"),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.AtLeast.Times(3)), "at least 3 times but found it once"),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.AtLeast.Times(3)), "at least 3 times but found it twice"),
         new CallCountAsserter(4, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(3)), "no more than 3 times but found it 4 times"),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.Like(n => n % 2 == 1)), "the number of times specified by the predicate 'n => ((n % 2) == 1)' but no calls were made"),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.Like(n => n % 2 == 0)), "the number of times specified by the predicate 'n => ((n % 2) == 0)' but found it once"),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.Like(n => n % 2 == 1)), "the number of times specified by the predicate 'n => ((n % 2) == 1)' but found it twice"),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.Like(n => n % 2 == 0)), "the number of times specified by the predicate 'n => ((n % 2) == 0)' but found it 3 times")
     });
 }
예제 #21
0
        public void ShouldChangeToPreviousPageWhen_P_IsPressed()
        {
            var output = A.Fake <IConsole>();

            A
            .CallTo(() => output.Read())
            .ReturnsNextFromSequence('p', 'x');

            var coordinator = new DisplayCoordinator(A.Fake <IFileReader>(), A.Fake <IFormatter>(), output);

            coordinator.Display("file.csv", 42);

            A
            .CallTo(() => output.Read())
            .MustHaveHappened(Repeated.Like(i => i == 2));
        }
예제 #22
0
        public void ShouldExitWhen_X_IsPressed()
        {
            var output = A.Fake <IConsole>();

            A
            .CallTo(() => output.Read())
            .Returns('x');

            var coordinator = new DisplayCoordinator(A.Fake <IFileReader>(), A.Fake <IFormatter>(), output);

            coordinator.Display("file.csv", 42);

            A
            .CallTo(() => output.Read())
            .MustHaveHappened(Repeated.Like(i => i == 1));
        }
예제 #23
0
        public void ShouldGenerateImplementationWithSignature()
        {
            const string stepText    = "Do nothing";
            var          stepLiteral = $"\"{stepText}\"";

            Setup(stepText, "DoNothing", false);
            CodeClass    targetClass;
            CodeFunction impl;

            _stepImplementationGenerator.TryGenerateMethodStub(SelectedClass, _textSnapshotLine, out targetClass,
                                                               out impl);

            _functionCall.MustHaveHappened();
            A.CallTo(() => impl.AddParameter(A <string> ._, A <object> ._, A <object> ._))
            .MustHaveHappened(Repeated.Like(i => i == 0));
            A.CallTo(() => impl.AddAttribute("Step", stepLiteral, A <object> ._)).MustHaveHappened();
        }
예제 #24
0
        public void ShouldGenerateImplementationWithFileParameter()
        {
            const string stepText    = "Do something with <file:foo.txt>";
            var          stepLiteral = $"\"{stepText}\"";

            Setup(stepText, "DoSomethingWithFilefootxt", false, "file:foo.txt");
            CodeClass    targetClass;
            CodeFunction impl;

            _stepImplementationGenerator.TryGenerateMethodStub(SelectedClass, _textSnapshotLine, out targetClass,
                                                               out impl);

            _functionCall.MustHaveHappened();
            A.CallTo(() => impl.AddParameter("foo", vsCMTypeRef.vsCMTypeRefString, A <object> ._))
            .MustHaveHappened(Repeated.Like(i => i == 1));
            A.CallTo(() => impl.AddAttribute("Step", stepLiteral, A <object> ._)).MustHaveHappened();
        }
예제 #25
0
        /// <summary>
        /// Creates and initializes a new instance of the AnimationView class.
        /// </summary>
        /// <param name="parent">The parent is a given container, which will be attached by AnimationView as a child. It's <see cref="EvasObject"/> type.</param>
        /// <since_tizen> preview </since_tizen>
        public AnimationView(EvasObject parent) : base(parent)
        {
            _started  = new SmartEvent(this, this.Handle, "play,start");
            _repeated = new SmartEvent(this, this.Handle, "play,repeat");
            _finished = new SmartEvent(this, this.Handle, "play,done");
            _paused   = new SmartEvent(this, this.Handle, "play,pause");
            _resumed  = new SmartEvent(this, this.Handle, "play,resume");
            _stopped  = new SmartEvent(this, this.Handle, "play,stop");
            _updated  = new SmartEvent(this, this.Handle, "play,update");

            _started.On += (sender, e) =>
            {
                Started?.Invoke(this, EventArgs.Empty);
            };

            _repeated.On += (sender, e) =>
            {
                Repeated?.Invoke(this, EventArgs.Empty);
            };

            _finished.On += (sender, e) =>
            {
                Finished?.Invoke(this, EventArgs.Empty);
            };

            _paused.On += (sender, e) =>
            {
                Paused?.Invoke(this, EventArgs.Empty);
            };

            _resumed.On += (sender, e) =>
            {
                Resumed?.Invoke(this, EventArgs.Empty);
            };

            _stopped.On += (sender, e) =>
            {
                Stopped?.Invoke(this, EventArgs.Empty);
            };

            _updated.On += (sender, e) =>
            {
                Updated?.Invoke(this, EventArgs.Empty);
            };
        }
        public void Assert_with_function_call_should_assert_on_assertions_produced_by_factory()
        {
            // Arrange
            A.CallTo(() => this.ruleProducedByFactory.ToString()).Returns("call description");

            // Act
            var returnConfig = new RuleBuilder.ReturnValueConfiguration <int>()
            {
                ParentConfiguration = this.builder
            };

            returnConfig.MustHaveHappened(Repeated.Times(99).Exactly);

            // Assert
            var repeatMatcher = A <Func <int, bool> > .That.Matches(x => x.Invoke(99) == true);

            A.CallTo(() => this.asserter.AssertWasCalled(A <Func <IFakeObjectCall, bool> > .Ignored, "call description", repeatMatcher, "exactly #99 times")).MustHaveHappened(Repeated.Once);
        }
        public async void IServiceCollectionExtensions_Register_RegisterJob()
        {
            // Зарегистрированные джобы
            var scheduleJobc = new List <IScheduleJob>();
            var jobDetail1   = A.Fake <IJobDetail>();
            var jobDetail2   = A.Fake <IJobDetail>();
            var jobDetail3   = A.Fake <IJobDetail>();

            scheduleJobc.Add(new ScheduleJob(jobDetail1, new List <ITrigger>()
            {
                A.Fake <ITrigger>()
            }));
            scheduleJobc.Add(new ScheduleJob(jobDetail2, new List <ITrigger>()
            {
                A.Fake <ITrigger>()
            }));
            scheduleJobc.Add(new ScheduleJob(jobDetail3, new List <ITrigger>()
            {
                A.Fake <ITrigger>()
            }));

            IServiceProvider serviceProvider = A.Fake <IServiceProvider>();

            A.CallTo(() => serviceProvider.GetService(typeof(IEnumerable <IScheduleJob>))).Returns(scheduleJobc);


            ISchedulerFactory schedulerFactory = A.Fake <ISchedulerFactory>();
            IScheduler        scheduler        = A.Fake <IScheduler>();

            A.CallTo(() => schedulerFactory.GetScheduler(A <CancellationToken> .Ignored))
            .Returns(Task.FromResult(scheduler));

            IJobFactory jobFactory = A.Fake <IJobFactory>();

            var testClass = new QuartzHostedService(serviceProvider, schedulerFactory, jobFactory);
            await testClass.StartAsync(CancellationToken.None);

            A.CallTo(
                () => scheduler.ScheduleJob(
                    A <IJobDetail> .That.Matches(jd => jd == jobDetail1 || jd == jobDetail2 || jd == jobDetail3),
                    A <ITrigger> .Ignored,
                    A <CancellationToken> .Ignored))
            .MustHaveHappened(Repeated.Like(count => count == 3));
        }
예제 #28
0
        public void When_CallingApplyAndItemIsUncofigured_Should_CallTestAgainIfWasSuccesful()
        {
            //Arrange
            var fixture   = Test.Fixture;
            var runList   = fixture.CreateMany <ConfigItem>().ToArray();
            var drivers   = new[] { A.Fake <IResourceDriver>(), A.Fake <IResourceDriver>(), A.Fake <IResourceDriver>() };
            var pluginMan = fixture.Freeze <IPluginManager>();
            var sut       = fixture.Create <ConfigManager>();

            A.CallTo(() => pluginMan.GetResource(runList[0].Resource)).Returns(drivers[0]);
            A.CallTo(() => drivers[0].Test()).Returns(ResourceState.NotConfigured).Once()
            .Then.Returns(ResourceState.Configured).Once();

            //Act
            var result = sut.ApplyRunList(runList);

            //Assert
            A.CallTo(() => drivers[0].Test()).MustHaveHappened(Repeated.Like(r => r == 2));
        }
 private static IEnumerable <CallCountAsserter> MatchingAssertions()
 {
     return(new[]
     {
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.Exactly.Once)),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.AtLeast.Once)),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.AtLeast.Once)),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.NoMoreThan.Once)),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.NoMoreThan.Once)),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.Exactly.Twice)),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.AtLeast.Twice)),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.AtLeast.Twice)),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.NoMoreThan.Twice)),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.NoMoreThan.Twice)),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.NoMoreThan.Twice)),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.Exactly.Times(0))),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.AtLeast.Times(0))),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.AtLeast.Times(0))),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(0))),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.Exactly.Times(1))),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.AtLeast.Times(1))),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.AtLeast.Times(1))),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(1))),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(1))),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.Exactly.Times(2))),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.AtLeast.Times(2))),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.AtLeast.Times(2))),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(2))),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(2))),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(2))),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.Exactly.Times(3))),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.AtLeast.Times(3))),
         new CallCountAsserter(4, call => call.MustHaveHappened(Repeated.AtLeast.Times(3))),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(3))),
         new CallCountAsserter(1, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(3))),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(3))),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.NoMoreThan.Times(3))),
         new CallCountAsserter(0, call => call.MustHaveHappened(Repeated.Like(n => n % 2 == 0))),
         new CallCountAsserter(2, call => call.MustHaveHappened(Repeated.Like(n => n % 2 == 0))),
         new CallCountAsserter(3, call => call.MustHaveHappened(Repeated.Like(n => n % 3 == 0)))
     });
 }
예제 #30
0
        private object[] ParseWithRepeats(string source, ParsingContext ctx)
        {
            var result = new List <object>();

            int    activeIndex   = ctx.Index;
            object failureResult = null;

            while (result.Count < Max && ctx.Success)
            {
                var itemResult = Repeated.Parse(source, ctx);
                if (ctx.Success)
                {
                    result.Add(itemResult);
                    activeIndex = ctx.Index;
                    if (Separator != null)
                    {
                        Separator.Parse(source, ctx);
                        if (ctx.Success)
                        {
                            activeIndex = ctx.Index;
                        }
                    }
                }
                else
                {
                    failureResult = itemResult;
                }
            }

            ctx.Success = result.Count >= Min;
            if (ctx.Success)
            {
                ctx.Index = activeIndex;
            }
            else if (failureResult != null)
            {
                result.Add(failureResult);
            }

            return(result.ToArray());
        }
예제 #31
0
        public void RabbitMQBinding_TransferLargeBinary_TextBaseSerialization()
        {
            IOneWayService channel = _channelFactory.CreateChannel();

            Blob data = new Blob
            {
                Id   = 1,
                Data = new byte[8 * 1024 * 1024] // 8MB
            };

            A.CallTo(_errorProcessorFake).DoesNothing();
            A.CallTo(() => _processorFake.LargeData(A <Blob> .Ignored)).Invokes(() => _ev.Set());

            channel.LargeData(data);

            bool wait = _ev.Wait(TimeSpan.FromSeconds(10));

            wait.Should().BeTrue();

            A.CallTo(() => _processorFake.LargeData(A <Blob> ._)).MustHaveHappened(Repeated.Like(i => i == 1));
        }
예제 #32
0
        public void ShouldReadModelAndFormatTableAndAskForAction()
        {
            var fileReader = A.Fake <IFileReader>();
            var formatter  = A.Fake <IFormatter>();

            A
            .CallTo(() => formatter.Format(null))
            .WithAnyArguments()
            .Returns("Die Tabelle");

            var output = A.Fake <IConsole>();

            A
            .CallTo(() => output.Read())
            .Returns('x');
            var coordinator = new DisplayCoordinator(fileReader, formatter, output);

            coordinator.Display("file.csv", 42);

            A
            .CallTo(() => fileReader.Read("file.csv"))
            .MustHaveHappened();

            A
            .CallTo(() => formatter.Format(null))
            .WithAnyArguments()
            .MustHaveHappened();

            A
            .CallTo(() => output.Write("Die Tabelle", A <object[]> .Ignored))
            .MustHaveHappened(Repeated.Like(i => i == 1));

            A
            .CallTo(() => output.Write(A <string> .That.Contains("N(ext"), A <object[]> .Ignored))
            .MustHaveHappened(Repeated.Like(i => i == 1));

            A
            .CallTo(() => output.Read())
            .MustHaveHappened();
        }
예제 #33
0
        public void CheckNextCall(
            FakeManager fakeManager,
            Func<IFakeObjectCall, bool> callPredicate,
            string callDescription,
            Repeated repeatConstraint)
        {
            Guard.AgainstNull(fakeManager, nameof(fakeManager));
            Guard.AgainstNull(callPredicate, nameof(callPredicate));
            Guard.AgainstNull(callDescription, nameof(callDescription));
            Guard.AgainstNull(repeatConstraint, nameof(repeatConstraint));
            this.fakeManagers.Add(fakeManager);
            this.assertedCalls.Add(
                new AssertedCall { CallDescription = callDescription, RepeatDescription = repeatConstraint.ToString() });

            var allCalls = this.fakeManagers.SelectMany(f => f.GetRecordedCalls()).OrderBy(SequenceNumberManager.GetSequenceNumber).ToList();

            int matchedCallCount = 0;
            foreach (var currentCall in allCalls.SkipWhile(c => SequenceNumberManager.GetSequenceNumber(c) <= this.currentSequenceNumber))
            {
                if (repeatConstraint.Matches(matchedCallCount))
                {
                    return;
                }

                if (callPredicate(currentCall))
                {
                    matchedCallCount++;
                    this.currentSequenceNumber = SequenceNumberManager.GetSequenceNumber(currentCall);
                }
            }

            if (!repeatConstraint.Matches(matchedCallCount))
            {
                ThrowExceptionWhenAssertionFailed(this.assertedCalls, this.callWriter, allCalls);
            }
        }