public void DeleteTest()
        {
            Student v = new Student();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.Name = "Ig1N37FOm";
                v.Age  = 20;
                context.Set <Student>().Add(v);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID.ToString());

            Assert.IsInstanceOfType(rv.Model, typeof(StudentVM));

            StudentVM vm = rv.Model as StudentVM;

            v         = new Student();
            v.ID      = vm.Entity.ID;
            vm.Entity = v;
            _controller.Delete(v.ID.ToString(), null);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <Student>().Find(v.ID);
                Assert.AreEqual(data, null);
            }
        }
        public async void Remove_NotExistingtStudent_ReturnsNotFoundResponse()
        {
            // Arrange
            var notExistingId = -1;

            mockService.Setup(repo => repo.GetAsync(It.IsAny <int>()));

            // Act
            var badResponse = await studentController.Delete(notExistingId);

            // Assert
            Assert.IsType <NotFoundResult>(badResponse.Result);
        }
Exemple #3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.lstStudent.SelectedItems.Count <= 0)
            {
                MessageBox.Show("Bạn chưa chọn đối tượng!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            DialogResult dlr = MessageBox.Show("Bạn có muốn xóa đối tượng?", "Thông báo",
                                               MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dlr == DialogResult.No)
            {
                return;
            }

            string getMssv = this.lstStudent.SelectedItems[0].SubItems[1].Text;

            this.lstStudent.SelectedItems[0].Remove();

            Student deleteStd = StudentController.getMssvStd(getMssv);

            try
            {
                StudentController.Delete(deleteStd);
            }
            catch
            {
                MessageBox.Show("err delete");
            }
            DisplayListView();
        }
Exemple #4
0
        public void StudentControllerCanDelete()
        {
            DbContextOptions <Lab13StudentEnrollmentDbContext> options =
                new DbContextOptionsBuilder <Lab13StudentEnrollmentDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (Lab13StudentEnrollmentDbContext context = new Lab13StudentEnrollmentDbContext(options))
            {
                // Arrange
                Course course = new Course();
                course.Name        = "DotNet";
                course.Description = "Embrace the flood";

                CourseController cc = new CourseController(context);

                var x = cc.Create(course);

                Student student = new Student();
                student.Name     = "Someone";
                student.CourseID = 1;
                StudentController sc = new StudentController(context);

                var y = sc.Create(student);
                // Act
                var z = sc.Delete(student.ID);

                var results = context.Students.Where(a => a.Name == "Someone");
                // Assert
                Assert.Equal(0, results.Count());
            }
        }
Exemple #5
0
        public void StudentControllerCanDelete()
        {
            DbContextOptions <EnrollmentDbContext> options =
                new DbContextOptionsBuilder <EnrollmentDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (EnrollmentDbContext context = new EnrollmentDbContext(options))
            {
                Course course = new Course();
                course.ID           = 3;
                course.ClassName    = ClassName.Python;
                course.Instructor   = "Miss Snake";
                course.StartingDate = new DateTime(2012, 12, 12);
                course.EndDate      = new DateTime(2012, 12, 25);

                Student student = new Student();
                student.Name         = "Mario";
                student.CourseId     = 3;
                student.Passing      = true;
                student.HoursOfSleep = 5;

                CourseController cc = new CourseController(context);
                var y = cc.Create(course);

                StudentController sc = new StudentController(context);
                var x = sc.Create(student);
                var z = sc.Delete(1);

                var results = context.Student.Where(a => a.Name == "Mario");

                Assert.Equal(0, results.Count());
            }
        }
        public void DeleteStudent_ServiceMethodIsCalled()
        {
            var controller = new StudentController(StudentServiceMock.Object, CollegeRulesMock.Object, StudentPathProviderMock.Object);

            controller.Delete(12);

            StudentServiceMock.Verify(x => x.Delete(It.IsAny <int>()), Times.Once);
        }
        public async Task DeleteStudent_ValidCall()
        {
            var response = await StudentController.Delete(1);

            var code = ((ObjectResult)response.Result).StatusCode;

            Assert.AreEqual((int)HttpStatusCode.OK, code);
        }
        public async Task DeleteStudent_BadRequest()
        {
            var response = await StudentController.Delete(null);

            var code = (StatusCodeResult)response.Result;

            Assert.AreEqual((int)HttpStatusCode.BadRequest, code.StatusCode);
        }
