public void Create(Customer newCustomer, IDbConnection connection)
        {
            const string sql = @"
                INSERT INTO Customers (CustomerID, CompanyName, ContactName)
                    VALUES (@customerID, @companyName, @contactName)";

            connection.Execute(sql, new
                {
                    customerId = newCustomer.CustomerId,
                    companyName = newCustomer.CompanyName,
                    contactName = newCustomer.ContactName
                });
        }
        public void Create_ShouldUpdateTableWithCustomerData()
        {
            const string customerId = "SKN";
            var expectedCustomer = new Customer(
                customerId,
                "SkyNet",
                "T-800"
                );

            _customersDataAdapter.Create(expectedCustomer, SqlConnection);

            var actualCustomer = _customersDataAdapter.Get(customerId, SqlConnection);
            Assert.AreEqual(expectedCustomer.CustomerId, actualCustomer.CustomerId);
            Assert.AreEqual(expectedCustomer.CompanyName, actualCustomer.CompanyName);
            Assert.AreEqual(expectedCustomer.ContactName, actualCustomer.ContactName);
        }
        public void Update(string customerId, Customer updatedCustomer, IDbConnection connection)
        {
            const string sql = @"
                UPDATE Customers 
                    SET CompanyName = @companyName, 
                        ContactName = @contactName
                WHERE CustomerId = @customerId";

            connection.Execute(sql, new
            {
// ReSharper disable RedundantAnonymousTypePropertyName
                customerId = customerId,
// ReSharper restore RedundantAnonymousTypePropertyName
                companyName = updatedCustomer.CompanyName,
                contactName = updatedCustomer.ContactName
            });
        }
        public void Delete_WithValidCustomerId_ShouldRemoveCustomerFromDatabase()
        {
            const string customerId = "SKN";
            var customer = new Customer(
                customerId,
                "SkyNet",
                "T-800"
                );

            _customersDataAdapter.Create(customer, SqlConnection);

            // Act
            _customersDataAdapter.Delete(customerId, SqlConnection);

            var actualCustomer = _customersDataAdapter.Get(customerId, SqlConnection);
            Assert.IsNull(actualCustomer);
        }
        public void Update_WithExistingCustomer_ShouldUpdateCustomerInDatabase()
        {
            const string customerId = "SKN";
            var originalCustomer = new Customer(
                customerId,
                "SkyNet",
                "T-800"
                );

            _customersDataAdapter.Create(originalCustomer, SqlConnection);

            // Act
            var updatedCustomer = new Customer(
                customerId,
                "TurboProp Inc.",
                "Roger Ramjet");

            _customersDataAdapter.Update(customerId, updatedCustomer, SqlConnection);

            var actualCustomer = _customersDataAdapter.Get(customerId, SqlConnection);
            Assert.AreEqual(updatedCustomer.CustomerId, actualCustomer.CustomerId);
            Assert.AreEqual(updatedCustomer.CompanyName, actualCustomer.CompanyName);
            Assert.AreEqual(updatedCustomer.CustomerId, actualCustomer.CustomerId);
        }
 private static void CheckExpectedCustomer3(Customer customer)
 {
     Assert.AreEqual(CustomerSeeder.CustomerId3, customer.CustomerId);
     Assert.AreEqual(CustomerSeeder.CustomerName3, customer.CompanyName);
     Assert.AreEqual(CustomerSeeder.ContactName3, customer.ContactName);
 }