public void DeleteProduct_ShouldReturnNoContentStatusCode()
        {
            Student testItem = _dbContext.Students.First();

            var result = _testController.DeleteStudent(testItem.Id).GetAwaiter().GetResult() as StatusCodeResult;

            Assert.IsNotNull(result);

            Assert.AreEqual((int)HttpStatusCode.NoContent, result.StatusCode);
        }
示例#2
0
        public void DeleteStudent_NotExistingIdPassed_ReturnsNotFoundResponse()
        {
            // Arrange
            var notExistingId = 1;

            // Act
            var badResponse = _controller.DeleteStudent(notExistingId);

            // Assert
            Assert.IsType <NotFoundResult>(badResponse);
        }
示例#3
0
 private void deleteRecordToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (studentsRecord.Rows.Count >= 2)
     {
         if (studentsRecord.SelectedRows.Count == 1 && studentsRecord.CurrentRow.Cells[0].Value != null)
         {
             int          row       = studentsRecord.CurrentCell.RowIndex;
             string       studNum   = studentsRecord.Rows[row].Cells[0].Value.ToString();
             string       delCourse = studentsRecord.Rows[row].Cells[4].Value.ToString();
             DialogResult dialog    = new DialogResult();
             dialog = MessageBox.Show("Confirm delete student?", "Warning", MessageBoxButtons.YesNo);
             if (dialog == DialogResult.Yes)
             {
                 StudentsController.DeleteStudent(studNum);
                 searchbox_ButtonClick(null, null);
             }
         }
         else
         {
             MessageBox.Show("No student selected!");
         }
     }
     focusHere.Focus();
     SetStudentRecords(StudentsController.GetStudents());
 }
示例#4
0
        public void DeleteStudent_ShouldDeleteStudent()
        {
            Student studentEnitity = new Student()
            {
                StudentId = 1,
                FirstName = "Minko",
                LastName  = "Markov",
                School    = new School(),
                Grade     = 5
            };

            var fakeRepo = new FakeStudentRepository();

            fakeRepo.Add(studentEnitity);
            fakeRepo.Add(studentEnitity);
            var controller = new StudentsController(fakeRepo);

            studentEnitity.FirstName = "Kiro";

            SetupController(controller);
            controller.PutStudent(studentEnitity.StudentId, studentEnitity);

            controller.DeleteStudent(studentEnitity.StudentId);

            Assert.AreEqual(1, fakeRepo.Entities.Count());
        }
示例#5
0
        public async Task DeleteStudent_RequiresPositiveId(int studentId)
        {
            var service    = new Mock <IStudentService>(MockBehavior.Strict);
            var controller = new StudentsController(service.Object, Mapper.Instance);

            var result = await controller.DeleteStudent(studentId);

            Assert.IsTrue(result is BadRequestObjectResult);
        }
示例#6
0
        public void ShouldReturnNotFoundWhenStudentNotExist()
        {
            var controller = new StudentsController(_unitOfWork, _urlHelper);

            var sut = controller.DeleteStudent("222");

            var notFoundResult = Assert.IsType <NotFoundObjectResult>(sut);

            Assert.Equal("222", notFoundResult.Value);
        }
示例#7
0
        public void ShouldReturnNoContentWhenDeleteSuccess()
        {
            var controller = new StudentsController(_unitOfWork, _urlHelper);

            var sut = controller.DeleteStudent("1");

            Assert.IsType <NoContentResult>(sut);

            Assert.Equal(0, _randomStudent.Single(x => x.Id == "1").IsActived);
        }
示例#8
0
        //===========================================
        //
        // <Summary>
        //      Method for Deleting a Student
        //  Record
        //
        //===========================================
        private void DeleteStudent()
        {
            string       studentNumber = StudentRecords.CurrentRow.Cells[0].Value.ToString();
            DialogResult result        = new DialogResult();

            result = MessageBox.Show("Are you sure to delete this record ? ", "Warning", MessageBoxButtons.YesNoCancel);

            if (result == DialogResult.Yes)
            {
                StudentsController.DeleteStudent(studentNumber);
                GetStudentRecords();
            }
        }
