public override IEnumerable<Employee> Read() { var rows = DBConnection.ExecuteQuery("SELECT Id, Name, Email FROM Employee"); var employees = new List<Employee>(); //Goes through a foreach loop to add all the employees to the 'employees' list to be read foreach (var row in rows) { Employee e = new Employee { Id = (int)row.ElementAt(0), Name = row.ElementAt(1).ToString(), EmailAddress = row.ElementAt(2).ToString() }; employees.Add(e); } return employees; }
public void TestDeleteEmployee() { string sql = ""; var employee = new Employee {Id = 1, Name = "Jessie", EmailAddress = "*****@*****.**" }; var mock = new Mock<DatabaseConnection>(); var crud = new SqliteEmployeeCrud(mock.Object); //This is used to callback the string whith the information that you send (the Sql statement) mock.Setup(x => x.ExecuteQuery(It.IsAny<string>())).Callback((string s) => sql = s); crud.Delete(employee); //Is used to force the SqliteCustomerCrud to use the Executequery (DBConnection.ExecuteQuery) mock.Verify(x => x.ExecuteQuery(It.IsAny<string>())); //Checks the string that is send whether or not its the same as the one written below Assert.AreEqual("DELETE FROM Employee WHERE Id="+employee.Id+"", sql); }
public void TestCreateToSqlEmployee() { string sql = ""; var person = new Employee { Id = 1, Name = "Jessie", EmailAddress = "*****@*****.**" }; var mock = new Mock<DatabaseConnection>(); var crud = new SqliteEmployeeCrud(mock.Object); //Execute query calls back the string sql containing the string from SqliteEmployeeCrud 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>())); //Checks the string that is send whether or not its the same as the one written below Assert.AreEqual($"INSERT INTO Employee (Id, Name, EmailAddress) VALUES ({person.Id}, {person.Name}, {person.EmailAddress})", sql); }
public override void Update(Employee entry) { //Updates an employee based on the id given when the method is called DBConnection.ExecuteQuery($"UPDATE Employee SET Name={entry.Name}, Email={entry.EmailAddress} WHERE Id={entry.Id}"); }
public override void Delete(Employee entry) { //Deletes a single employee based on the id given when the method is called DBConnection.ExecuteQuery($"DELETE FROM Employee WHERE Id="+entry.Id+""); }
public override void Create(Employee entry) { //Creates a new employee with an Autoincrementet employee id DBConnection.ExecuteQuery($"INSERT INTO Employee (Id, Name, Email) VALUES ({entry.Id}, {entry.Name}, {entry.EmailAddress})"); }
public void TestUpdateEmployee() { string sql = ""; var employee = new Employee { Id = 1, Name = "Jessie", EmailAddress = "*****@*****.**" }; var mock = new Mock<DatabaseConnection>(); var crud = new SqliteEmployeeCrud(mock.Object); //Execute query calls back the string sql containing the string from SqliteEmployeeCrud mock.Setup(x => x.ExecuteQuery(It.IsAny<string>())).Callback((string s) => sql = s); crud.Update(employee); //Is used to force the SqliteCustomerCrud to use the Executequery (DBConnection.ExecuteQuery) mock.Verify(x => x.ExecuteQuery(It.IsAny<string>())); //Checks the string that is send whether or not its the same as the one written below Assert.AreEqual($"UPDATE Employee SET Name={employee.Name}, EmailAddress={employee.EmailAddress} WHERE Id={employee.Id}", sql); }