Exemple #9
0
        public void TestInitialize()
        {
            StudentController            studentController = new StudentController();
            IDictionary <string, object> filters           = new Dictionary <string, object>();

            foreach (var entity in studentController.Get(filters))
            {
                studentController.Delete(entity.Id);
            }
        }
        public void DeleteShouldReturnNotFoundWhenUserDoesntExist()
        {
            // Arrange
            var mockRepository = new Mock <IStudentRepository>();
            var controller     = new StudentController(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = controller.Delete(DEFAULT_ID);

            // Assert
            Assert.IsInstanceOf <NotFoundResult>(actionResult);
        }
Exemple #11
0
        public void DeleteStudent_ShouldAssertTrue(string Id)
        {
            using var scope = _factory.Server.Host.Services.CreateScope();
            var studentService = scope.ServiceProvider.GetRequiredService <IStudentService>();

            var studentController = new StudentController(studentService);

            var id     = Guid.Parse(Id);
            var result = studentController.Delete(id);

            Assert.Equal(typeof(OkObjectResult), result.GetType());
        }
        public void StudentDeleteCorrectID()
        {
            var db = new TestStudentIspitiContext();
            db.Initialize();
            StudentController controller = new StudentController(db);
            string i = "07_001";

            var result = controller.Delete(i) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(Student));
        }
        public void StudentDeleteNotCorrectID()
        {
            var db = new TestStudentIspitiContext();
            db.Initialize();
            StudentController controller = new StudentController(db);
            string i = "99_999";

            var result = controller.Delete(i);

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
            var httpResult = result as HttpNotFoundResult;
            Assert.AreEqual(404, httpResult.StatusCode);
        }
Exemple #14
0
        private void button1_Click(object sender, EventArgs e)  // Delete a user
        {
            string username = Students.GetItemText(Students.SelectedItem);

            if (username == null || username.Equals(""))
            {
                MessageBox.Show("Select a student from the list.");
            }
            else
            {
                _StudentController.Delete(username);
                UpdateStudentCount();
                UpdateListBox(StudentModel.AllStudents);
            }
        }
Exemple #15
0
        public void Controller_Student_Delete_Post_Null_Data_Should_Return_Error()
        {
            // Arrange
            StudentController controller = new StudentController();

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = (RedirectToRouteResult)controller.Delete((StudentDisplayViewModel)null);

            // Assert
            Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName);
        }
        // [Theory]
        // [InlineData(1)]
        // [InlineData(2)]
        // [InlineData(3)]
        public void Delete_ValidId_ReturnBadRequest()
        {
            //arrange
            var dbContext  = DbContextMocker.GetDbContext(nameof(Delete_ValidId_ReturnBadRequest));
            var controller = new StudentController(dbContext);

            //act
            var result         = controller.Delete(1);
            var okObjectResult = result as OkObjectResult;

            dbContext.Dispose();

            //assert
            Assert.NotNull(okObjectResult);
            Assert.Equal(200, okObjectResult.StatusCode);
        }
        public void DeleteShouldReturnOkWhenSucceded()
        {
            // Arrange
            var mockRepository = new Mock <IStudentRepository>();

            mockRepository.Setup(x => x.GetStudent(It.IsAny <int>()))
            .Returns(FakeUser());

            var controller = new StudentController(mockRepository.Object);

            // Act
            IHttpActionResult actionResult = controller.Delete(DEFAULT_ID);
            var contentResult = actionResult as OkNegotiatedContentResult <StudentDto>;

            // Assert
            Assert.IsInstanceOf <OkResult>(actionResult);
        }
        public void StudentDelete()
        {
            StudentController sk = new StudentController();

            Mock <UnitOfWork>        mockUnit    = new Mock <UnitOfWork>(new Zadatak2Context());
            Mock <StudentRepository> mockStudent = new Mock <StudentRepository>(new Zadatak2Context());

            mockStudent.Setup(x => x.FindStudent(SeedClass.GetStudentsTest()[1].BI)).Returns(SeedClass.GetStudentsTest()[1]);

            sk.UnitOfWork          = mockUnit.Object;
            sk.UnitOfWork.Studenti = mockStudent.Object;
            ViewResult rezultat = sk.Delete(SeedClass.GetStudentsTest()[1].BI) as ViewResult;

            mockStudent.Verify((x => x.FindStudent(SeedClass.GetStudentsTest()[1].BI)), Times.Once());
            Assert.AreEqual(SeedClass.GetStudentsTest()[1].GetType(), rezultat.Model.GetType());
            Assert.IsNotNull(rezultat);
        }
Exemple #19
0
        public void Controller_DeleteOperation_Success()
        {
            StudentController studentController = new StudentController();

            string[] data   = { "University", "Leia", "Female", "20151231145934" };
            IEntity  entity = EntityFactory.CreateEntity(EntityType.Student, data);

            studentController.Add(entity);

            IDictionary <string, object> filters = new Dictionary <string, object>();
            var createdEntity = studentController.Get(filters)[0];

            studentController.Delete(createdEntity.Id);

            var count = studentController.Get(filters).Count;

            Assert.AreEqual(count, 0);
        }
        public async void Delete_Errors()
        {
            StudentControllerMockFacade mock = new StudentControllerMockFacade();
            var mockResult = new Mock <ActionResponse>();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.FromResult <ActionResponse>(mockResult.Object));
            StudentController controller = new StudentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Delete(default(int));

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Delete(It.IsAny <int>()));
        }
