Esempio n. 1
0
        public void Command_objects_can_specify_idempotency_token_by_implementing_IIdempotent()
        {
            var command = new CreateCommandTarget(Guid.NewGuid().ToString());

            var delivery1 = new CommandDelivery <CreateCommandTarget>(command);
            var delivery2 = new CommandDelivery <CreateCommandTarget>(command);

            delivery1.IdempotencyToken.Should().Be(delivery2.IdempotencyToken);
        }
Esempio n. 2
0
        public async Task CommandReceiver_Trace_publishes_delivery_properties_as_telemetry_properties()
        {
            // arrange
            var dueTime = DateTimeOffset.Parse("2086-12-05", CultureInfo.InvariantCulture);

            var command = new CreateCommandTarget("the-id");

            var handler = CommandHandler.Create <CreateCommandTarget>(d => d.Complete());

            var delivery = new CommandDelivery <CreateCommandTarget>(
                command,
                idempotencyToken: "the-idempotency-token",
                dueTime: dueTime,
                numberOfPreviousAttempts: 4);
            await configuration.CommandScheduler <CreateCommandTarget>().Schedule(delivery);

            // act
            await configuration.CommandReceiver <CreateCommandTarget>().Receive(handler);

            // assert
            var logEvent = log[4];

            logEvent
            .Category
            .Should()
            .Be("CommandReceiver<CreateCommandTarget>",
                "we're verifying that we have the right log event");

            var properties = logEvent
                             .Evaluate()
                             .Properties;

            properties
            .Should()
            .Contain(t => t.Name == "IdempotencyToken" &&
                     t.Value.As <string>() == "the-idempotency-token");
            properties
            .Should()
            .Contain(t => t.Name == "DueTime" &&
                     t.Value.As <DateTimeOffset>() == dueTime);

            properties
            .Should()
            .Contain(t => t.Name == "NumberOfPreviousAttempts" &&
                     t.Value.As <int>() == 4);
        }