public void Test_Equals_ObjectEqualsOverride()
        {
            Client firstClient = new Client("Rebecca", 1);
              Client secondClient = new Client("Rebecca", 1);

              Assert.Equal(firstClient, secondClient);
        }
        public void Test_Delete_DeletesStylistFromDatabase()
        {
            string name1 = "Rebecca";
              Stylist testStylist1 = new Stylist(name1);
              testStylist1.Save();

              string name2 = "Tony";
              Stylist testStylist2 = new Stylist(name2);
              testStylist2.Save();

              Client testClient1 = new Client("Sam", testStylist1.GetId());
              testClient1.Save();
              Client testClient2 = new Client("Beth", testStylist2.GetId());
              testClient2.Save();
              Console.WriteLine(Client.Find(testClient1.GetId()).GetName());
              Console.WriteLine(Client.Find(testClient2.GetId()).GetName());

              testStylist1.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.Equal(testStylistList, resultStylists);
              Assert.Equal(testClientList, resultClients);
        }
        public static Client Find(int id)
        {
            SqlConnection conn = DB.Connection();
              SqlDataReader rdr = null;
              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);
              rdr = cmd.ExecuteReader();

              int foundClientId = 0;
              string foundClientName = null;
              int foundClientStylistId = 0;

              while(rdr.Read())
              {
            foundClientId = rdr.GetInt32(0);
            foundClientName = rdr.GetString(1);
            foundClientStylistId = rdr.GetInt32(2);
              }
              Client foundClient = new Client(foundClientName, foundClientStylistId, foundClientId);

              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return foundClient;
        }
        public void Test_Find_FindsCategoryInDatabase()
        {
            Client testClient = new Client("Rebecca", 1);
              testClient.Save();

              Client foundClient = Client.Find(testClient.GetId());

              Assert.Equal(testClient, foundClient);
        }
        public void Test_Equals_ReturnsTrueIfContentAndRestaurantAreIdentical()
        {
            //Arrange
              Client firstClient = new Client("Wendy", "blonde", 3);
              Client secondClient = new Client("Wendy", "blonde", 3);

              //Assert
              Assert.Equal(firstClient, secondClient);
        }
        public void Test_Save_SavesClientToDatabase()
        {
            Client testClient = new Client("Rebecca", 1);
              testClient.Save();

              List<Client> result = Client.GetAll();
              List<Client> testList = new List<Client>{testClient};

              Assert.Equal(testList, result);
        }
        public void Test_GetAll_RetrievesAllClientsFromDatabase()
        {
            Client firstClient = new Client("Rebecca", 1);
              Client secondClient = new Client("Tony", 1);
              firstClient.Save();
              secondClient.Save();

              List<Client> testList = new List<Client>{firstClient, secondClient};
              List<Client> result = Client.GetAll();

              Assert.Equal(testList, result);
        }
        public void Test_Find_ReturnsASpecificClientObject()
        {
            //Arrange
              Client newClient = new Client("Wendy", "blonde", 3);
              newClient.Save();

              //Act
              Client foundClient = Client.Find(newClient.GetId());

              //Assert
              Assert.Equal(newClient, foundClient);
        }
        public void Test_Delete_DeleteClientFromDatabase()
        {
            string name1 = "Rebecca";
              Client testClient1 = new Client(name1, 0);
              testClient1.Save();
              string name2 = "Tony";
              Client testClient2 = new Client(name2, 0);
              testClient2.Save();

              testClient1.Delete();
              List<Client> result = Client.GetAll();
              List<Client> testClientList = new List<Client>{testClient2};

              Assert.Equal(testClientList, result);
        }
        public void Test_DeleteOne_DeletesASpecificClientObject()
        {
            //Arrange
              Client firstClient = new Client("Wendy", "blonde", 3);
              firstClient.Save();
              Client secondClient = new Client("Jasper", "brunette", 2);
              secondClient.Save();

              //Act
              secondClient.Delete();
              List<Client> expectedClient = new List<Client> {firstClient};
              List<Client> testClient= Client.GetAll();

              //Assert
              Assert.Equal(expectedClient, testClient);
        }
        public void Test_Delete_DeletesStylistAndClientsByStylistId()
        {
            //Arrange
              Stylist firstStylist = new Stylist("Tracy", 17);
              firstStylist.Save();
              Stylist secondStylist = new Stylist("Chad", 10);
              secondStylist.Save();

              Client firstClient = new Client("Jasper", "brunette", firstStylist.GetId());
              firstClient.Save();
              Client secondClient = new Client("Wendy", "blonde", secondStylist.GetId());
              secondClient.Save();

              List<Stylist> expectedStylist = new List<Stylist>{firstStylist};
              List<Client> expectedResult = new List<Client> {firstClient};
              //Act
              secondStylist.Delete();

              List<Stylist> resultingStylist = Stylist.GetAll();
              List<Client> result = Client.GetAll();
              //Assert
              Assert.Equal(expectedStylist, resultingStylist);
              Assert.Equal(expectedResult, result);
        }
        public void Test_GetClients_RetrievesAllClientsWithStylist()
        {
            Stylist testStylist = new Stylist("Rebecca");
              testStylist.Save();

              Client firstClient = new Client("Sam", testStylist.GetId());
              firstClient.Save();
              Client secondClient = new Client("Beth", testStylist.GetId());
              secondClient.Save();

              List<Client> testClientList = new List<Client> {firstClient, secondClient};
              List<Client> resultClientList = testStylist.GetClients();

              Assert.Equal(testClientList, resultClientList);
        }
        public void Test_SetHairColorAndStylistId_AdjustsDatabaseCorrectly()
        {
            // Arrange
              Client firstClient = new Client("Wendy", "blonde", 3);
              firstClient.Save();

              //Act
              firstClient.SetHairColor("brunette");
              firstClient.SetStylistId(2);
              Client resultClient = Client.Find(firstClient.GetId());

              //Assert
              Assert.Equal("brunette", resultClient.GetHairColor());
              Assert.Equal(2, resultClient.GetStylistId());
        }
        public void Test_Save_SavesCorrectObjectToDatabase()
        {
            //Arrange
              Client newClient = new Client("Wendy", "blonde", 3);

              //Act
              newClient.Save();
              Client savedClient = Client.GetAll()[0];

              //Assert
              Assert.Equal(newClient, savedClient);
        }
        public void Test_Update_UpdatesClientInDatabase()
        {
            string name = "Rebecca";
              int stylistId = 1;
              Client testClient = new Client(name, stylistId);
              testClient.Save();
              string newName = "Becky";
              int newStylistId = 2;

              testClient.Update(newName, newStylistId);

              string result = testClient.GetName();

              Assert.Equal(newName, result);
        }
        public List<Client> GetClients()
        {
            SqlConnection conn = DB.Connection();
              SqlDataReader rdr = null;
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM clients WHERE stylistId = @StylistId;", conn);
              SqlParameter cuisineIdParameter = new SqlParameter();
              cuisineIdParameter.ParameterName = "@StylistId";
              cuisineIdParameter.Value = this.GetId();
              cmd.Parameters.Add(cuisineIdParameter);
              rdr = cmd.ExecuteReader();

              List<Client> clients = new List<Client> {};
              while(rdr.Read())
              {
            int clientId = rdr.GetInt32(0);
            string clientName = rdr.GetString(1);
            int clientStylistId = rdr.GetInt32(2);
            Client newClient = new Client(clientName, clientStylistId, clientId);
            clients.Add(newClient);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return clients;
        }
        public void Test_GetClients_FindsClientsByStylistId()
        {
            //Arrange
              Stylist newStylist = new Stylist("Tracy", 18);
              newStylist.Save();

              Client firstClient = new Client("Jasper", "brunette", newStylist.GetId());

              firstClient.Save();
              Client secondClient = new Client("Wendy", "blonde", 2);
              secondClient.Save();
              List<Client> expectedResult = new List<Client> {firstClient};
              //Act
              List<Client> result = newStylist.GetClients();
              //Assert
              Assert.Equal(expectedResult, result);
        }
Пример #18
0
        public static List<Client> GetAll()
        {
            List<Client> allClients = new List<Client>{};

              SqlConnection conn = DB.Connection();
              SqlDataReader rdr = null;
              conn.Open();

              SqlCommand cmd = new SqlCommand("SELECT * FROM clients;", conn);
              rdr = cmd.ExecuteReader();

              while(rdr.Read())
              {
            int clientId = rdr.GetInt32(0);
            string clientName = rdr.GetString(1);
            int clientSylistId = rdr.GetInt32(2);
            Client newClient = new Client(clientName, clientSylistId, clientId);
            allClients.Add(newClient);
              }

              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }

              return allClients;
        }
Пример #19
0
        public List<Client> GetClients()
        {
            List<Client> allClientsMatchingStylist = new List<Client>{};
              SqlConnection conn = DB.Connection();
              SqlDataReader rdr = null;
              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().ToString();

              cmd.Parameters.Add(stylistIdParameter);

              rdr = cmd.ExecuteReader();

              while(rdr.Read())
              {
            int clientId = rdr.GetInt32(0);
            string clientName = rdr.GetString(1);
            string clientHairColor = rdr.GetString(2);
            int clientStylistId = rdr.GetInt32(3);
            Client newClient = new Client(clientName, clientHairColor, clientStylistId, clientId);
            allClientsMatchingStylist.Add(newClient);
              }
              if (rdr != null)
              {
            rdr.Close();
              }
              if (conn != null)
              {
            conn.Close();
              }
              return allClientsMatchingStylist;
        }