Exemple #21
0
        public void Delete_RedirectsToStudents_WhenStudentExists()
        {
            //Arrange
            Student student = new Student()
            {
                Name = "Test Student"
            };
            StudentService studentService = Substitute.For <StudentService>();

            studentService.GetStudentById(5).Returns(student);
            StudentController controller = new StudentController(studentService);

            //Act
            var actionResult = controller.Delete(student.Id);

            // Assert
            actionResult.Should().BeOfType <RedirectToActionResult>().Which.ActionName.Should().Be("Students");
        }
Exemple #22
0
        public void Controller_Student_Delete_Post_Invalid_Model_Should_Send_Back_For_Edit()
        {
            // Arrange
            StudentController       controller = new StudentController();
            StudentDisplayViewModel data       = new StudentDisplayViewModel();

            // Make ModelState Invalid
            controller.ModelState.AddModelError("test", "test");

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = controller.Delete(data) as ViewResult;

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
Exemple #23
0
        public void Delete_RedirectToStudents()
        {
            // Arrange
            int studentId = 1;

            var studentServiceMock = Substitute.For <StudentService>();

            studentServiceMock.DeleteStudent(studentId).Returns(true);
            var controller = new StudentController(studentServiceMock);

            // Act
            var result = controller.Delete(studentId);

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Students", redirectToActionResult.ActionName);
        }
        public void DeleteStudentTest()
        {
            Student deleteStudentTestData;

            deleteStudentTestData = StudentTestData.GetTestDataStudentDelete();

            var expectedStudent = Task.FromResult(deleteStudentTestData);

            mockStudentRepository.Setup(m => m.Student.GetStudentByIdAsync(deleteStudentTestData.Id)).Returns(expectedStudent);
            mockStudentRepository.Setup(m => m.Student.DeleteStudent(deleteStudentTestData)).Returns(true);

            OkObjectResult content        = studentController.Delete(deleteStudentTestData.Id).Result as OkObjectResult;
            HttpStatusCode httpStatusCode = (HttpStatusCode)content.StatusCode;

            var response = content.Value as ResponseModel <Student>;
            var actualDeleteSuccessMessage = response.Message;

            Assert.AreEqual(httpStatusCode, HttpStatusCode.OK);
            Assert.AreEqual(ResponseMessage.OnSuccessDeleteMessage, actualDeleteSuccessMessage);
        }
Exemple #25
0
        public void GivenId_WheIdValid_ThenDeleteStudent()
        {
            schoolContext = new SchoolContext();
            //Given
            Student student = new Student()
            {
                Id          = "60f6a6fc-9de7-4fca-b75c-f6f335c76961",
                FirstName   = "Carson",
                LastName    = "Alexander",
                Enrollments = new List <Enrollment>()
            };
            var count = studentController.GetAll().Count();

            //When
            studentController.Delete(mockedSchoolContext.Object.Students[0]);
            var countResult = studentController.GetAll().Count();

            //Assert
            Assert.AreNotEqual(countResult, count);
        }
Exemple #26
0
        public void Controller_Student_Delete_Post_Empty_Id_Should_Send_Back_For_Edit()
        {
            // Arrange
            StudentController       controller = new StudentController();
            StudentDisplayViewModel dataEmpty  = new StudentDisplayViewModel
            {
                // Make data.Id empty
                Id = ""
            };

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var resultEmpty = (ViewResult)controller.Delete(dataEmpty);

            // Assert
            Assert.IsNotNull(resultEmpty, TestContext.TestName);
        }
Exemple #27
0
        public void Controller_Student_Delete_Get_Default_Should_Pass()
        {
            // Arrange
            StudentController controller = new StudentController();

            string id = DataSourceBackend.Instance.StudentBackend.GetDefault().Id;

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            ViewResult result = controller.Delete(id) as ViewResult;

            // Reset DataSourceBackend
            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
Exemple #28
0
        public void Controller_Student_Delete_Invalid_Null_Data_Should_Return_Error()
        {
            // Arrange
            StudentController controller = new StudentController();
            string            id         = "bogus";

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = (RedirectToRouteResult)controller.Delete(id);

            // Reset
            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.AreEqual("Error", result.RouteValues["action"], TestContext.TestName);
            Assert.AreEqual("Home", result.RouteValues["controller"], TestContext.TestName);
        }
        public void GivenDeletingStudent_WhenDeleting_ThenCorrespondingStudentIsDeleted()
        {
            // Arrange

            var testStudent = new Student("OliCreationTest", "test")
            {
                Id = 1
            };
            DeleteStudentMessage      request = null;
            DeleteStudentReplyMessage reply   = null;

            var queryCountWrapper = new Mock <IQueryCountWrapper>();

            queryCountWrapper.SetupGet(qcw => qcw.QueryCount).Returns(0);

            var bus = new Mock <IBus>(MockBehavior.Strict);

            bus
            .Setup(b => b.SendRequest
                   <DeleteStudentMessage, DeleteStudentReplyMessage>
                       (It.IsAny <string>(), It.IsAny <DeleteStudentMessage>(), null, It.IsAny <int>()))
            .Returns <string, DeleteStudentMessage, Dictionary <string, string>, int>(
                (endpoint, message, headers, timeout) =>
            {
                request = message;
                reply   = new DeleteStudentReplyMessage(message.CorrelationId);
                return(reply);
            });

            var claimsHelper = new Mock <IClaimsHelper>(MockBehavior.Strict);
            var controller   = new StudentController(bus.Object, claimsHelper.Object, queryCountWrapper.Object);

            // Act
            var result         = controller.Delete((int)testStudent.Id);
            var okObjectResult = result as ObjectResult;

            // Assert

            Assert.Equal(reply.CorrelationId, okObjectResult.Value);
        }
Exemple #30
0
        public async Task CanDeleteStudents()
        {
            var options = new DbContextOptionsBuilder <StudentContext>()
                          .UseInMemoryDatabase(databaseName: "testing321")
                          .Options;

            using (var context = new StudentContext(options))
            {
                var SController = new StudentController(context);
                await context.SaveChangesAsync();

                var course = await context.Course.FirstOrDefaultAsync(x => x.Department == "CPTS");

                Student s1 = new Student()
                {
                    LastName = "Scott", FirstName = "Was Here", Enrolled = 12
                };
                Student s2 = new Student()
                {
                    LastName = "Steve", FirstName = "Was Not Here", Enrolled = 12
                };
                await context.Student.AddAsync(s1);

                await context.Student.AddAsync(s2);

                await context.SaveChangesAsync();

                var list = await context.Student.ToListAsync();

                //Act
                var scott = await context.Student.FirstOrDefaultAsync(x => x.LastName == "Scott");

                SController.Delete(scott.ID);

                //Assert
                var numStudents = await context.Student.CountAsync();

                Assert.Equal(1, numStudents);
            }
        }
        public void TestDeleteStudent()
        {
            bool isItemDeleted = false;
            bool isItemAdded   = false;
            var  repository    = Mock.Create <IRepository <Student> >();

            var studentModel = new StudentModel()
            {
                FirstName = "Pesho",
                LastName  = "Peshov",
                Grade     = 3
            };
            var studentEntity = new Student()
            {
                Id        = 1,
                FirstName = studentModel.FirstName,
                LastName  = studentModel.LastName,
                Grade     = studentModel.Grade
            };

            Mock.Arrange(() => repository.Add(Arg.IsAny <Student>()))
            .DoInstead(() => isItemAdded = true)
            .Returns(studentEntity);

            var controller = new StudentController(repository);

            SetupController.Create(controller, "post", "student");

            controller.Post(studentEntity);

            Mock.Arrange(() => repository.Delete(Arg.IsAny <Student>()))
            .DoInstead(() => isItemDeleted = true);


            SetupController.Create(controller, "delete", "student");

            controller.Delete(studentEntity.Id);

            Assert.IsFalse(isItemDeleted);
        }
Exemple #32
0
        public void Controller_Student_Delete_Post_Default_Should_Return_Index_Page()
        {
            // Arrange
            StudentController controller = new StudentController();

            // Get default student
            StudentModel            student = DataSourceBackend.Instance.StudentBackend.GetDefault();
            StudentDisplayViewModel data    = new StudentDisplayViewModel(student);

            var context = CreateMoqSetupForCookie();

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            // Act
            var result = (RedirectToRouteResult)controller.Delete(data);

            // Reset
            DataSourceBackend.Instance.Reset();

            // Assert
            Assert.AreEqual("Index", result.RouteValues["action"], TestContext.TestName);
        }
        public void StudentDeleteNullTest()
        {
            /*Test Delete when null is passed*/
            var db = new TestStudentIspitiContext();
            db.Initialize();
            StudentController controller = new StudentController(db);
            string i = null;

            var result = controller.Delete(i);

            Assert.IsInstanceOfType(result, typeof(System.Web.Mvc.HttpStatusCodeResult));
            var httpResult = result as HttpStatusCodeResult;
            Assert.AreEqual(400, httpResult.StatusCode);
        }