public override void Context()
 {
     base.Context();
     _quantity = Quantity.AtLeastOne();
     _receivedCalls.stub(x => x.AllCalls()).Return(new[] { _call });
     _callSpecificationFactory.stub(x => x.CreateFrom(_call, MatchArgs.Any)).Return(_callSpecFromMethodSpec);
 }
        /// <summary>
        /// Checks this substitute has received the following call with any arguments.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="substitute"></param>
        /// <returns></returns>
        public static T ReceivedWithAnyArgs <T>(this T substitute) where T : class
        {
            var router = GetRouterForSubstitute(substitute);

            router.SetRoute(x => RouteFactory().CheckReceivedCalls(x, MatchArgs.Any, Quantity.AtLeastOne()));
            return(substitute);
        }
示例#3
0
        public static T Received <T>(this T substitute) where T : class
        {
            var router = GetRouterForSubstitute(substitute);

            router.SetRoute <CheckReceivedCallsRoute>(MatchArgs.AsSpecifiedInCall, Quantity.AtLeastOne());
            return(substitute);
        }
示例#4
0
        public void Should_set_route_to_check_the_next_call_has_been_received_with_any_arguments()
        {
            var state = mock <ISubstituteState>();

            _routerForSubstitute.FactoryMethodUsedToSetRoute(state);
            _routeFactory.received(x => x.CheckReceivedCalls(state, MatchArgs.Any, Quantity.AtLeastOne()));
        }
示例#5
0
        public async Task Can_produce_first_block_when_private_chains_allowed()
        {
            var context = new Context();

            context.InitProducer(new AuRaConfig {
                AllowAuRaPrivateChains = true, ForceSealing = true
            });
            (await StartStop(context, false)).ShouldProduceBlocks(Quantity.AtLeastOne());
        }
示例#6
0
        public static T ReceivedWithAnyArgs <T>(this T substitute) where T : class
        {
            if (substitute == null)
            {
                throw new NullSubstituteReferenceException();
            }

            return(substitute.ReceivedWithAnyArgs(Quantity.AtLeastOne()));
        }
示例#7
0
        public async Task Produces_block_when_ForceSealing_is_false_and_there_are_transactions()
        {
            var        context    = new Context();
            AuRaConfig auRaConfig = new AuRaConfig {
                ForceSealing = false
            };

            context.InitProducer(auRaConfig);
            context.TransactionSource.GetTransactions(Arg.Any <BlockHeader>(), Arg.Any <long>()).Returns(new[] { Build.A.Transaction.TestObject });
            (await StartStop(context)).ShouldProduceBlocks(Quantity.AtLeastOne());
        }
        public async Task GetMessages_WhenCalled_FilterOutInvalidItems()
        {
            // Arrange
            var airTableService     = Substitute.For <IAirTableService>();
            var mapperConfiguration = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <MessageMapper>();
            });

            IMapper mapper = mapperConfiguration.CreateMapper();

            var command = new GetMessagesQuery();
            var handler = new GetMessagesQuery.GetMessagesQueryHandler(airTableService, mapper);

            var response = new AirTableGetResponseDTO()
            {
                records = new List <RecordsDTO>()
                {
                    new RecordsDTO()
                    {
                        id = "recCR2LP7wZVioc5H", fields = new FieldsDTO()
                        {
                            id = null, Message = "Message", receivedAt = DateTime.Now.ToString()
                        }
                    },
                    new RecordsDTO()
                    {
                        id = "recCR2LP7wZVioc5H", fields = new FieldsDTO()
                        {
                            id = "2", Message = "Message", receivedAt = DateTime.Now.ToString()
                        }
                    },
                    new RecordsDTO()
                    {
                        id = "recCR2LP7wZVioc5H", fields = new FieldsDTO()
                        {
                            id = "3", Message = "Message", receivedAt = DateTime.Now.ToString()
                        }
                    }
                }
            };

            airTableService.GetMessagesAsync().Returns(response);

            // Act
            var result = handler.Handle(command, new System.Threading.CancellationToken());

            // Assert
            await airTableService.Received(Quantity.AtLeastOne()).GetMessagesAsync();

            result.Should().NotBeNull();
            result.Result.Should().HaveCount(2);
        }
示例#9
0
 public override void Because()
 {
     try
     {
         _requiredQuantity = Quantity.AtLeastOne();
         sut.Throw(_callSpecification, _actualCalls, _relatedCalls, _requiredQuantity);
     }
     catch (ReceivedCallsException ex)
     {
         _exception = ex;
         return;
     }
     throw new AssertionException("Expected a matching exception to be thrown.");
 }
