public void Test2_Return_ClientObjectsOverride() { Client firstClient = new Client("dsds",13); Client secondClient = new Client("dsds",13); Assert.Equal(firstClient, secondClient); }
public static Client Find(int Id) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM clients WHERE id = @clientId;", conn); SqlParameter ClientParameter = new SqlParameter(); ClientParameter.ParameterName = "@clientId"; ClientParameter.Value = Id; cmd.Parameters.Add(ClientParameter); SqlDataReader rdr = cmd.ExecuteReader(); string foundName=null; int foundStylistId=0; int foundId=0; while(rdr.Read()) { foundId=rdr.GetInt32(0); foundName=rdr.GetString(1); foundStylistId=rdr.GetInt32(2); } Client foundClient= new Client(foundName, foundStylistId, foundId); if (rdr!= null) { rdr.Close(); } if (conn != null) { conn.Close(); } return foundClient; }
public static Client Find(int id) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM clients WHERE id = @ClientId;", conn); SqlParameter clientIdParameter = new SqlParameter(); clientIdParameter.ParameterName = "@ClientId"; clientIdParameter.Value = id.ToString(); cmd.Parameters.Add(clientIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); int foundClientId = 0; string foundClientName = null; string foundClientTreatment = null; while(rdr.Read()) { foundClientId = rdr.GetInt32(0); foundClientName = rdr.GetString(1); foundClientTreatment = rdr.GetString(1); } Client foundClient = new Client(foundClientName, foundClientTreatment, foundClientId); if(rdr!=null) { rdr.Close(); } if(conn!=null) { conn.Close(); } return foundClient; }
public void Test_NamesAreEqual_ReturnsTrueIfNamesAreTheSame() { // Arrange, Act Client firstClient = new Client("Doc Gonzo", "Brush", 1); Client secondClient = new Client("Doc Gonzo", "Brush", 1); //Assert Assert.Equal(firstClient, secondClient); }
public void Test4_Save_AssignsIdToObjects() { Client firstClient = new Client("erere", 13); firstClient.Save(); Client savedClient = Client.GetAll()[0]; Assert.Equal(firstClient, savedClient); }
public void Test6_Update_ClientInDatabase() { Client oneClient = new Client("erere", 13); oneClient.Save(); oneClient.Update("q"); string result = oneClient.GetName(); Assert.Equal("q", result); }
public void Test3_Save_ClientsToObjects() { List<Client> saveOneClient = new List<Client>{}; Client firstClient = new Client("erere", 13); saveOneClient.Add(firstClient); firstClient.Save(); List<Client> allClients=Client.GetAll(); Assert.Equal(saveOneClient,allClients); }
public void FindById_FindsAClientById_ClientFoundById() { // Arrange Client testClient = new Client("Doc Gonzo", "Brush", 1); testClient.Save(); // Act Client foundClient = Client.Find(testClient.GetId()); // Assert Assert.Equal(testClient, foundClient); }
public HomeModule() { Get["/"] = _ => { var allStylists = Stylist.GetAll(); return View["index.cshtml", allStylists]; }; Post["/"] = _ => { var newStylist = new Stylist(Request.Form["stylist-name"], Request.Form["stylist-specialty"]); newStylist.Save(); var allStylists = Stylist.GetAll(); return View["index.cshtml", allStylists]; }; Get["/stylists/{id}"] = parameters => { Dictionary<string, object> model = new Dictionary<string, object>(); var selectedStylist = Stylist.Find(parameters.id); var stylistClients = selectedStylist.GetClients(parameters.id); model.Add("stylist", selectedStylist); model.Add("clients", stylistClients); return View["stylist.cshtml", model]; }; Get["/stylist/edit/{id}"] = parameters => { Stylist selectedStylist = Stylist.Find(parameters.id); return View["stylist_edit.cshtml", selectedStylist]; }; Patch["stylist/edit/{id}"] = parameters => { Stylist selectedStylist = Stylist.Find(parameters.id); selectedStylist.Update(Request.Form["stylist-name"]); return View["success.cshtml"]; }; Post["/stylist/new"] = _ => { Client newClient = new Client(Request.Form["client-name"], Request.Form["client-treatment"], Request.Form["stylist-id"]); newClient.Save(); return View["success.cshtml"]; }; Get["stylist/delete/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); return View["stylist_delete.cshtml", SelectedStylist]; }; Delete["stylist/delete/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); SelectedStylist.Delete(); return View["success.cshtml"]; }; }
public void Test5_Find_FindsClientInDatabase() { //Arrange Client oneClient = new Client("erere", 13); oneClient.Save(); //Act Client foundClient = Client.Find(oneClient.GetId()); //Assert Assert.Equal(oneClient, foundClient); }
public void Test_Save_AssignsIdToObject() { // Arrange Client testClient = new Client("Doc Gonzo", "Haircut", 1); // Act testClient.Save(); Client savedClient = Client.GetAll()[0]; int result = savedClient.GetId(); int testId = testClient.GetId(); // Assert Assert.Equal(testId, result); }
public void Test5_GetAllClient_esInStylist_true() { Stylist myStylist = new Stylist("lo-main"); myStylist.Save(); Client firstClient = new Client("Pizza",myStylist.GetId()); firstClient.Save(); Client secondClient = new Client("tacos",myStylist.GetId()); secondClient.Save(); List<Client> testClientList = new List<Client> {firstClient,secondClient}; List<Client> resultClientList = myStylist.GetClient(); Assert.Equal(testClientList, resultClientList); }
public void Test_Delete_DeletesClientFromDatabase() { // Arrange string name = "Yousef"; Client testClient = new Client(name, "Cuts", 1); testClient.Save(); string name2 = "John"; Client testClient2 = new Client(name, "Brushes", 1); testClient2.Save(); // Act testClient.Delete(); List<Client> resultClients = Client.GetAll(); List<Client> testClientList = new List<Client> {testClient2}; // Assert Assert.Equal(testClientList, resultClients); }
public void Test_Delete_DeletesStylistFromDatabase() { // Arrange string name = "Doctor Gonzo"; Stylist testStylist = new Stylist(name, "Cuts"); testStylist.Save(); string name2 = "Mouse"; Stylist testStylist2 = new Stylist(name2, "Brushes"); testStylist2.Save(); Client testClient = new Client("Sid", "Cut", testStylist.GetId()); testClient.Save(); Client testClient2 = new Client("Yousef", "Color", testStylist2.GetId()); testClient2.Save(); // Act testStylist.Delete(); List<Stylist> resultStylists = Stylist.GetAll(); List<Stylist> testStylistList = new List<Stylist> {testStylist2}; List<Client> resultClients = Client.GetAll(); List<Client> testClientList = new List<Client> {testClient2}; // Assert Assert.Equal(testStylistList, resultStylists); Assert.Equal(testClientList, resultClients); }
public void Test7_DeleteOneClient_true() { Client firstClientsClient = new Client("erere",87); firstClientsClient.Save(); Client secondClientsDsih= new Client("erere",56); secondClientsDsih.Save(); firstClientsClient.Delete(); List<Client> resultClient=Client.GetAll(); List<Client> afterDeleteOneClientsClient= new List<Client> {secondClientsDsih}; Assert.Equal(afterDeleteOneClientsClient,resultClient); }
public void Dispose() { Stylist.DeleteAll(); Client.DeleteAll(); }
public List<Client> GetClient() { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM clients WHERE stylist_id = @StylistId;", conn); SqlParameter stylistIdParameter = new SqlParameter(); stylistIdParameter.ParameterName = "@StylistId"; stylistIdParameter.Value = this.GetId(); cmd.Parameters.Add(stylistIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); List<Client> allClientes = new List<Client> {}; while(rdr.Read()) { int dishId = rdr.GetInt32(0); string dishName = rdr.GetString(1); int dishStylistId = rdr.GetInt32(2); Client newClient = new Client(dishName,dishStylistId,dishId); allClientes.Add(newClient); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return allClientes; }
public void Update_UpdatesAClient_ClientUpdated() { // Arrange string name1 = "Doc Gonzo"; string service1 = "Fur"; Client testClient1 = new Client(name1, service1, 1); testClient1.Save(); string name2 = "Doctor Gonzo"; string nameExpected = name2; // Act testClient1.Update(name2); string nameResult = testClient1.GetName(); // Assert Assert.Equal(nameExpected, nameResult); }
public void Test7_Delete_OneStylist_true() { Stylist firstStylist = new Stylist("A"); firstStylist.Save(); Stylist secondStylist = new Stylist("B"); secondStylist.Save(); Client firstStylistClient = new Client("sddsds",firstStylist.GetId()); firstStylistClient.Save(); Client secondStylistDsih= new Client("dssdsdds",secondStylist.GetId()); secondStylistDsih.Save(); firstStylist.Delete(); List<Stylist> allStylists = Stylist.GetAll(); List<Stylist> afterDeleteOneStylist= new List<Stylist> {secondStylist}; List<Client> resultClient=Client.GetAll(); List<Client> afterDeleteOneStylistClient= new List<Client> {secondStylistDsih}; Assert.Equal(afterDeleteOneStylist,allStylists); Assert.Equal(afterDeleteOneStylistClient,resultClient); }
// a method to get a stylist's list of clients public List<Client> GetClients(int id) { List<Client> allClients = new List<Client>{}; SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM clients WHERE stylist_id = @StylistId;", conn); SqlParameter stylistIdParameter = new SqlParameter(); stylistIdParameter.ParameterName = "@StylistId"; stylistIdParameter.Value = id.ToString(); cmd.Parameters.Add(stylistIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); int foundClientId = 0; string foundClientName = null; string foundClientTreatment = null; while(rdr.Read()) { foundClientId = rdr.GetInt32(0); foundClientName = rdr.GetString(1); foundClientTreatment = rdr.GetString(2); Client foundClient = new Client(foundClientName, foundClientTreatment, foundClientId); allClients.Add(foundClient); } if(rdr!=null) { rdr.Close(); } if(conn!=null) { conn.Close(); } return allClients; }
public HomeModule() { Get["/"] = _ => { Dictionary<string,object> model=Member.AllData("Welcome To Our Salon!"); return View["index.cshtml",model]; }; Post["/stylist/new"] =_ => { Stylist newStylist = new Stylist(Request.Form["new-name"]); newStylist.Save(); string message="Thank you for join us "+Request.Form["new-name"]; Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Post["/client/new"] =_ => { Client newClient = new Client(Request.Form["new-name"],Request.Form["stylist-id"]); newClient.Save(); string message="We appreciated your bussiness. "+Request.Form["new-name"]; Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Delete["/delete/stylist/{id}"]=parameters =>{ Stylist foundStylist = Stylist.Find(parameters.id); string message="You Suscessfully Delete "+foundStylist.GetName(); foundStylist.Delete(); Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Patch["/edit/stylist/{id}"]=parameters =>{ Stylist foundStylist = Stylist.Find(parameters.id); string message="You Suscessfully Change Name from"+ foundStylist.GetName()+" to "+ Request.Form["edit-stylist-name"]; foundStylist.Update(Request.Form["edit-stylist-name"]); Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Delete["/delete/client/{id}"]=parameters =>{ Client foundClient = Client.Find(parameters.id); string message="You Suscessfully Delete "+foundClient.GetName(); foundClient.Delete(); Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Patch["/edit/client/{id}"]=parameters =>{ Client foundClient = Client.Find(parameters.id); string message="You Suscessfully Change Name from"+ foundClient.GetName()+" to "+ Request.Form["edit-client-name"]; foundClient.Update(Request.Form["edit-client-name"]); Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; Get["/Client/{id}"]=parameters =>{ Stylist foundStylist = Stylist.Find(parameters.id); List<Client> allMyClients=foundStylist.GetClient(); Dictionary<string,object> model= new Dictionary<string,object>{}; model.Add("stylist",foundStylist); model.Add("client",allMyClients); return View["client.cshtml",model]; }; Get["/delete-all"]=_=>{ return View["confirmation.cshtml"]; }; Post["/delete/confirmation"]=_=>{ string message=" You enter wrong password, and thus you cannont delete anything."; if(Request.Form["confirm-delete"]=="delete-all-clients"&&Request.Form["user-password"]=="123") { Client.DeleteAll(); message=Request.Form["userName"]+", You deleted all client data"; }else if(Request.Form["confirm-delete"]=="delete-all"&&Request.Form["user-password"]=="123") { message=Request.Form["userName"]+", You deleted all data"; Client.DeleteAll(); Stylist.DeleteAll(); } Dictionary<string,object> model=Member.AllData(message); return View["allpeople.cshtml",model]; }; }
public static List<Client> GetAll() { List<Client> allClients = new List<Client>{}; SqlConnection conn =DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM clients",conn); SqlDataReader rdr = cmd.ExecuteReader(); int id=0; string name= null; int stylistId=0; while(rdr.Read()) { id=rdr.GetInt32(0); name= rdr.GetString(1); stylistId=rdr.GetInt32(2); Client newClient= new Client(name,stylistId,id); allClients.Add(newClient); } if(rdr !=null) { rdr.Close(); } if(conn !=null) { conn.Close(); } return allClients; }
public void Test_Save_SavesToDatabase() { // Arrange Client testClient = new Client("Doc Gonzo", "Brush", 1); testClient.Save(); // Act List<Client> listResult = Client.GetAll(); List<Client> listExpected = new List<Client>{testClient}; // Assert Assert.Equal(listExpected, listResult); }