Esempio n. 1
0
    public void Test_FindFindsTaskInDatabase()
    {
      //Arrange
      Task testTask = new Task("Mow the lawn");
      testTask.Save();

      //Act
      Task foundTask = Task.Find(testTask.GetId());

      //Assert
      Assert.Equal(testTask, foundTask);
    }
        public void Test_Find_FindsTaskInDatabase()
        {
            //Arrange
              DateTime fakeTime = new DateTime(2016, 1, 1);
              Task testTask = new Task("Mow the lawn", 1, fakeTime);
              testTask.Save();

              //Act
              Task foundTask = Task.Find(testTask.GetId());

              //Assert
              Assert.Equal(testTask, foundTask);
        }
Esempio n. 3
0
 public override bool Equals(System.Object otherTask)
 {
     if (!(otherTask is Task))
     {
         return(false);
     }
     else
     {
         Task newTask             = (Task)otherTask;
         bool idEquality          = this.GetId() == newTask.GetId();
         bool descriptionEquality = this.GetDescription() == newTask.GetDescription();
         bool categoryEquality    = this.GetCategoryId() == newTask.GetCategoryId();
         return(idEquality && descriptionEquality && categoryEquality);
     }
 }
Esempio n. 4
0
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange
            Task testTask = new Task("Mow the lawn");

            //Act
            testTask.Save();
            Task savedTask = Task.GetAll()[0];

            int result = savedTask.GetId();
            int testId = testTask.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Esempio n. 5
0
    public void Test_SaveAssignsIdToObject()
    {
      //Arrange
      Task testTask = new Task("Mow the lawn");
      testTask.Save();

      //Act
      Task savedTask = Task.GetAll()[0];

      int result = savedTask.GetId();
      int testId = testTask.GetId();

      //Assert
      Assert.Equal(testId, result);
    }
        public void Test_Save_AssignsIdToObject()
        {
            //Arrange
              DateTime fakeTime = new DateTime(2016, 1, 1);
              Task testTask = new Task("Mow the lawn", 1, fakeTime);

              //Act
              testTask.Save();
              Task savedTask = Task.GetAll()[0];

              int result = savedTask.GetId();
              int testId = testTask.GetId();

              //Assert
              Assert.Equal(testId, result);
        }
