private async Task CreateStudentOrTeacher(AppUser appUser, User user)
        {
            if (appUser.IsStudent)
            {
                var currentStudent = await _userManager.FindByNameAsync(appUser.UserName);

                await _userManager.AddToRoleAsync(currentStudent, "student");

                await _studentsController.Create(new Student
                {
                    FirstName   = user.FirstName,
                    LastName    = user.LastName,
                    PhoneNumber = "000-000-000",
                    Email       = user.Email
                });
            }

            if (appUser.IsTeacher)
            {
                var currentTeacher = await _userManager.FindByNameAsync(appUser.UserName);

                await _userManager.AddToRoleAsync(currentTeacher, "teacher");

                await _teachersController.Create(new Teacher
                {
                    FirstName   = user.FirstName,
                    LastName    = user.LastName,
                    PhoneNumber = "000-000-000",
                    Email       = user.Email
                });
            }
        }
        public void Teachers_Controller_Test_On_CreateModel_With_Invalid_Model()
        {
            //Arrange
            Guid   id          = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            string firstName   = "a";
            string lastName    = "TestL";
            string userName    = "******";
            string password    = "******";
            string emailAdress = "TestE";

            Teacher expectedTeacher = new Teacher(firstName, lastName, userName, password, emailAdress);

            expectedTeacher.Id = id;

            TeacherModel expectedModel = new TeacherModel();

            expectedModel.EmailAddress = " ";
            var repo = Substitute.For <IRepository>();
            var sut  = new TeachersController(repo);

            repo.Create(expectedTeacher);

            //Act
            sut.ModelState.AddModelError("FirstName", "Firstname Required");
            var actual = sut.Create(expectedModel).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(ViewResult));
        }
        public void Teachers_Controller_Test_On_Create()
        {
            //Arrange
            var repo = Substitute.For <IRepository>();
            var sut  = new TeachersController(repo);

            //Act
            var actual = sut.Create();

            //Assert
            Assert.IsInstanceOfType(actual, typeof(ViewResult));
        }
        public async Task Create_ShouldReturnJsonAnonymousObject_WhenInvalidObjectPassed()
        {
            // Arrange
            var teacher = new Teacher()
            {
                LastName = "Brzeczyszczykiewicz",
                Email    = "*****@*****.**"
            };

            _controller.ModelState.AddModelError("FirstName", "Required");

            // Act
            dynamic response = await _controller.Create(teacher);

            var valueFromAnnonymous = response.Value.GetType().GetProperty("text").GetValue(response.Value, null);

            // Assert
            Assert.IsType <JsonResult>(response);
            //Assert.Equal("{ text = Invalid Techer model! }", s.Value.ToString());
            Assert.NotNull(response);
            Assert.Equal("Invalid Techer model!", valueFromAnnonymous);
        }
Ejemplo n.º 5
0
        public static void TeachersTest()
        {
            var repository        = new TeacherAdoNetRepository();
            var licenseRepository = new LicenseEFRepository();
            var service           = new TeacherService(repository, licenseRepository);
            var controller        = new TeachersController(service);

            var teacherPostModel = new TeacherPostModel {
                FirstName = "Puzo", LastName = "Moe", LicenseNum = 2
            };

            controller.Create(teacherPostModel);

            var teachers = controller.GetAll();
        }