Exemplo n.º 1
0
		private static ConfigurationStub GetConfiguration()
		{
			var result = new ConfigurationStub();
			if (TestConfigurationHelper.hibernateConfigFile != null)
				result.Configure(TestConfigurationHelper.hibernateConfigFile);
			return result;
		}
        public async Task SaveEvents_WithOneNewInitializedInterfaceEvent_ShouldAddEventInStore()
        {
            //Arrangements
            var sut = new ConfigurationStub <TestState>()
                      .WithDefaultSetup()
                      .WithDefaultStateFactory()
                      .WithEventApplier(new CountChangedApplier())
                      .GetNewSUT <int>();
            var id       = 5;
            var newCount = 3;

            using (var session = await sut.BeginSessionFor(id))
            {
                //Act
                session.AddEvent <ICountChangedInterfaceEvent>(x => x.NewCount = newCount);

                await session.SaveChanges();
            }

            //Assert
            sut[id].Should().NotBeNull();
            sut[id].Length.Should().Be(1);
            sut[id][0].instance.Should().BeAssignableTo <ICountChangedInterfaceEvent>();
            sut[id][0].instance.As <ICountChangedInterfaceEvent>().NewCount.Should().Be(newCount);
        }
Exemplo n.º 3
0
        private static ConfigurationStub GetConfiguration()
        {
            var result = new ConfigurationStub();

            if (TestConfigurationHelper.hibernateConfigFile != null)
            {
                result.Configure(TestConfigurationHelper.hibernateConfigFile);
            }
            return(result);
        }
Exemplo n.º 4
0
        public void WithUpconvertersFrom_NullAssembly_ShouldThrowArgumentNullException()
        {
            // Arrange
            var sut = new ConfigurationStub();

            // Act
            var exception = Record.Exception(() => sut.WithUpconvertersFrom((Assembly)null));

            // Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <ArgumentNullException>();
        }
        public void Execute_NoValidTopicEndpoint_ValidationFails()
        {
            // Arrange
            var configurationStub = new ConfigurationStub();
            var validationStep    = new EventGridTopicEndpointValidationStep(configurationStub);

            // Act
            var validationResult = validationStep.Execute();

            // Assert
            Assert.False(validationResult.Successful);
        }
        public async Task BeginSession_WithNewIdAndNotThrow_ShouldNotThrow()
        {
            //Arrangements
            var sut = new ConfigurationStub <TestState>()
                      .WithDefaultSetup()
                      .GetNewSUT <int>();

            //Act
            var exception = await Record.ExceptionAsync(() => sut.BeginSessionFor(123, throwIfNotExists: false));

            //Assert
            exception.Should().BeNull();
        }
Exemplo n.º 7
0
        public void WithUpconvertersFrom_UpconverterContainerAssembly_ShouldNotThrowException()
        {
            // Arrange
            var sut = new ConfigurationStub();

            // Act
            var exception = Record.Exception(() => sut.WithUpconvertersFrom(typeof(BullOak.Repositories.Test.Unit.UpconverterContainer.EventA).Assembly)
                                             .AndNoMoreUpconverters()
                                             .Build());

            // Assert
            exception.Should().BeNull();
        }
        public void Execute_InvalidTopicEndpoint_ValidationFails()
        {
            // Arrange
            const string configuredTopicEndpoint = "arcus";
            var          configurationStub       = new ConfigurationStub(EnvironmentVariables.Runtime.EventGrid.TopicEndpoint, configuredTopicEndpoint);
            var          validationStep          = new EventGridTopicEndpointValidationStep(configurationStub);

            // Act
            var validationResult = validationStep.Execute();

            // Assert
            Assert.False(validationResult.Successful);
        }
        public void Execute_HasValidTopicEndpoint_Succeeds()
        {
            // Arrange
            const string configuredTopicEndpoint = "https://arcus.com";
            var          configurationStub       = new ConfigurationStub(EnvironmentVariables.Runtime.EventGrid.TopicEndpoint, configuredTopicEndpoint);
            var          validationStep          = new EventGridTopicEndpointValidationStep(configurationStub);

            // Act
            var validationResult = validationStep.Execute();

            // Assert
            Assert.True(validationResult.Successful);
        }
