public override IEnumerable<Customer> Read() { var rows = DBConnection.ExecuteQuery("SELECT Company, Name, Cvr, Email FROM Customer"); var customers = new List<Customer>(); //Goes through a foreach loop to add all the customers to a list to be read foreach(var row in rows) { Customer c = new Customer { CompanyName = row.ElementAt(0).ToString(), Name = row.ElementAt(1).ToString(), Cvr = row.ElementAt(2).ToString(), EmailAddress = row.ElementAt(3).ToString() }; customers.Add(c); } return customers; }
public void TestDeleteCustomer() { string sql = ""; var customer = new Customer { CompanyName = "merch", Name = "Sarah", Cvr = "12345678", EmailAddress = "*****@*****.**" }; var mock = new Mock<DatabaseConnection>(); var crud = new SqliteCustomerCrud(mock.Object); //Execute query calls back the string sql containing the string from SqliteCustomerCrud mock.Setup(x => x.ExecuteQuery(It.IsAny<string>())).Callback((string s) => sql = s); crud.Delete(customer); //Is used to force the SqliteCustomerCrud to use the Executequery (DBConnection.ExecuteQuery) mock.Verify(x => x.ExecuteQuery(It.IsAny<string>())); Assert.AreEqual("DELETE FROM Customer WHERE Cvr=" + customer.Cvr + "", sql); }
public void TestCreateToSql() { string sql = ""; var person = new Customer { CompanyName = "Merch", Name = "Jens", Cvr = "12345678", EmailAddress = "*****@*****.**" }; var mock = new Mock<DatabaseConnection>(); var crud = new SqliteCustomerCrud(mock.Object); //Execute query calls back the string sql containing the string from SqliteCustomerCrud mock.Setup(x => x.ExecuteQuery(It.IsAny<string>())).Callback((string s) => sql = s); crud.Create(person); //Is used to force the SqliteCustomerCrud to use the Executequery (DBConnection.ExecuteQuery) //Can be used to verify other things when its used for employee mock.Verify(x => x.ExecuteQuery(It.IsAny<string>())); Assert.AreEqual("INSERT INTO Customer (Company, Name, Cvr, EmailAddress) VALUES (Merch, Jens, 12345678, [email protected])", sql); }
public override void Update(Customer entry) { //Updates a customer based on the Cvr given when the method is called DBConnection.ExecuteQuery($"UPDATE Customer SET Company={entry.CompanyName}, Name={entry.Name}, Email={entry.EmailAddress} WHERE Cvr={entry.Cvr}"); }
public override void Delete(Customer entry) { //Deletes a customer based on the Cvr given when the method is called DBConnection.ExecuteQuery($"DELETE FROM Customer WHERE Cvr='{entry.Cvr}'"); }
public override void Create(Customer entry) { //Create a new customer where the primary key is NOT Autoincrementet DBConnection.ExecuteQuery($"INSERT INTO Customer (Company, Name, Cvr, Email) VALUES ('{entry.CompanyName}', '{entry.Name}', '{entry.Cvr}', '{entry.EmailAddress}')"); }