public async Task Should_Add_Subscription_To_Database() { var options = new DbContextOptionsBuilder <SubscriptionContext>() .AddInterceptors(new DomainEventDispatcher(Substitute.For <IMediator>())) .UseSqlServer("Server=localhost;Database=Subscriptions;uid=sa;pwd=yourStrong(!)Password;") .Options; var context = new SubscriptionContext(options); await context.Database.EnsureCreatedAsync(); var product = new Product("Flowers", 10, BillingPeriod.Monthly); var customer = new Customer(new Email("*****@*****.**"), new CustomerName("Hossam", "Barakat")); await context.Products.AddAsync(product); await context.Customers.AddAsync(customer); await context.SaveChangesAsync(); var handler = new SubscribeRequestHandler(context, new SubscriptionAmountCalculator()); await handler.Handle(new SubscribeRequest { CustomerId = customer.Id, ProductId = product.Id }, CancellationToken.None); var subscription = await context.Subscriptions .SingleOrDefaultAsync(x => x.Customer.Id == customer.Id && x.Product.Id == product.Id); subscription.ShouldNotBeNull(); }
public async Task Should_Add_Subscription_To_Database() { var options = new DbContextOptionsBuilder <SubscriptionContext>() .UseSqlServer("Server=localhost;Database=Subscriptions;uid=sa;pwd=yourStrong(!)Password;") .Options; var context = new SubscriptionContext(options); await context.Database.EnsureCreatedAsync(); var customer = new Customer { Id = Guid.NewGuid(), Email = "*****@*****.**", FirstName = "Hossam", LastName = "Barakat" }; await context.Customers.AddAsync(customer); var product = new Product { Id = Guid.NewGuid(), Name = "Weekly Bunch", Amount = 10, BillingPeriod = BillingPeriod.Monthly }; await context.Products.AddAsync(product); await context.SaveChangesAsync(); var sut = new SubscribeRequestHandler(context, Substitute.For <IEmailSender>()); var subscribeRequest = new SubscribeRequest { CustomerId = customer.Id, ProductId = product.Id }; await sut.Handle(subscribeRequest, CancellationToken.None); var subscription = await context.Subscriptions .SingleOrDefaultAsync(x => x.Customer.Id == customer.Id && x.Product.Id == product.Id); subscription.ShouldNotBeNull(); }