Exemplo n.º 10
0
        private PagedResponse <BookProxy> GetByFilterAsync(PagedRequest <BookFilterPayload> pagination, Settings settings = null)
        {
            settings = settings ?? Settings.Empty;

            var config = ConfigurationStub.Create(() =>
            {
                return(settings);
            });

            var service = new BookService(Db, BusPublisherStub.Create(), config, TenantAccessorStub.Create());

            return(service.GetByFilterAsync(pagination).GetAwaiter().GetResult());
        }
Exemplo n.º 11
0
        private BookProxy GetByIdAsync(Guid id, Settings settings = null)
        {
            settings = settings ?? Settings.Empty;

            var config = ConfigurationStub.Create(() =>
            {
                return(settings);
            });

            var service = new BookService(Db, BusPublisherStub.Create(), config, TenantAccessorStub.Create());

            return(service.GetByIdAsync(id).GetAwaiter().GetResult());
        }
Exemplo n.º 12
0
        public void Execute_HasValidAuthKey_Succeeds()
        {
            // Arrange
            const string configuredAuthKey = "ABC";
            var          configurationStub = new ConfigurationStub(EnvironmentVariables.Runtime.EventGrid.AuthKey, configuredAuthKey);
            var          validationStep    = new EventGridAuthKeyValidationStep(configurationStub);

            // Act
            var validationResult = validationStep.Execute();

            // Assert
            Assert.True(validationResult.Successful);
        }
        public async Task BeginSession_WithNewId_ShouldReturnSession()
        {
            //Arrangements
            var sut = new ConfigurationStub <TestState>()
                      .WithDefaultSetup()
                      .GetNewSUT <int>();

            //Act
            var session = await sut.BeginSessionFor(123);

            //Assert
            session.Should().NotBeNull();
            session.Should().BeAssignableTo <IManageSessionOf <TestState> >();
        }
        public async Task BeginSession_WithNewIdAndThrowIfNotExist_ShouldThrowException()
        {
            //Arrangements
            var sut = new ConfigurationStub <TestState>()
                      .WithDefaultSetup()
                      .GetNewSUT <int>();

            //Act
            var exception = await Record.ExceptionAsync(() => sut.BeginSessionFor(123, throwIfNotExists: true));

            //Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <StreamNotFoundException>();
        }
        public async Task StreamWithoutEvents_Exists_ShouldReturnFalse()
        {
            //Arrange
            int id  = 42;
            var sut = new ConfigurationStub <TestState>()
                      .WithDefaultSetup()
                      .GetNewSUT <int>();

            //Act
            var exists = await sut.Contains(id);

            //Assert
            exists.Should().BeFalse();
        }
Exemplo n.º 16
0
        public void WithUpconvertersFrom_UpconverterContainerAssembly_ShouldLoadInternalUpconvertersOfInternalEvents()
        {
            // Arrange
            var sut = new ConfigurationStub();

            // Act
            sut.WithUpconvertersFrom(typeof(BullOak.Repositories.Test.Unit.UpconverterContainer.EventA).Assembly)
            .AndNoMoreUpconverters()
            .Build();

            // Assert
            sut.GetUpconvertFunctions()
            .Any(x => x.Key.Name.Equals("InternalEvent"))
            .Should().BeTrue();
        }
