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));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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)'");
        }
Ejemplo n.º 4
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));
        }
 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")
     });
 }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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();
        }
        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));
        }
Ejemplo n.º 11
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)))
     });
 }
Ejemplo n.º 13
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));
        }
Ejemplo n.º 14
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();
        }