Esempio n. 1
0
        public static EventStore WithDefaults()
        {
            var options = new DbContextOptionsBuilder <EventStore>()
                          .UseInMemoryDatabase($"{Guid.NewGuid()}")
                          .Options;

            var dateTime = new MachineDateTime();

            var correlationIdAccessor = new TestCorrelationIdAccessor(Guid.NewGuid());

            var eventStore = new EventStore(options, dateTime, correlationIdAccessor, Mock.Of <IMediator>());

            return(eventStore);
        }
Esempio n. 2
0
        public static AppDbContext WithDefaults()
        {
            var options = new DbContextOptionsBuilder()
                          .UseInMemoryDatabase($"{Guid.NewGuid()}")
                          .Options;

            var context      = new EventStoreDbContext(options);
            var dateTime     = new MachineDateTime();
            var eventStore   = new EventStore(context, dateTime, new TestCorrelationIdAccessor(Guid.NewGuid()));
            var aggregateSet = new AggregateSet(context, dateTime);

            var appDbContext = new AppDbContext(eventStore, aggregateSet);

            DbInitializer.Initialize(appDbContext, ConfigurationFactory.Create());

            appDbContext.SaveChangesAsync(default).GetAwaiter().GetResult();
Esempio n. 3
0
        public async Task Should_StoreAndReHydrateCorrectly()
        {
            var fakeId = Guid.NewGuid();

            var dateRange = DateRange.Create(DateTime.UtcNow.AddDays(1), DateTime.UtcNow.AddDays(2)).Value;

            var rental = new Rental(fakeId, fakeId, dateRange, (Price)1m);

            var dateTime            = new MachineDateTime();
            var options             = new DbContextOptionsBuilder().UseInMemoryDatabase("UnitTest").Options;
            var eventStoreDbContext = new EventStoreDbContext(options);
            var eventStore          = new EventStore(eventStoreDbContext, dateTime);
            var aggregateSet        = new AggregateSet(eventStoreDbContext, dateTime);

            eventStore.Store(rental);

            await eventStore.SaveChangesAsync(default);
        protected override void Dispose(bool disposing)
        {
            var options = new DbContextOptionsBuilder()
                          .UseSqlServer(_configuration[DataDefaultConnectionString])
                          .Options;

            var dateTime = new MachineDateTime();

            var context = new EventSourcingDistilledDbContext(options, dateTime, new TestCorrelationIdAccessor(_correlationId));

            foreach (var storedEvent in context.StoredEvents.Where(x => x.CorrelationId == _correlationId))
            {
                context.Remove(storedEvent);
            }

            context.SaveChanges();

            base.Dispose(disposing);
        }
        public async Task AddInterest_Tests(decimal yearlyint, int accountid)
        {
            var account = new Account()
            {
                AccountId = 1, Balance = 10000
            };
            var command = new AddInterestCommand()
            {
                AccountId      = accountid,
                YearlyInterest = yearlyint, LatestInterest = DateTime.Now
            };

            var options = new DbContextOptionsBuilder <BankAppDataContext>()
                          .UseInMemoryDatabase(databaseName: "AddInterest_Tests")
                          .Options;

            decimal expected;

            using (var context = new BankAppDataContext(options))
            {
                context.Add(new Account()
                {
                    AccountId = 1, Balance = 10000
                });
                context.SaveChanges();
                var machine = new MachineDateTime()
                {
                };
                machine.Now = machine.Now.AddDays(30);
                var handler = new AddInterestCommandHandler(context, machine);

                expected = 10039.73m;

                await handler.Handle(command, CancellationToken.None);

                var newbalance = await context.Accounts.SingleOrDefaultAsync(a => a.AccountId == 1);

                var test = Math.Round(newbalance.Balance, 2);
                Assert.Equal(expected, test);
            }
        }