Ejemplo n.º 1
0
        public async Task CreateCustomerShouldUpdateExistingCustomer()
        {
            var options = new DbContextOptionsBuilder <WHMSDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var context = new WHMSDbContext(options);
            context.Customers.Add(new Customer {
                Email = "*****@*****.**", FirstName = "Pesho", LastName = "Peshov", PhoneNumber = "000000"
            });
            await context.SaveChangesAsync();

            var service = new CustomersService(context);
            var model   = new CustomerViewModel {
                Email = "*****@*****.**", FirstName = "Test", LastName = "Testov", PhoneNumber = "123451234"
            };

            await service.CreateOrUpdateCustomerAsync(model);

            var dbCustomer = context.Customers.FirstOrDefault();

            Assert.NotNull(dbCustomer);
            Assert.Equal("*****@*****.**", dbCustomer.Email);
            Assert.Equal("Test", dbCustomer.FirstName);
            Assert.Equal("Testov", dbCustomer.LastName);
            Assert.Equal("123451234", dbCustomer.PhoneNumber);
        }