Beispiel #1
0
        public async Task CreateUserRole_With_Lector_Role()
        {
            var passwordHasherMock    = new Mock <IPasswordHasher>();
            var passwordGeneratorMock = new Mock <IPasswordGenerator>();

            passwordHasherMock.Setup_HashPassword_Returns_Eight_Character_String();
            passwordGeneratorMock.Setup_GetRandomAlphanumericString_Returns_Eight_Character_String();

            var request = new CreateLectorCommand
            {
                Email            = "*****@*****.**",
                AcademicDegreeId = 1,
                AcademicRankId   = 1,
                FirstName        = "Name 3",
                LastName         = "LastName 3",
                Patronymic       = "Patronymic 3",
                PhoneNumber      = "+3333333333"
            };

            var handler = new CreateLectorCommandHandler(Context, passwordHasherMock.Object, passwordGeneratorMock.Object);

            var result = await handler.Handle(request, CancellationToken.None);

            passwordGeneratorMock.Verify_GetRandomAlphanumericString_Called_Once();
            passwordHasherMock.Verify_HashPassword_Called_Once();

            var user = Context.Users.SingleOrDefault(x => x.Email == request.Email);

            Assert.IsNotNull(user);
            Assert.IsTrue(Context.UserRoles.Where(x => x.RoleId == 1 && x.UserId == user.Id).Count() == 1);
        }
Beispiel #2
0
        public async Task CreateLector()
        {
            var passwordHasherMock    = new Mock <IPasswordHasher>();
            var passwordGeneratorMock = new Mock <IPasswordGenerator>();

            passwordHasherMock.Setup_HashPassword_Returns_Eight_Character_String();
            passwordGeneratorMock.Setup_GetRandomAlphanumericString_Returns_Eight_Character_String();

            var request = new CreateLectorCommand
            {
                Email            = "*****@*****.**",
                AcademicDegreeId = 1,
                AcademicRankId   = 1,
                FirstName        = "Name 3",
                LastName         = "LastName 3",
                Patronymic       = "Patronymic 3",
                PhoneNumber      = "+3333333333"
            };

            var handler = new CreateLectorCommandHandler(Context, passwordHasherMock.Object, passwordGeneratorMock.Object);

            var(id, _) = await handler.Handle(request, CancellationToken.None);

            passwordGeneratorMock.Verify_GetRandomAlphanumericString_Called_Once();
            passwordHasherMock.Verify_HashPassword_Called_Once();

            Assert.IsTrue(Context.Lectors.Where(x => x.Id == id).Count() == 1);
        }
Beispiel #3
0
        public async Task <IActionResult> Create([FromBody] CreateLectorCommand command)
        {
            var(id, password) = await Mediator.Send(command);

            await Mediator.Send(new SendPasswordToNewLectorCommand { LectorId = id, Password = password });

            return(CreatedAtAction("Get", new { id }));
        }
Beispiel #4
0
        public async Task ThrowDuplicateException_WhenEmailExists()
        {
            var passwordHasherMock    = new Mock <IPasswordHasher>();
            var passwordGeneratorMock = new Mock <IPasswordGenerator>();

            var request = new CreateLectorCommand
            {
                Email            = "*****@*****.**",
                AcademicDegreeId = 1,
                AcademicRankId   = 1,
                FirstName        = "Name 3",
                LastName         = "LastName 3",
                Patronymic       = "Patronymic 3",
                PhoneNumber      = "+3333333333"
            };

            var handler = new CreateLectorCommandHandler(Context, passwordHasherMock.Object, passwordGeneratorMock.Object);

            var exception = Assert.ThrowsAsync <DuplicateException>(async() => await handler.Handle(request, CancellationToken.None));

            Assert.AreEqual(exception.Message, ExceptionMessagesBuilderHelper.GetDuplicateExceptionMessage(nameof(Lector), "Email", request.Email));
        }