public void Test2_Equal_ReturnsTrueIfNameAreTheSame() { Stylist firstStylist = new Stylist("Bobby"); Stylist secondStylist = new Stylist("Bobby"); Assert.Equal(firstStylist, secondStylist); }
public static Stylist Find(int id) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM stylists WHERE id = @StylistId;", conn); SqlParameter stylistIdParameter = new SqlParameter(); stylistIdParameter.ParameterName = "@StylistId"; stylistIdParameter.Value = id.ToString(); cmd.Parameters.Add(stylistIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); int foundStylistId = 0; string foundStylistName = null; while(rdr.Read()) { foundStylistId = rdr.GetInt32(0); foundStylistName = rdr.GetString(1); } Stylist foundStylist = new Stylist(foundStylistName, foundStylistId); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return foundStylist; }
public void Test5_Find_NewStylistInDatabase() { Stylist testStylist = new Stylist ("Maggy"); testStylist.Save(); Stylist foundStylist = Stylist.Find(testStylist.GetId()); Assert.Equal(testStylist, foundStylist); }
public void Test_Save_Find_FoundItemEqualsItem() { //Arrange/Act Stylist item = new Stylist("Sherri", "M-W-F", "Clients love her."); item.Save(); //Assert Assert.Equal(Stylist.Find(item.id), item); }
public void Test3_SavesToDatabase() { Stylist testStylist = new Stylist("Jimmy"); testStylist.Save(); List<Stylist> result = Stylist.GetAll(); List<Stylist> testList = new List<Stylist>{testStylist}; Assert.Equal(testList, result); }
public void Test_Delete() { //Arrange/Act Stylist item = new Stylist("Sherri", "M-W-F", "Clients love her."); item.Save(); item.Delete(); //Assert Assert.Equal(Stylist.Find(item.id), null); }
public void Test_Save_CanRetrieveOneItem() { //Arrange/Act Stylist item = new Stylist("Sherri", "M-W-F", "Clients love her."); item.Save(); List<Stylist> allStylists = Stylist.GetAll(); //Assert Assert.Equal(1, allStylists.Count); }
public void Test4_Save_AssignIdToObject() { Stylist testStylist = new Stylist("Anthony"); testStylist.Save(); Stylist savedStylist = Stylist.GetAll()[0]; int result = savedStylist.GetId(); int testId = testStylist.GetId(); Assert.Equal(testId, result); }
public void Test6_Update_StylistToDatabase() { string name = "Maggy"; Stylist testStylist = new Stylist(name); testStylist.Save(); string newName = "Steve"; testStylist.Update(newName); string result = testStylist.GetName(); Assert.Equal(newName, result); }
public void Test_GetClients() { //Arrange Stylist item = new Stylist("Sherri", "M-W-F", "Clients love her."); item.Save(); Client a = new Client("Janet", item.id, "She's a handful."); a.Save(); //Act List<Client> clients = item.GetClients(); //Assert Assert.Equal(clients[0], a); }
public void Test_Update() { //Arrange/Act Stylist item = new Stylist("Sherri", "M-W-F", "Clients love her."); item.Save(); item.Update(new List<string>{"name"}, new List<object>{"Sherry"}); //Assert Assert.Equal(Stylist.Find(item.id).name, "Sherry"); }
public void Test_DatabaseEmptyAtFirst() { int result = Stylist.GetAll().Count; Assert.Equal(0, result); }
public void Dispose() { Stylist.DeleteAll(); }
public HomeModule() { Get["/"] = _ => { return(View["index.cshtml"]); }; //CREATE Get["/client/new"] = _ => { List <Stylist> AllStylists = Stylist.GetAll(); return(View["add_client.cshtml", AllStylists]); }; Get["/stylist/new"] = _ => { return(View["add_stylist.cshtml"]); }; Post["/clients"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); Client newClient = new Client(Request.Form["client-name"], Request.Form["client-phone"], Request.Form["client-email"], Request.Form["stylist"]); var selectedStylist = Stylist.Find(newClient.GetStylistId()); newClient.Save(); model.Add("stylist", selectedStylist); model.Add("client", newClient); return(View["success.cshtml", model]); }; Post["/stylists"] = _ => { Dictionary <string, object> model = new Dictionary <string, object>(); Stylist newStylist = new Stylist(Request.Form["stylist-name"], Request.Form["stylist-phone"], Request.Form["stylist-email"]); var selectedStylist = Stylist.Find(newStylist.GetId()); newStylist.Save(); model.Add("stylist", newStylist); return(View["success.cshtml", newStylist]); }; //READ Get["/clients"] = _ => { List <Client> AllClients = Client.GetAll(); return(View["clients.cshtml", AllClients]); }; Get["/stylists"] = _ => { List <Stylist> AllStylist = Stylist.GetAll(); return(View["stylists.cshtml", AllStylist]); }; Get["/clients/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); var selectedClient = Client.Find(parameters.id); var selectedStylist = Stylist.Find(selectedClient.GetStylistId()); model.Add("stylist", selectedStylist); model.Add("client", selectedClient); return(View["client.cshtml", model]); }; Get["/stylists/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); var selectedStylist = Stylist.Find(parameters.id); var ClientsStylist = selectedStylist.GetClients(); model.Add("stylist", selectedStylist); model.Add("clients", ClientsStylist); return(View["stylist.cshtml", model]); }; //UPDATE Get["/client/edit/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object> { }; Client SelectedClient = Client.Find(parameters.id); List <Stylist> AllStylists = Stylist.GetAll(); model.Add("client", SelectedClient); model.Add("stylists", Stylist.GetAll()); return(View["edit_client.cshtml", model]); }; Get["/stylist/edit/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); return(View["edit_stylist.cshtml", SelectedStylist]); }; Patch["/client/edit/{id}"] = parameters => { Client SelectedClient = Client.Find(parameters.id); var selectedStylist = Stylist.Find(SelectedClient.GetStylistId()); SelectedClient.Update(Request.Form["client-name"], Request.Form["client-phone"], Request.Form["client-email"], Request.Form["stylist-id"]); return(View["success.cshtml"]); }; Patch["/stylist/edit/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); SelectedStylist.Update(Request.Form["stylist-name"], Request.Form["stylist-phone"], Request.Form["stylist-email"]); return(View["success.cshtml"]); }; //DESTROY Get["client/delete/{id}"] = parameters => { Client SelectedClient = Client.Find(parameters.id); return(View["delete_client.cshtml", SelectedClient]); }; Get["stylist/delete/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); return(View["delete_stylist.cshtml", SelectedStylist]); }; Delete["client/delete/{id}"] = parameters => { Client SelectedClient = Client.Find(parameters.id); SelectedClient.Delete(); return(View["success.cshtml"]); }; Delete["stylist/delete/{id}"] = parameters => { Stylist SelectedStylist = Stylist.Find(parameters.id); SelectedStylist.Delete(); return(View["success.cshtml"]); }; Post["/clients/cleared"] = _ => { Client.DeleteAll(); return(View["cleared.cshtml"]); }; Post["/stylists/cleared"] = _ => { Client.DeleteAll(); Stylist.DeleteAll(); return(View["cleared.cshtml"]); }; }
public static List<Stylist> GetAll() { List<Stylist> allStylists = new List<Stylist>{}; SqlConnection conn = DB.Connection(); conn.Open(); //using parameters: creating sql command SqlCommand cmd = new SqlCommand("SELECT * FROM stylists;", conn); // no placeholder in the above command : place holder example is @stylists SqlDataReader rdr = cmd.ExecuteReader(); while(rdr.Read()) { int stylistId = rdr.GetInt32(0); string stylistName = rdr.GetString(1); Stylist newStylist = new Stylist(stylistName, stylistId); allStylists.Add(newStylist); } if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return allStylists; }
public HomeModule() { Get["/"] = _ => { List <Stylist> AllLists = Stylist.GetAll(); return(View["index.cshtml"]); }; Get["/stylists"] = _ => { var AllStylists = Stylist.GetAll(); return(View["stylists.cshtml", AllStylists]); }; Get["/clients"] = _ => { var AllClients = Client.GetAll(); return(View ["clients.cshtml", AllClients]); }; Get["/stylists/new"] = _ => { return(View["stylists_form.cshtml"]); }; Post["/stylists/new"] = _ => { Stylist newStylist = new Stylist(Request.Form["name"], Request.Form["availability"]); newStylist.Save(); List <Stylist> allStylists = Stylist.GetAll(); return(View["success.cshtml"]); }; Get["/client/new"] = _ => { List <Stylist> AllStylists = Stylist.GetAll(); return(View["clients_form.cshtml", AllStylists]); }; Post["/clients/new"] = _ => { Client newClient = new Client(Request.Form["client-name"], Request.Form["stylist"]); newClient.Save(); return(View["success.cshtml"]); }; Post["/clients/delete"] = _ => { Client.DeleteAll(); return(View["cleared.cshtml"]); }; Get["/stylists/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); var selectedStylist = Stylist.Find(parameters.id); var stylistClientsList = selectedStylist.GetClients(); model.Add("stylist", selectedStylist); model.Add("clients", stylistClientsList); 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.UpdateName(Request.Form["stylist-name"]); return(View["success.cshtml"]); }; Get["/client/edit/{id}"] = parameters => { Client selectedClient = Client.Find(parameters.id); return(View["client_edit.cshtml", selectedClient]); }; Patch["/client/edit/{id}"] = parameters => { Client selectedClient = Client.Find(parameters.id); selectedClient.UpdateName(Request.Form["client-name"]); 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"]); }; Get["/client/delete/{id}"] = parameters => { Client selectedClient = Client.Find(parameters.id); return(View["/client_delete.cshtml", selectedClient]); }; Delete["/client/delete/{id}"] = parameters => { Client selectedClient = Client.Find(parameters.id); selectedClient.Delete(); return(View["success.cshtml"]); }; }
public HomeModule() { Get["/"] = _ => { List <Stylist> AllStylists = Stylist.GetAll(); return(View["index.cshtml", AllStylists]); }; Get["/clients"] = _ => { List <Client> AllClients = Client.GetAll(); return(View["clients.cshtml", AllClients]); }; Get["/stylists"] = _ => { List <Stylist> AllStylists = Stylist.GetAll(); return(View["stylists.cshtml", AllStylists]); }; Get["/stylists/new"] = _ => { return(View["stylists_form.cshtml"]); }; Post["/stylists/new"] = _ => { Stylist newStylist = new Stylist(Request.Form["stylist-name"]); newStylist.Save(); return(View["success.cshtml"]); }; Post["/stylists/delete"] = _ => { Stylist.DeleteAll(); return(View["delete_all.cshtml"]); }; Get["/clients/new"] = _ => { List <Stylist> AllStylists = Stylist.GetAll(); return(View["clients_form.cshtml", AllStylists]); }; Post["/clients/new"] = _ => { Client newClient = new Client(Request.Form["client-name"], Request.Form["stylist-id"]); newClient.Save(); return(View["success.cshtml"]); }; // Post["/clients/delete"] = _ => { // Client.DeleteAll(); // return View["delete_all.cshtml"]; // }; Get["/stylists/{id}"] = parameters => { Dictionary <string, object> model = new Dictionary <string, object>(); var SelectedStylist = Stylist.Find(parameters.id); var StylistClients = SelectedStylist.GetClients(); 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"]); }; 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["delete_all.cshtml"]); }; }
public void Dispose() { Client.DeleteAll(); Stylist.DeleteAll(); }
public static Stylist Find(int findId) { DBObjects dbo = DBObjects.CreateCommand("SELECT * FROM stylists WHERE id=@Id;", new List<string> {"@Id"}, new List<object> {findId}); SqlDataReader rdr = dbo.RDR; rdr = dbo.CMD.ExecuteReader(); Stylist result = null; while(rdr.Read()) { result = new Stylist(rdr.GetString(1), rdr.GetString(2), rdr.GetString(3), rdr.GetInt32(0)); } dbo.Close(); return result; }
public void GetAll_StylistsEmptyAtFirst_0() { int result = Stylist.GetAll().Count; Assert.Equal(0, result); }
public HomeModule() { Get["/"] = _ => { List<Stylist> stylists = Stylist.GetAll(); return View["index.cshtml", stylists]; }; Post["/stylists/new"] = _ => { Stylist newStylist = new Stylist(Request.Form["name"], Request.Form["avail"], Request.Form["notes"]); newStylist.Save(); List<Stylist> stylists = Stylist.GetAll(); return View["index.cshtml", stylists]; }; Get["/stylists/{id}"] = parameter => { Stylist foundStylist = Stylist.Find(parameter.id); return View["stylist.cshtml", foundStylist]; }; Patch["/stylists/edit/{id}"] = parameter => { Stylist editedStylist = Stylist.Find(parameter.id); List<string> updateColumns = new List<string> {"name", "availability", "notes"}; string newStylistId = (string)Request.Form["avail"]; string newName = (string)Request.Form["name"]; string newNotes = (string)Request.Form["notes"]; List<object> updateValues = new List<object> {newName, newStylistId, newNotes}; editedStylist.Update(updateColumns, updateValues); return View["stylist.cshtml", editedStylist]; }; Delete["/stylists/delete/{id}"] = parameter => { Stylist deletedStylist = Stylist.Find(parameter.id); deletedStylist.Delete(); List<Stylist> stylists = Stylist.GetAll(); return View["index.cshtml", stylists]; }; Post["/clients/new"] = _ => { string newName = (string)Request.Form["name"]; int stylistId = (int)Request.Form["stylist_id"]; string newNotes = (string)Request.Form["notes"]; Client newClient = new Client(newName, stylistId, newNotes); newClient.Save(); Stylist foundStylist = Stylist.Find(stylistId); return View["stylist.cshtml", foundStylist]; }; Get["/clients/{id}"] = parameter => { Client foundClient = Client.Find(parameter.id); List<object> model = new List<object> {}; model.Add(foundClient); model.Add(Stylist.GetAll()); return View["client.cshtml", model]; }; Patch["/clients/edit/{id}"] = parameter => { Client editedClient = Client.Find(parameter.id); List<string> updateColumns = new List<string> {"name", "stylist_id", "notes"}; int newStylistId = (int)Request.Form["stylist_id"]; string newName = (string)Request.Form["name"]; string newNotes = (string)Request.Form["notes"]; List<object> updateValues = new List<object> {newName, newStylistId, newNotes}; editedClient.Update(updateColumns, updateValues); List<object> model = new List<object> {}; model.Add(editedClient); model.Add(Stylist.GetAll()); return View["client.cshtml", model]; }; Delete["/clients/delete/{id}"] = parameter => { Client deletedClient = Client.Find(parameter.id); deletedClient.Delete(); Stylist foundStylist = Stylist.Find(deletedClient.stylist_id); return View["stylist.cshtml", foundStylist]; }; }
public Homemodule() { Get["/"] = _ => { List<Stylist> AllStylists = Stylist.GetAll(); return View["index.cshtml", AllStylists]; }; Get["/clients"] = _ => { List<Client> AllClients = Client.GetAll(); return View["clients.cshtml", AllClients]; }; Get["/stylists"] = _ => { List<Stylist> AllStylists = Stylist.GetAll(); return View["stylists.cshtml", AllStylists]; }; Get["/stylists/new"] = _ => { return View["stylists_form.cshtml"]; }; Post["/stylists/new"] = _ => { Stylist newStylist = new Stylist(Request.Form["stylist-name"]); newStylist.Save(); return View["success.cshtml"]; }; Get["/clients/new"] = _ => { List<Stylist> AllStylists = Stylist.GetAll(); return View["clients_form.cshtml", AllStylists]; }; Post["/clients/new"] = _ => { Client newClient = new Client(Request.Form["client-name"], Request.Form["stylist-id"]); newClient.Save(); return View["success.cshtml"]; }; Post["/clients/delete"] = _ => { Client.DeleteAll(); return View["cleared.cshtml"]; }; Get["/stylists/{id}"] = parameters => { Dictionary<string, object> model = new Dictionary<string, object>(); var SelectedStylist = Stylist.Find(parameters.id); var StylistClients = SelectedStylist.GetClients(); 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"]; }; 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 Test1_EmptyDatabase() { int result = Stylist.GetAll().Count; Assert.Equal(0, result); }