示例#10
0
    private static void ValidateCallReceived <T>(
        this T substitute,
        Action <T> substituteCall,
        MatchArgs?matchArgs)
        where T : class
    {
        var context    = SubstitutionContext.Current;
        var callRouter = context.GetCallRouterFor(substitute);

        context.ThreadContext
        .SetNextRoute(
            callRouter,
            x => context.RouteFactory.CheckReceivedCalls(
                x,
                matchArgs ?? MatchArgs.AsSpecifiedInCall,
                Quantity.AtLeastOne()));
        substituteCall(substitute);
    }
示例#11
0
        public async Task SaveMessage_WhenCalled_ReturnsMessage()
        {
            //Arrange
            var airTableService     = Substitute.For <IAirTableService>();
            var mapperConfiguration = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <MessageMapper>();
            });

            IMapper mapper  = mapperConfiguration.CreateMapper();
            var     command = new SaveMessageCommand("text", "title");
            var     handler = new SaveMessageCommand.SaveMessageCommandHandler(airTableService, mapper);

            var records = new RecordsDTO()
            {
                id = "recCR2LP7wZVioc5H", fields = new FieldsDTO()
                {
                    id = "1", Message = "Message", receivedAt = DateTime.Now.ToString()
                }
            };

            airTableService.SaveMessageAsync(Arg.Any <AirTableSaveRequestDTO>()).Returns(new AirTableSaveResponseDTO()
            {
                records = new List <RecordsDTO>()
                {
                    records
                }
            });

            // Act
            var result = await handler.Handle(command, new System.Threading.CancellationToken());

            // Assert
            await airTableService.Received(Quantity.AtLeastOne()).SaveMessageAsync(Arg.Any <AirTableSaveRequestDTO>());

            result.Should().NotBeNull();
            result.records.Should().HaveCount(1);
            result.records.Should().Equals(records);
            result.records[0].fields.Message.Should().Equals("text");
            result.records[0].fields.Summary.Should().Equals("title");
        }
示例#12
0
        public async Task Should_Support_Options_Monitor()
        {
            var(_, server, configuration) = await InitializeWithConfiguration(
                ConfigureClient, options =>
            {
                ConfigureServer(options);
                options.Services.Configure <BinderSourceUrl>("mysection");
            }
                );

            var options = server.GetService <IOptionsMonitor <BinderSourceUrl> >();
            var sub     = Substitute.For <Action <BinderSourceUrl> >();

            options.OnChange(sub);

            configuration.Update("mysection", new Dictionary <string, string> {
                ["host"] = "localhost", ["port"] = "443"
            });
            configuration.Update("notmysection", new Dictionary <string, string> {
                ["host"] = "127.0.0.1", ["port"] = "123"
            });
            await options.WaitForChange(CancellationToken);

            await SettleNext();

            // IOptionsMonitor<> is registered as a singleton, so this will update
            options.CurrentValue.Host.Should().Be("localhost");
            options.CurrentValue.Port.Should().Be(443);
            sub.Received(Quantity.AtLeastOne()).Invoke(Arg.Any <BinderSourceUrl>());

            configuration.Update("mysection", new Dictionary <string, string> {
                ["host"] = "127.0.0.1", ["port"] = "80"
            });
            await options.WaitForChange(CancellationToken);

            await SettleNext();

            options.CurrentValue.Host.Should().Be("127.0.0.1");
            options.CurrentValue.Port.Should().Be(80);
            sub.Received(Quantity.Within(2, int.MaxValue)).Invoke(Arg.Any <BinderSourceUrl>());
        }
 public static T ReceivedOnly <T>(this T substitute) where T : class
 {
     return(substitute.ReceivedOnly(Quantity.AtLeastOne()));
 }
示例#14
0
 public async Task Produces_block()
 {
     (await StartStop(new Context())).ShouldProduceBlocks(Quantity.AtLeastOne());
 }
 public override void Context()
 {
     base.Context();
     _quantity = Quantity.AtLeastOne();
     _receivedCalls.stub(x => x.AllCalls()).Return(new[] { _call });
 }
 public void Should_set_tell_the_substitute_to_assert_that_the_next_call_has_been_received_with_any_arguments()
 {
     _routerForSubstitute.received(x => x.SetRoute <CheckReceivedCallsRoute>(MatchArgs.Any, Quantity.AtLeastOne()));
 }
示例#17
0
 /// <summary>
 /// Checks this substitute has received the following call with any arguments.
 /// </summary>
 public static T ReceivedWithAnyArgs <T>(this T substitute) where T : class
 {
     return(substitute.ReceivedWithAnyArgs(Quantity.AtLeastOne()));
 }
示例#18
0
 [Test, Retry(10)] // TODO: fix the need for retry
 public async Task Produces_block_when_ForceSealing_is_false_and_there_are_transactions()
 {
     _auraConfig.ForceSealing.Returns(false);
     _pendingTxSelector.SelectTransactions(Arg.Any <long>()).Returns(new[] { Build.A.Transaction.TestObject });
     (await StartStop()).ShouldProduceBlocks(Quantity.AtLeastOne());
 }