Exemplo n.º 17
0
        public void WhenAValidatorIsNotProvided_RepositoryShouldHaveAlwaysPassValidator()
        {
            //Arrange
            var sut = new ConfigurationStub <TestState>()
                      .WithDefaultSetup()
                      .GetNewSUT <int>();

            //Act
            var defaultValidator = sut.GetType()
                                   .GetField("stateValidator", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(sut);

            //Assert
            defaultValidator.Should().NotBeNull();
            defaultValidator.GetType().Should().Be <AlwaysPassValidator <TestState> >();
        }
Exemplo n.º 18
0
        public async Task WhenAValidatorIsNotProvided_StartSession_ShouldProvideSessionWithAlwaysPassValidator()
        {
            //Arrange
            var repo = new ConfigurationStub <TestState>()
                       .WithDefaultSetup()
                       .GetNewSUT <int>();
            var sut = await repo.BeginSessionFor(42);

            //Act
            var defaultValidator = (sut as InMemoryEventStoreSession <TestState, int>).StateValidator;

            //Assert
            defaultValidator.Should().NotBeNull();
            defaultValidator.GetType().Should().Be <AlwaysPassValidator <TestState> >();
        }
Exemplo n.º 19
0
        public async Task StreamWithOneEvent_BeginSessionWithThrowIfNotExists_ShouldNotThrow()
        {
            //Arrange
            int    id     = 42;
            object @event = new object();
            var    sut    = new ConfigurationStub <TestState>()
                            .WithDefaultSetup()
                            .GetNewSUT <int>()
                            .WithEventInStream(@event, id);

            //Act
            var exception = await Record.ExceptionAsync(() => sut.BeginSessionFor(id, true));

            //Assert
            exception.Should().BeNull();
        }
        public async Task StreamWithOneEvent_ExistsWithDifferentId_ShouldReturnFalse()
        {
            //Arrange
            int    idWithEvent = 42;
            object @event      = new object();
            var    sut         = new ConfigurationStub <TestState>()
                                 .WithDefaultSetup()
                                 .GetNewSUT <int>()
                                 .WithEventInStream(@event, idWithEvent);

            //Act
            var exists = await sut.Contains(idWithEvent + 1);

            //Assert
            exists.Should().BeFalse();
        }
        public async Task StreamWithOneEvent_Clear_ShouldEmptyStream()
        {
            //Arrange
            int    id     = 42;
            object @event = new object();
            var    sut    = new ConfigurationStub <TestState>()
                            .WithDefaultSetup()
                            .GetNewSUT <int>()
                            .WithEventInStream(@event, id);

            //Act
            await sut.Delete(id);

            //Assert
            sut[id].Should().BeEmpty();
        }
Exemplo n.º 22
0
        public async Task WhenAValidatorIsProvided_StartSession_ShouldProvideSessionWithValidator()
        {
            //Arrange
            int id   = 42;
            var repo = new ConfigurationStub <TestState>()
                       .WithDefaultSetup()
                       .GetNewSUT <int>(new AlwaysFailValidator <TestState>());
            var sut = await repo.BeginSessionFor(id);

            //Act
            var exception = await Record.ExceptionAsync(() => sut.SaveChanges());

            //Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <AggregateException>();
            (exception as AggregateException).InnerExceptions[0].Should().BeOfType <BusinessException>();
        }
Exemplo n.º 23
0
        private BookUpdateMessage SaveAsync(BookMessage model, Settings settings = null)
        {
            settings = settings ?? Settings.Empty;

            var config = ConfigurationStub.Create(() =>
            {
                return(settings);
            });

            var bus = BusPublisherStub.Create();

            var service = new BookService(Db, bus, config, TenantAccessorStub.Create());

            service.SaveAsync(model).Wait();

            return(bus.DequeueExchange <BookUpdateMessage>(ExchangeNames.Book));
        }
        public async Task StreamWithOneEvent_ClearThenBeginSessionWiththrowIfNotExist_ShouldThrow()
        {
            //Arrange
            int    id     = 42;
            object @event = new object();
            var    sut    = new ConfigurationStub <TestState>()
                            .WithDefaultSetup()
                            .GetNewSUT <int>()
                            .WithEventInStream(@event, id);
            await sut.Delete(id);

            //Act
            var exception = await Record.ExceptionAsync(() => sut.BeginSessionFor(id, true));

            //Assert
            exception.Should().NotBeNull();
            exception.Should().BeOfType <StreamNotFoundException>();
        }
Exemplo n.º 25
0
        public void WithUpconvertersFrom_OneUpconverterTypeAndOneOtherType_ShouldNotThrowException()
        {
            // Arrange
            var sut  = new ConfigurationStub();
            var data = new Type[]
            {
                GetType(),
                typeof(UpconverterAToB)
            };

            // Act
            var build = sut.WithUpconvertersFrom(data)
                        .AndNoMoreUpconverters();
            var exception = Record.Exception(() => build.Build());

            // Assert
            exception.Should().BeNull();
        }
        public async Task DisposeSession_WithOneEvent_ShouldNotPublishEvents()
        {
            //Arrangements
            var config = new ConfigurationStub <TestState>()
                         .WithDefaultSetup();
            var sut    = config.GetNewSUT <int>();
            var @event = new object();
            var id     = 42;

            using (var session = await sut.BeginSessionFor(id))
            {
                //Act
                session.AddEvent(@event);
            }

            //Assert
            config.EventsThatHaveBeenPublished.Count.Should().Be(0);
        }
        public async Task DisposeSession_WithOneEvent_ShouldNotSaveEvents()
        {
            //Arrangements
            var sut = new ConfigurationStub <TestState>()
                      .WithDefaultSetup()
                      .GetNewSUT <int>();
            var @event = new object();
            var id     = 42;

            using (var session = await sut.BeginSessionFor(id))
            {
                //Act
                session.AddEvent(@event);
            }

            //Assert
            sut[id].Should().BeEmpty();
        }
Exemplo n.º 28
0
        private (ShippingDtoMessage Dto, DropCopyNumberMessage Proxy) CreateAsync(PurchaseMessage message, Settings settings = null)
        {
            settings = settings ?? Settings.Empty;

            var config = ConfigurationStub.Create(() =>
            {
                return(settings);
            });

            var bus = BusPublisherStub.Create();

            var service = new PurchaseService(Db, bus, config, TenantAccessorStub.Create());

            service.CreateAsync(message).Wait();

            var drop    = bus.Dequeue <DropCopyNumberMessage>(QueueNames.Library);
            var payload = bus.Dequeue <ShippingDtoMessage>(QueueNames.Bookstore);

            return(payload, drop);
        }
        public async Task SaveEvents_WithOneNewEvent_ShouldAddEventInStore()
        {
            //Arrangements
            var sut = new ConfigurationStub <TestState>()
                      .WithDefaultSetup()
                      .GetNewSUT <int>();
            var @event = new object();
            var id     = 42;

            using (var session = await sut.BeginSessionFor(id))
            {
                //Act
                session.AddEvent(@event);
                await session.SaveChanges();
            }

            //Assert
            sut[id].Should().NotBeNull();
            sut[id].Length.Should().Be(1);
            sut[id][0].instance.Should().Be(@event);
        }
Exemplo n.º 30
0
        public void WithUpconvertersFrom_OneUpconverterTypeAndOneOtherType_ShouldAddOneUpconverterInList()
        {
            // Arrange
            var sut  = new ConfigurationStub();
            var data = new Type[]
            {
                GetType(),
                typeof(UpconverterAToB)
            };

            // Act
            sut.WithUpconvertersFrom(data)
            .AndNoMoreUpconverters()
            .Build();

            // Assert
            var upconvertFuncs = sut.GetUpconvertFunctions();

            upconvertFuncs.Should().NotBeNull();
            upconvertFuncs.Length.Should().Be(1);
            upconvertFuncs[0].Key.Should().Be <EventA>();
        }
        public async Task StreamWithOneEvent_BeginSessionAndAddOneEvent_ShouldHaveStreamWith2Events()
        {
            //Arrange
            int    id     = 42;
            object @event = new object();
            var    sut    = new ConfigurationStub <TestState>()
                            .WithDefaultSetup()
                            .GetNewSUT <int>()
                            .WithEventInStream(@event, id);
            object newEvent = new object();

            //Act
            using (var session = await sut.BeginSessionFor(id))
            {
                session.AddEvent(newEvent);
                await session.SaveChanges();
            }

            //Assert
            sut[id].Length.Should().Be(2);
            sut[id][1].instance.Should().Be(newEvent);
        }