コード例 #1
0
        public void Delete_StudentIdIsEmpty_Fail()
        {
            // Arrange
            var id = Guid.Empty;

            // Act
            var result = _service.Delete(id);

            // Assert
            Assert.That(result, Is.Not.Null);
            Assert.That(result.Succeed, Is.False);
        }
コード例 #2
0
 public ActionResult <String> Delete(int id)
 {
     try
     {
         return(Ok(_ss.Delete(id)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #3
0
        public void Delete()
        {
            Mock <DbContexts.MVCWebAppDbContext> dbContext = new Mock <DbContexts.MVCWebAppDbContext>();
            IStudentsService studentService = new StudentsService(dbContext.Object);

            var students = new List <Student>()
            {
                new Student()
                {
                    StudentID = 1, RefNo = "12456343", FirstName = "John", LastName = "Smith", DateOfBirth = DateTime.Now.AddYears(-10), DateCreated = DateTime.Now
                },
                new Student()
                {
                    StudentID = 2, RefNo = "87984564", FirstName = "Pete", LastName = "Luck", DateOfBirth = DateTime.Now.AddYears(-20), DateCreated = DateTime.Now.AddDays(1)
                }
            };

            var mockSet = new Mock <DbSet <Student> >();

            mockSet.As <IQueryable <Student> >().Setup(m => m.Provider).Returns(students.AsQueryable().Provider);
            mockSet.As <IQueryable <Student> >().Setup(m => m.Expression).Returns(students.AsQueryable().Expression);
            mockSet.As <IQueryable <Student> >().Setup(m => m.ElementType).Returns(students.AsQueryable().ElementType);
            mockSet.As <IQueryable <Student> >().Setup(m => m.GetEnumerator()).Returns(students.AsQueryable().GetEnumerator());

            dbContext.Setup(m => m.Students.Remove(It.IsAny <Student>())).Callback <Student>((entity) => students.Remove(entity));

            dbContext.Setup(c => c.Students).Returns(mockSet.Object);

            int idToDelete = 1;

            dbContext.Setup(s => s.Students.Find(idToDelete)).Returns(students.Single(s => s.StudentID == idToDelete));

            // call delete method now
            studentService.Delete(idToDelete);

            // 1 object deleted, it should return 1
            Assert.Equal(1, students.Count());  // <----- Error here

            dbContext.Verify(s => s.Students.Find(idToDelete), Times.Once);
            dbContext.Verify(s => s.Students.Remove(It.IsAny <Student>()), Times.Once);
            dbContext.Verify(s => s.SaveChanges(), Times.Once);
        }
コード例 #4
0
        public async Task <IActionResult> DeleteStudent(int id)
        {
            var student = StudentsService.GetByID(id);

            if (student == null)
            {
                return(NotFound());
            }

            try
            {
                await StudentsService.Delete(id);

                return(NoContent());
            }
            catch (DbUpdateException /* ex */)
            {
                //log the error (uncomment ex variable name and write a log.)
                return(BadRequest());
            }
        }
コード例 #5
0
 public void Delete(int ID)
 {
     StudentsSVC.Delete(ID);
 }
コード例 #6
0
 public ActionResult Delete(int id)
 {
     _studentsService.Delete(id);
     return(RedirectToAction(nameof(Index)));
 }
コード例 #7
0
 public void Delete(int id)
 {
     _service.Delete(id);
 }
コード例 #8
0
 public void Delete(int ID)
 {
     studentsService.Delete(ID);
 }
コード例 #9
0
 public void should_not_Delete_Student()
 {
     Assert.Equal(-1, _studentService.Delete(-13445));
 }