Exemple #1
0
        public void Test_Execution_To_Failue_On_Waiting_For_Transaction_Ending()
        {
            // Arrange

            var switcher  = TransitionExecutionStateSwitcherBuilder.Build();
            var aggregate = TransactionExecutionAggregate.Start
                            (
                Guid.NewGuid(),
                Guid.NewGuid(),
                0,
                "",
                new[] { new TransactionOutputValueType("", 0) },
                "",
                "",
                "",
                false
                            );

            // Act / Assert

            Assert.Equal(TransactionExecutionState.Started, aggregate.State);

            Assert.True(switcher.Switch(aggregate, new SourceAddressLockedEvent()));
            Assert.Equal(TransactionExecutionState.SourceAddressLocked, aggregate.State);

            Assert.True(switcher.Switch(aggregate, new TransactionBuiltEvent()));
            Assert.Equal(TransactionExecutionState.Built, aggregate.State);

            Assert.True(switcher.Switch(aggregate, new TransactionSignedEvent()));
            Assert.Equal(TransactionExecutionState.Signed, aggregate.State);

            Assert.True(switcher.Switch(aggregate, new TransactionBroadcastedEvent()));
            Assert.Equal(TransactionExecutionState.Broadcasted, aggregate.State);

            Assert.True(switcher.Switch(aggregate, new SourceAddressLockReleasedEvent()));
            Assert.Equal(TransactionExecutionState.WaitingForEnding, aggregate.State);

            Assert.True(switcher.Switch(aggregate, new TransactionExecutionFailedEvent
            {
                ErrorCode = TransactionExecutionResult.UnknownError
            }));
            Assert.Equal(TransactionExecutionState.WaitingForEndingFailed, aggregate.State);

            Assert.True(switcher.Switch(aggregate, new BroadcastedTransactionClearedEvent()));
            Assert.Equal(TransactionExecutionState.Cleared, aggregate.State);
        }
        protected override void Load(ContainerBuilder builder)
        {
            builder.Register(context => new AutofacDependencyResolver(context)).As <IDependencyResolver>().SingleInstance();

            builder.Register(c => new RetryDelayProvider(
                                 _settings.SourceAddressLockingRetryDelay,
                                 _settings.WaitForTransactionRetryDelay,
                                 _settings.NotEnoughBalanceRetryDelay,
                                 _settings.RebuildingConfirmationCheckRetryDelay))
            .AsSelf();

            builder.RegisterInstance(TransitionExecutionStateSwitcherBuilder.Build())
            .As <IStateSwitcher <TransactionExecutionAggregate> >();

            builder.RegisterInstance(OperationExecutionStateSwitcherBuilder.Build())
            .As <IStateSwitcher <OperationExecutionAggregate> >();

            // Sagas
            builder.RegisterType <TransactionExecutionSaga>();
            builder.RegisterType <OperationExecutionSaga>();

            // Interceptors
            builder.RegisterType <ErrorsCommandInterceptor>();
            builder.RegisterType <ErrorsEventInterceptor>();

            // Command handlers
            builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource(t =>
                                                                                 t.Namespace == typeof(StartOperationExecutionCommandsHandler).Namespace ||
                                                                                 t.Namespace == typeof(StartTransactionExecutionCommandHandler).Namespace));

            //CQRS Message Cancellation
            Lykke.Cqrs.MessageCancellation.Configuration.ContainerBuilderExtensions.RegisterCqrsMessageCancellation(
                builder,
                (options) =>
            {
                #region Registry

                //Commands
                options.Value
                .MapMessageId <ClearActiveTransactionCommand>(x => x.OperationId.ToString())
                .MapMessageId <GenerateActiveTransactionIdCommand>(x => x.OperationId.ToString())
                .MapMessageId <NotifyOperationExecutionCompletedCommand>(x => x.OperationId.ToString())
                .MapMessageId <NotifyOperationExecutionFailedCommand>(x => x.OperationId.ToString())
                .MapMessageId <BroadcastTransactionCommand>(x => x.OperationId.ToString())
                .MapMessageId <BuildTransactionCommand>(x => x.OperationId.ToString())
                .MapMessageId <ClearBroadcastedTransactionCommand>(x => x.OperationId.ToString())
                .MapMessageId <LockSourceAddressCommand>(x => x.OperationId.ToString())
                .MapMessageId <ReleaseSourceAddressLockCommand>(x => x.OperationId.ToString())
                .MapMessageId <SignTransactionCommand>(x => x.OperationId.ToString())
                .MapMessageId <StartTransactionExecutionCommand>(x => x.OperationId.ToString())
                .MapMessageId <WaitForTransactionEndingCommand>(x => x.OperationId.ToString())
                .MapMessageId <StartOperationExecutionCommand>(x => x.OperationId.ToString())
                .MapMessageId <StartOneToManyOutputsExecutionCommand>(x => x.OperationId.ToString())

                //Events
                .MapMessageId <ActiveTransactionClearedEvent>(x => x.OperationId.ToString())
                .MapMessageId <ActiveTransactionIdGeneratedEvent>(x => x.OperationId.ToString())
                .MapMessageId <OperationExecutionStartedEvent>(x => x.OperationId.ToString())
                .MapMessageId <BroadcastTransactionCommand>(x => x.OperationId.ToString())
                .MapMessageId <SourceAddressLockedEvent>(x => x.OperationId.ToString())
                .MapMessageId <SourceAddressLockReleasedEvent>(x => x.OperationId.ToString())
                .MapMessageId <TransactionBroadcastedEvent>(x => x.OperationId.ToString())
                .MapMessageId <TransactionBuildingRejectedEvent>(x => x.OperationId.ToString())
                .MapMessageId <TransactionBuiltEvent>(x => x.OperationId.ToString())
                .MapMessageId <TransactionExecutionCompletedEvent>(x => x.OperationId.ToString())
                .MapMessageId <TransactionExecutionFailedEvent>(x => x.OperationId.ToString())
                .MapMessageId <TransactionExecutionRepeatRequestedEvent>(x => x.OperationId.ToString())
                .MapMessageId <TransactionExecutionStartedEvent>(x => x.OperationId.ToString())
                .MapMessageId <TransactionReBuildingRejectedEvent>(x => x.OperationId.ToString())
                .MapMessageId <TransactionSignedEvent>(x => x.OperationId.ToString())
                .MapMessageId <OneToManyOperationExecutionCompletedEvent>(x => x.OperationId.ToString())
                .MapMessageId <OperationExecutionCompletedEvent>(x => x.OperationId.ToString())
                .MapMessageId <OperationExecutionFailedEvent>(x => x.OperationId.ToString())
                .MapMessageId <BroadcastedTransactionClearedEvent>(x => x.OperationId.ToString());

                #endregion
            });

            builder.Register(CreateEngine)
            .As <ICqrsEngine>()
            .SingleInstance()
            .AutoActivate();
        }