示例#9
0
        public void DeleteStudent_ShouldReturnNotFound()
        {
            // Arrange
            testSchoolRegisterContext = new TestSchoolRegisterContext();
            studentRepo        = new MockStudentRepo(testSchoolRegisterContext);
            studentsController = new StudentsController(studentRepo);

            //Act
            IHttpActionResult actionResult = studentsController.DeleteStudent("sampleStudentId");

            //Assert
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
示例#10
0
        public async Task DeleteStudent_ReturnsOkWhenStudentIsDeleted()
        {
            var service = new Mock <IStudentService>();

            service.Setup(x => x.DeleteStudent(2))
            .Returns(Task.FromResult(true))
            .Verifiable();
            var controller = new StudentsController(service.Object, Mapper.Instance);

            var result = await controller.DeleteStudent(2);

            Assert.IsTrue(result is OkResult);
            service.VerifyAll();
        }
示例#11
0
        public async Task DeleteStudent_ReturnsNotFoundWhenTheStudentFailsToDelete()
        {
            var service = new Mock <IStudentService>();

            service.Setup(x => x.DeleteStudent(2))
            .Returns(Task.FromResult(false))
            .Verifiable();
            var controller = new StudentsController(service.Object, Mapper.Instance);

            var result = await controller.DeleteStudent(2);

            Assert.IsTrue(result is NotFoundResult);
            service.VerifyAll();
        }
        public async Task Delete_Student()
        {
            //given
            int studentId = 1;
            var mockStudentReposiotory = new Mock <IStudentRepository>();

            mockStudentReposiotory.Setup(x => x.Delete(studentId)).ReturnsAsync(true);

            //When
            StudentsController studentsController = new StudentsController(mockStudentReposiotory.Object);
            var result = await studentsController.DeleteStudent(studentId) as ObjectResult;

            //Then
            Assert.AreEqual((int)HttpStatusCode.OK, result.StatusCode);
        }
示例#13
0
        public void DeleteStudent_ShouldReturnForbidden()
        {
            //Arrange
            testSchoolRegisterContext = new TestSchoolRegisterContext();
            studentRepo        = new MockStudentRepo(testSchoolRegisterContext);
            studentsController = new StudentsController(studentRepo);
            PopulateStudentFields();

            //Act
            var actionResult = studentsController.DeleteStudent("unauthenticatedStudentId") as ResponseMessageResult;


            //Assert
            Assert.IsNotNull(actionResult);
            Assert.AreEqual(actionResult.Response.StatusCode, HttpStatusCode.Forbidden);
        }
示例#14
0
        public async Task Should_RemoveExistingStudent()
        {
            // arrange
            const int     studentId = 2;
            IActionResult result;
            Student       studentResult;

            // act
            using (var dbContext = new BlogPostContext(fixture.Options))
            {
                var controller = new StudentsController(dbContext, fixture.Mapper, studentServiceMock.Object, studentRepositoryMock.Object);
                result = await controller.DeleteStudent(studentId);

                studentResult = dbContext.Students.FirstOrDefault(x => x.Id == studentId);
            }

            // assert
            var noContentResult = result.As <NoContentResult>();

            noContentResult.StatusCode.Should().Be(StatusCodes.Status204NoContent);
            studentResult.Should().BeNull();
        }
        public void TestMethodDelete()
        {
            //Arrange
            Student student_expected = new Student()
            {
                StudentID      = 4,
                LastName       = "Cladera",
                FirstName      = "Isabel",
                EnrollmentDate = DateTime.Today,
            };
            StudentsController studentsController = new StudentsController();

            //Act
            IHttpActionResult actionResult        = studentsController.PostStudent(student_expected);
            IHttpActionResult actionResult_Delete = studentsController.DeleteStudent(student_expected.StudentID);

            //var student_actual = actionResult as OkNegotiatedContentResult<Student>;

            //Assert
            //Assert.IsNotNull(student_actual);
            // Assert.AreEqual(student_expected.StudentID, student_actual.Content.StudentID);
            Assert.IsInstanceOfType(actionResult_Delete, typeof(OkNegotiatedContentResult <Student>));
        }
示例#16
0
 private void ButtonDeleteStudent_Click(object sender, RoutedEventArgs e)
 {
     _studentsController.DeleteStudent(_studentsController.SelectedStudent.StudentId);
     MessageBox.Show("Student deleted successfully");
     PopulateAllStudents();
 }