public void Complete_Removes_Headers()
        {
            //Arrange
            var correlationId = Guid.NewGuid();
            var saga          = new MySaga
            {
                CorrelationId = correlationId,
                Headers       = new Dictionary <string, string>()
                {
                    { "SomeKey", Guid.NewGuid().ToString() }
                },
            };

            database.Insert(new SagaData()
            {
                CorrelationId = correlationId, BlobData = JsonConvert.SerializeObject(saga.SagaData)
            });
            database.Insert(new SagaHeaders()
            {
                CorrelationId = correlationId, Key = saga.Headers.First().Key, Value = saga.Headers.First().Value
            });


            // Act
            sut.Complete(saga);

            // Assert
            var updatedHeaders = DatabaseHelpers.GetSagaHeaders(database, correlationId);

            updatedHeaders.Should().HaveCount(0);
        }
        public void Save_Updates_ExistingSagaData()
        {
            //Arrange
            var correlationId = Guid.NewGuid();
            var expectedGuid  = Guid.NewGuid();
            var saga          = new MySaga
            {
                CorrelationId = correlationId,
                SagaData      = { SomeGuid = Guid.NewGuid(), },
            };

            database.Insert(new SagaData()
            {
                CorrelationId = correlationId, BlobData = JsonConvert.SerializeObject(saga.SagaData)
            });

            saga.SagaData.SomeGuid = expectedGuid;

            // Act
            sut.Save(saga);

            // Assert
            var updatedData = DatabaseHelpers.GetSagaData(database, correlationId);

            updatedData.Should().NotBeNull();
            updatedData.BlobData.Should().ContainEquivalentOf(expectedGuid.ToString());
        }
        public void Save_Updates_ExistingHeaders()
        {
            //Arrange
            var correlationId = Guid.NewGuid();
            var expectedValue = Guid.NewGuid().ToString();
            var saga          = new MySaga
            {
                CorrelationId = correlationId,
                Headers       = new Dictionary <string, string>()
                {
                    { "SomeKey", Guid.NewGuid().ToString() }
                },
            };

            database.Insert(new SagaData()
            {
                CorrelationId = correlationId, BlobData = JsonConvert.SerializeObject(saga.SagaData)
            });
            database.Insert(new SagaHeaders()
            {
                CorrelationId = correlationId, Key = saga.Headers.First().Key, Value = saga.Headers.First().Value
            });

            saga.Headers["SomeKey"] = expectedValue;

            // Act
            sut.Save(saga);

            // Assert
            var updatedHeaders = DatabaseHelpers.GetSagaHeaders(database, correlationId);

            updatedHeaders.Should().HaveCount(1);
            updatedHeaders.First().Value.Should().Be(expectedValue);
        }
        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 #5
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 void Save_Persists_SagaData()
        {
            //Arrange
            var correlationId = Guid.NewGuid();
            var saga          = new MySaga {
                CorrelationId = correlationId
            };
            var expectedGuid = Guid.NewGuid();

            saga.SagaData.SomeGuid = expectedGuid;

            // Act
            sut.Save(saga);

            // Assert
            var restoredSaga = DatabaseHelpers.GetSagaData(database, correlationId);

            restoredSaga.Should().NotBeNull();
            restoredSaga.CorrelationId.Should().Be(correlationId);
            restoredSaga.BlobData.Should().ContainEquivalentOf(expectedGuid.ToString());
        }
        public void Complete_Removes_Data()
        {
            //Arrange
            var correlationId = Guid.NewGuid();
            var saga          = new MySaga
            {
                CorrelationId = correlationId,
            };

            database.Insert(new SagaData()
            {
                CorrelationId = correlationId, BlobData = JsonConvert.SerializeObject(saga.SagaData)
            });

            // Act
            sut.Complete(saga);

            // Assert
            var updatedData = DatabaseHelpers.GetSagaData(database, correlationId);

            updatedData.Should().BeNull();
        }
        public void Save_Persists_Headers()
        {
            //Arrange
            var correlationId = Guid.NewGuid();
            var saga          = new MySaga {
                CorrelationId = correlationId
            };
            var expectedValue = Guid.NewGuid().ToString();

            saga.Headers = new Dictionary <string, string>()
            {
                { "key", expectedValue }
            };

            // Act
            sut.Save(saga);

            // Assert
            var restoredHeaders = DatabaseHelpers.GetSagaHeaders(database, correlationId);

            restoredHeaders.Should().HaveCount(1);
            restoredHeaders.First().Value.Should().Be(expectedValue);
        }