Ejemplo n.º 1
0
        public async Task WhenCreatePaymentAsync_ThenPaymentCreated()
        {
            // Arrange
            var payment = new Payment()
            {
                ID               = Guid.NewGuid(),
                CustomerID       = Guid.NewGuid(),
                Amount           = 100,
                ApproverID       = Guid.NewGuid(),
                Comment          = "test",
                PaymentStatus    = PaymentStatus.Pending,
                PaymentDateUtc   = DateTime.UtcNow,
                ProcessedDateUtc = DateTime.UtcNow.AddDays(1),
                RequestedDateUtc = DateTime.UtcNow.AddDays(2)
            };

            // Act
            var result = await _repo.CreatePaymentAsync(payment);

            // Assert
            result.Should().BeEquivalentTo(payment);
            using (var ctx = _dbContextCreator.CreateDbContext())
            {
                var paymentInDb = await ctx.Payment.FirstOrDefaultAsync();

                paymentInDb.Should().BeEquivalentTo(payment);
            }
        }
Ejemplo n.º 2
0
        public async Task GivenCustomerExists_WhenCreatePayment_ThenPaymentCreated()
        {
            // Arrange
            var customer = new Customer()
            {
                ID             = Guid.NewGuid(),
                CurrentBalance = 200
            };

            using (var ctx = _dbContextCreator.CreateDbContext())
            {
                ctx.Add(customer);
                await ctx.SaveChangesAsync();
            }

            var payment = new Payment()
            {
                ID             = Guid.NewGuid(),
                Amount         = 100,
                PaymentDateUtc = DateTime.UtcNow.AddDays(5),
                CustomerID     = customer.ID
            };

            // Act
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, Url);

            message.Content = new ObjectContent <Payment>(payment, new JsonMediaTypeFormatter());
            var response = await _client.SendAsync(message);

            var result = await response.Content.ReadAsAsync <Payment>();

            // Assert
            response.EnsureSuccessStatusCode();
            Assert.Equal(_utcNow, result.RequestedDateUtc);
            Assert.Equal(payment.ID, result.ID);
            Assert.Equal(payment.Amount, result.Amount);
            Assert.Equal(payment.PaymentDateUtc, result.PaymentDateUtc);
            Assert.Equal(payment.CustomerID, result.CustomerID);
            Assert.Equal(PaymentStatus.Pending, result.PaymentStatus);

            using (var ctx = _dbContextCreator.CreateDbContext())
            {
                var paymentInDb = await ctx.Payment.FirstOrDefaultAsync();

                result.Should().BeEquivalentTo(paymentInDb, options => options.Excluding(p => p.Customer));

                var customerInDb = await ctx.Customer.FirstOrDefaultAsync();

                Assert.Equal(customer.CurrentBalance - payment.Amount, customerInDb.CurrentBalance);
            }
        }
Ejemplo n.º 3
0
        public async Task GivenCustomerExists_WhenTopUpCustomerBalance_ThenBalanceToppedUp()
        {
            // Arrange
            var customer = new Customer()
            {
                ID             = Guid.NewGuid(),
                CurrentBalance = 200
            };

            using (var ctx = _dbContextCreator.CreateDbContext())
            {
                ctx.Add(customer);
                await ctx.SaveChangesAsync();
            }

            var dto = new TopUpCustomerBalanceDto()
            {
                CustomerID  = customer.ID,
                TopUpAmount = 100
            };

            // Act
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Put, Url + customer.ID.ToString() + "/CurrentBalance");

            message.Content = new ObjectContent <TopUpCustomerBalanceDto>(dto, new JsonMediaTypeFormatter());
            var response = await _client.SendAsync(message);

            // Assert
            response.EnsureSuccessStatusCode();

            using (var ctx = _dbContextCreator.CreateDbContext())
            {
                var customerInDb = await ctx.Customer.FirstOrDefaultAsync();

                Assert.Equal(customer.CurrentBalance + dto.TopUpAmount, customerInDb.CurrentBalance);
            }
        }
Ejemplo n.º 4
0
        public async Task WhenCreateStaffAsync_ThenStaffCreated()
        {
            // Arrange
            var staff = new Staff()
            {
                ID         = Guid.NewGuid(),
                Email      = "*****@*****.**",
                Surname    = "Test",
                GivenNames = "Person"
            };

            // Act
            var result = await _repo.CreateStaffAsync(staff);

            // Assert
            result.Should().BeEquivalentTo(staff);
            using (var ctx = _dbContextCreator.CreateDbContext())
            {
                var staffInDb = await ctx.Staff.FirstOrDefaultAsync();

                staffInDb.Should().BeEquivalentTo(staff);
            }
        }
Ejemplo n.º 5
0
        public async Task WhenCreateCustomerAsync_ThenCustomerCreated()
        {
            // Arrange
            var customer = new Customer()
            {
                ID             = Guid.NewGuid(),
                CurrentBalance = 200,
                Email          = "*****@*****.**",
                Surname        = "Test",
                GivenNames     = "Person"
            };

            // Act
            var result = await _repo.CreateCustomerAsync(customer);

            // Assert
            result.Should().BeEquivalentTo(customer);
            using (var ctx = _dbContextCreator.CreateDbContext())
            {
                var customerInDb = await ctx.Customer.FirstOrDefaultAsync();

                customerInDb.Should().BeEquivalentTo(customer);
            }
        }
Ejemplo n.º 6
0
 public InMemoryPaymentRepositoryTests()
 {
     _dbContextCreator = new DbContextCreator();
     _repo             = new InMemoryPaymentRepository(_dbContextCreator.CreateDbContext());
 }
Ejemplo n.º 7
0
 public InMemoryCustomerRepositoryTests()
 {
     _dbContextCreator = new DbContextCreator();
     _repo             = new InMemoryCustomerRepository(_dbContextCreator.CreateDbContext());
 }