Esempio n. 7
0
        public void Test_Save_AssignIdToObject()
        {
            //Arrange
            DateTime myDate   = new DateTime(1999, 6, 4);
            Task     testTask = new Task("Mow the lawn", 1, myDate);

            //Act
            testTask.Save();
            Task savedTask = Task.GetAll()[0];

            int result = savedTask.GetId();
            int testId = testTask.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Esempio n. 8
0
        public void Test_DueDate_SavesInRightFormat()
        {
            //Arrange
            string testDate = "2017-02-17";
            string taskDate;
            Task   testTask = new Task("Mow the lawn", "2017-02-17");

            testTask.Save();

            //Act
            Task foundTask = Task.Find(testTask.GetId());

            taskDate = foundTask.GetDueDate();
            //Assert
            Assert.Equal(testDate, taskDate);
        }
Esempio n. 9
0
 public override bool Equals(Object otherTask)
 {
     if (!(otherTask is Task))
     {
         return(false);
     }
     else
     {
         Task newTask             = (Task)otherTask;
         bool idEquality          = (this.GetId() == newTask.GetId());
         bool descriptionEquality = (this.GetDescription() == newTask.GetDescription());
         bool completedEquality   = (this.GetCompleted() == newTask.GetCompleted());
         bool dueDateEquality     = (this.GetDueDate() == newTask.GetDueDate());
         return(idEquality && descriptionEquality && completedEquality && dueDateEquality);
     }
 }
Esempio n. 10
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            Task testTask = new Task("Mow the carpet", 1, "05/10/2210");

            testTask.Save();

            //Act
            Task savedTask = Task.GetAll()[0];

            int result = savedTask.GetId();
            int testId = testTask.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Esempio n. 11
0
        public void Test_SaveAssignsIdToObject()
        {
            //Arrange
            DateTime time     = new DateTime(2016, 08, 08);
            Task     testTask = new Task("Mow the lawn", time);

            testTask.Save();

            //Act
            Task savedTask = Task.GetAll()[0];

            int result = savedTask.GetId();
            int testId = testTask.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Esempio n. 12
0
        public void Test_Save_AssignsIdToObject()
        {
            // Arrange
            Task testTask = new Task("Mow my cat");

            // Act
            testTask.Save();
            Task savedTask = Task.GetAll()[0];
            // =
            // List<Task> allTasks = Task.GetAll();
            // Task myTask = allTasks[0];
            // Array [0] b/c List<Task> is an array.
            // Get [0] in this case meant get the whole row of that first id index
            // which include description and other columns(if there's more)

            int result = savedTask.GetId();
        }
Esempio n. 13
0
        public void AddTask(Task newTask)
        {
            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("INSERT INTO categories_tasks (category_id, task_id) VALUES(@CategoryId, @TaskId);", conn);

            cmd.Parameters.AddWithValue("@CategoryId", this.GetId());
            cmd.Parameters.AddWithValue("@TaskId", newTask.GetId());

            cmd.ExecuteNonQuery();

            if (conn != null)
            {
                conn.Close();
            }
        }
        public void AddTask(Task newTask)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlCommand cmd = new SqlCommand("INSERT INTO categories_tasks(category_id,task_id) VALUES(@CategoryId,@TaskId);",conn);
              SqlParameter categoryIdParameter = new SqlParameter();
              categoryIdParameter.ParameterName = "@categoryId";
              categoryIdParameter.Value=this.GetId();
              cmd.Parameters.Add(categoryIdParameter);

              SqlParameter taskIdParameter = new SqlParameter();
              taskIdParameter.ParameterName="@TaskId";
              taskIdParameter.Value=newTask.GetId();
              cmd.Parameters.Add(taskIdParameter);

              cmd.ExecuteNonQuery();
              if(conn != null)
              {
            conn.Close();
              }
        }
        public void Test_Find_FindsTaskInDatabase()
        {
            DateTime testTime = new DateTime(2016, 1, 1);

              Task testTask = new Task("Mow the lawn",testTime);
              testTask.Save();

              Task foundTask = Task.Find(testTask.GetId());

              Assert.Equal(testTask, foundTask);
        }
Esempio n. 16
0
        public void AddTask(Task newTask)
        {
            SqlConnection conn = DB.Connection();
              conn.Open();

              SqlDataReader rdrCheckForDuplicate = null;
              SqlCommand cmdCheckForDuplicate = new SqlCommand("SELECT * FROM categories_tasks WHERE category_id=@CategoryId AND task_id=@TaskId", conn);
              SqlParameter categoryIdParameterCheckForDuplicate = new SqlParameter();
              categoryIdParameterCheckForDuplicate.ParameterName = "@CategoryId";
              categoryIdParameterCheckForDuplicate.Value = this.GetId();
              cmdCheckForDuplicate.Parameters.Add(categoryIdParameterCheckForDuplicate);

              SqlParameter taskIdParameterCheckForDuplicate = new SqlParameter();
              taskIdParameterCheckForDuplicate.ParameterName = "@TaskId";
              taskIdParameterCheckForDuplicate.Value = newTask.GetId();
              cmdCheckForDuplicate.Parameters.Add(taskIdParameterCheckForDuplicate);

              List<int> matchedJoins = new List<int> {};
              rdrCheckForDuplicate = cmdCheckForDuplicate.ExecuteReader();
              while(rdrCheckForDuplicate.Read())
              {
            matchedJoins.Add(rdrCheckForDuplicate.GetInt32(0));
              }

              if (rdrCheckForDuplicate != null) rdrCheckForDuplicate.Close();

              if (matchedJoins.Count == 0)
              {
            SqlCommand cmd = new SqlCommand("INSERT INTO categories_tasks (category_id, task_id) VALUES (@CategoryId, @TaskId)", conn);

            SqlParameter categoryIdParameter = new SqlParameter();
            categoryIdParameter.ParameterName = "@CategoryId";
            categoryIdParameter.Value = this.GetId();
            cmd.Parameters.Add(categoryIdParameter);

            SqlParameter taskIdParameter = new SqlParameter();
            taskIdParameter.ParameterName = "@TaskId";
            taskIdParameter.Value = newTask.GetId();
            cmd.Parameters.Add(taskIdParameter);

            cmd.ExecuteNonQuery();
              }
              if (conn != null)
              {
            conn.Close();
              }
        }
Esempio n. 17
0
        public void Test_FindFindsTaskInDatabase()
        {
            //Arrange
              Task testTask = new Task("Mow the lawn", new DateTime(2016, 2, 2), false);
              testTask.Save();

              //Act
              Task result = Task.Find(testTask.GetId());

              //Assert
              Assert.Equal(testTask, result);
        }