public void Run()
        {
            var builder = Wireup.UseInternalContainer()
                          .UseSqlServer()
                          .WithConnectionStringName("NSagaDatabase")
                          .UseMessageSerialiser <JsonNetSerialiser>();

            sagaMediator = builder.ResolveMediator();

            sagaRepository = builder.ResolveRepository();

            var correlationId = Guid.NewGuid();

            StartSaga(correlationId);

            RequestVerificationCode(correlationId);

            ProvideVerificationCode(correlationId);

            CreateAccount(correlationId);

            var saga      = sagaRepository.Find <AccountCreationSaga>(correlationId);
            var jamesName = saga.SagaData.Person.FullName;

            Console.WriteLine($"Taking information from SagaData; Person.FullName='{jamesName}'");
        }
Example #2
0
        public void Run()
        {
            try
            {
                // You need Azure Storage emulator running to run this
                var connectionString = "UseDevelopmentStorage=true";
                var builder          = Wireup.UseInternalContainer()
                                       .UseRepository <AzureTablesSagaRepository>()
                                       .Register(typeof(ITableClientFactory), new TableClientFactory(connectionString));

                sagaMediator = builder.ResolveMediator();

                var correlationId = Guid.NewGuid();
                var initMessage   = new PersonalDetailsVerification(correlationId)
                {
                    FirstName = "James",
                    LastName  = "Bond",
                };

                sagaMediator.Consume(initMessage);
            }
            catch (Exception)
            {
                Console.WriteLine("Quite likely you don't have Azure Storage Emulator running, so this sample can't be executed");
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            var builder    = Wireup.UseInternalContainer();
            var repository = builder.ResolveRepository();

            var correlationId = Guid.NewGuid();

            var simpleSaga = new VerySimpleSaga()
            {
                CorrelationId = correlationId,
                SagaData      = new DataStorage(),
                Headers       = new Dictionary <string, string>(),
            };

            repository.Save(simpleSaga); // initiate

            var result = simpleSaga.Consume(new SimpleMessage()
            {
                CorrelationId = correlationId, Value = "blah"
            });

            if (result.IsSuccessful)
            {
                repository.Save(simpleSaga);
            }

            Console.ReadKey();
        }
Example #4
0
        public Metadata()
        {
            var messageSerialiser = Wireup.UseInternalContainer().Resolve <IMessageSerialiser>();

            var simpleSaga = new VerySimpleSaga();
            var metadata   = simpleSaga.GetSagaMetadata(messageSerialiser);
        }
Example #5
0
        public MediatorBenchmarking()
        {
            mediator = Wireup.UseInternalContainer().UseRepository <FastSagaRepository>().ResolveMediator();

            correlationId = Guid.NewGuid();
            mediator.Consume(new FirstMessage(Program.FirstGuid));
        }
    public StaticReference()
    {
        var builder = Wireup.UseInternalContainer()
                      .UseRepository <DummySagaRepository>()
                      .UseMessageSerialiser <DummyMessageSerialiser>()
                      .UseSagaFactory <DummySagaFactory>();

        SagaMediatorBuilder.Current = builder;

        var sagaMediator = SagaMediatorBuilder.Current.ResolveMediator();
    }
Example #7
0
        public void DefaultRegistration_Resolves_DefaultComponents(Type requestedType, Type expectedImplementation)
        {
            //Arrange
            var builder = Wireup.UseInternalContainer(Assembly.GetExecutingAssembly());

            // Act
            var result = builder.Resolve(requestedType);

            // Assert
            result.Should().NotBeNull()
            .And.BeOfType(expectedImplementation);
        }
Example #8
0
        public void OverrideSagaFactory_Resolves_OverridenFactory()
        {
            // Arrange
            var builder = Wireup.UseInternalContainer(Assembly.GetExecutingAssembly())
                          .UseSagaFactory <NullSagaFactory>();

            // Act
            var result = builder.Resolve <ISagaFactory>();

            // Assert
            result.Should().NotBeNull().And.BeOfType <NullSagaFactory>();
        }
Example #9
0
        public void Default_Can_Initialise_Saga()
        {
            //Arrange
            var correlationId = Guid.NewGuid();
            var sagaMediator  = Wireup.UseInternalContainer(Assembly.GetExecutingAssembly()).ResolveMediator();

            // Act
            var result = sagaMediator.Consume(new MySagaInitiatingMessage(correlationId));

            // Assert
            result.IsSuccessful.Should().BeTrue();
        }
Example #10
0
        public void UseSqlServer_SetsPrivate_ToSqlRepository()
        {
            //Arrange
            var builder = Wireup.UseInternalContainer()
                          .UseSqlServer()
                          .WithConnectionStringName("TestingConnectionString");
            // Act
            var repository = builder.Resolve <ISagaRepository>();

            // Assert
            repository.Should().BeOfType <SqlSagaRepository>();
        }
        public void OverrideRepository_Resolves_OverridenRepository()
        {
            //Arrange
            var builder = Wireup.UseInternalContainer()
                          .UseRepository <NullSagaRepository>();

            // Act
            var result = builder.Resolve <ISagaRepository>();

            // Assert
            result.Should().NotBeNull().And.BeOfType <NullSagaRepository>();
        }
Example #12
0
        static void Main(string[] args)
        {
            // You need Azure Storage emulator running to run this
            var connectionString = "UseDevelopmentStorage=true";
            var builder          = Wireup.UseInternalContainer()
                                   .AddAssemblyToScan(typeof(ShoppingBasketSaga).Assembly)
                                   .UseRepository <AzureTablesSagaRepository>()
                                   .Register(typeof(ITableClientFactory), new TableClientFactory(connectionString));

            // register dependencies for sagas
            builder.Register(typeof(IEmailService), typeof(ConsoleEmailService));
            builder.Register(typeof(ICustomerRepository), typeof(SimpleCustomerRepository));


            var mediator = builder.ResolveMediator();

            var correlationId = Guid.NewGuid();

            // start the shopping.
            mediator.Consume(new StartShopping()
            {
                CorrelationId = correlationId,
                CustomerId    = Guid.NewGuid(),
            });

            // add a product into the basket
            mediator.Consume(new AddProductIntoBasket()
            {
                CorrelationId = correlationId,
                ProductId     = 1,
                ProductName   = "Magic Dust",
                ItemCount     = 42,
                ItemPrice     = 42.42M,
            });

            // retrieve the saga from the storage
            var repository = builder.ResolveRepository();
            var saga       = repository.Find <ShoppingBasketSaga>(correlationId);

            // you can access saga data this way
            if (saga.SagaData.BasketCheckedout)
            {
                // and issue another message
                mediator.Consume(new NotifyCustomerAboutBasket()
                {
                    CorrelationId = correlationId
                });
            }

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Example #13
0
        public void DefaultRegistration_ResolvePipline_ResolvesMetadataHook()
        {
            //Arrange
            var builder = Wireup.UseInternalContainer(Assembly.GetExecutingAssembly());

            // Act
            var result = builder.Resolve <IEnumerable <IPipelineHook> >();

            // Assert
            result.Should().NotBeNull()
            .And.HaveCount(1)
            .And.Contain(h => h.GetType() == typeof(MetadataPipelineHook));
        }
Example #14
0
        public void UseSqlServer_Registers_SqlServerRepository()
        {
            //Arrange
            var mediatorBuilder = Wireup.UseInternalContainer()
                                  .UseSqlServer()
                                  .WithConnectionStringName("TestingConnectionString");

            // Act
            var repository = mediatorBuilder.ResolveRepository();


            // Assert
            repository.Should().BeOfType <SqlSagaRepository>();
        }
        /// <summary>
        /// Default constructor to initialize the policy constructor
        /// </summary>
        /// <param name="request">New policy request</param>
        public PolicyCreator(NewPolicyRequest request)
        {
            _newPolicyRequest = request;

            var builder = Wireup.UseInternalContainer().UseMessageSerialiser <JsonNetSerialiser>();

            sagaMediator   = builder.ResolveMediator();
            sagaRepository = builder.ResolveRepository();

            _guid = Guid.NewGuid();
            Console.WriteLine($"New GUID: {_guid}");

            ((ISagaMessage)_newPolicyRequest).CorrelationId = _guid;
        }
Example #16
0
        public void AddingPipeline_Adds_ToCollection()
        {
            //Arrange
            var builder = Wireup.UseInternalContainer(Assembly.GetExecutingAssembly())
                          .AddPiplineHook <NullPipelineHook>();

            // Act
            var result = builder.Resolve <IEnumerable <IPipelineHook> >();

            // Assert
            result.Should().NotBeNull()
            .And.HaveCount(2)
            .And.Contain(h => h.GetType() == typeof(MetadataPipelineHook))
            .And.Contain(h => h.GetType() == typeof(NullPipelineHook));
        }
Example #17
0
    static void Main(string[] args)
    {
        var builder = Wireup.UseInternalContainer()
                      .UseSqlServer()
                      .WithConnectionStringName("NSagaDatabase");

        // register dependencies for sagas
        builder.Register(typeof(IEmailService), typeof(ConsoleEmailService));
        builder.Register(typeof(ICustomerRepository), typeof(SimpleCustomerRepository));

        var mediator = builder.ResolveMediator();

        var correlationId = Guid.NewGuid();

        // start the shopping.
        mediator.Consume(new StartShopping()
        {
            CorrelationId = correlationId,
            CustomerId    = Guid.NewGuid(),
        });

        // add a product into the basket
        mediator.Consume(new AddProductIntoBasket()
        {
            CorrelationId = correlationId,
            ProductId     = 1,
            ProductName   = "Magic Dust",
            ItemCount     = 42,
            ItemPrice     = 42.42M,
        });

        // retrieve the saga from the storage
        var repository = builder.ResolveRepository();
        var saga       = repository.Find <ShoppingBasketSaga>(correlationId);

        // you can access saga data this way
        if (saga.SagaData.BasketCheckedout)
        {
            // and issue another message
            mediator.Consume(new NotifyCustomerAboutBasket()
            {
                CorrelationId = correlationId
            });
        }

        Console.WriteLine("Press any key to exit");
        Console.ReadKey();
    }
Example #18
0
        public void UseSqlServerWithProviderName_Database_IsUsed()
        {
            //Arrange
            var mediator = Wireup.UseInternalContainer()
                           .UseSqlServer()
                           .WithConnectionString(@"Server=(localdb)\v12.0;Database=NSaga-Testing")
                           .ResolveMediator();
            var correlationId = Guid.NewGuid();

            // Act
            var result = mediator.Consume(new MySagaInitiatingMessage(correlationId));

            // Assert
            result.IsSuccessful.Should().BeTrue();
            var sagaData = DatabaseHelpers.GetSagaData(database, correlationId);

            sagaData.Should().NotBeNull();
        }
Example #19
0
        public void UseSqlServer_Database_IsUsed()
        {
            //Arrange
            var mediator = Wireup.UseInternalContainer(Assembly.GetExecutingAssembly())
                           .UseSqlServer()
                           .WithConnectionStringName("TestingConnectionString")
                           .ResolveMediator();
            var correlationId = Guid.NewGuid();

            // Act
            var result = mediator.Consume(new MySagaInitiatingMessage(correlationId));

            // Assert
            result.IsSuccessful.Should().BeTrue();
            var sagaData = DatabaseHelpers.GetSagaData(database, correlationId);

            sagaData.Should().NotBeNull();
        }
 public AddPipelineHook()
 {
     var builder = Wireup.UseInternalContainer()
                   .AddPiplineHook <DummyPipelineHook>();
 }
Example #21
0
        public TinyIocSagaFactoryTests()
        {
            var builder = Wireup.UseInternalContainer(Assembly.GetExecutingAssembly());

            Sut = builder.Resolve <ISagaFactory>();
        }
 public ReplaceRepository()
 {
     var builder = Wireup.UseInternalContainer()
                   .UseRepository <DummySagaRepository>();
 }
Example #23
0
 public ReplaceAssemblies()
 {
     var builder = Wireup.UseInternalContainer()
                   .ReplaceAssembliesToScan(new Assembly[] { typeof(ReplaceAssemblies).Assembly })
                   .AddAssembliesToScan(new Assembly[] { typeof(VerySimpleSaga).Assembly });
 }
Example #24
0
        public TinyIocSagaFactoryTests()
        {
            var builder = Wireup.UseInternalContainer();

            Sut = builder.Resolve <ISagaFactory>();
        }
Example #25
0
 public ReplaceMessageSerialiser()
 {
     var builder = Wireup.UseInternalContainer()
                   .UseMessageSerialiser <DummyMessageSerialiser>();
 }