Пример #1
0
        public void GetUserByUserName_UserNotFoundBusinessLogicTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _userManager = UserManagerMoqs.GetImplemented(testInfo);
            _testObject  = new UserService(_userManager, _roleManager, _profileService, _mapper);
            var userName = testInfo.NewUser.UserName;

            Assert.Throws <BusinessLogicException>(() => _testObject.GetUserByUserName(userName));
            _userManager.Received().FindByNameAsync(userName);
        }
Пример #2
0
        public void ResetPasswordAsyncTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _userManager = UserManagerMoqs.GetImplemented(testInfo);
            _testObject  = new UserService(_userManager, _roleManager, _profileService, _mapper);
            var existedUser = testInfo.GetExitedUser(_mapper);

            Assert.DoesNotThrow(() => _testObject.ResetPasswordAsync(existedUser.UserName, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()));

            _userManager.Received().ResetPasswordAsync(Arg.Any <int>(), Arg.Any <string>(), Arg.Any <string>());
        }
Пример #3
0
        public void RecoverUserAsyncTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _userManager = UserManagerMoqs.GetImplemented(testInfo);
            _testObject  = new UserService(_userManager, _roleManager, _profileService, _mapper);
            var existedUser = testInfo.GetExitedUser(_mapper);

            Assert.DoesNotThrow(() => _testObject.RecoverUserAsync(existedUser.UserName));

            _userManager.Received().GeneratePasswordResetTokenAsync(Arg.Any <int>());
            _userManager.Received().SendEmailAsync(Arg.Any <int>(), Arg.Any <string>(), Arg.Any <string>());
        }
Пример #4
0
        public void ResetPasswordAsync_CreatingErrorBusinesslogicTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _userManager = UserManagerMoqs.GetImplemented(testInfo);
            _testObject  = new UserService(_userManager, _roleManager, _profileService, _mapper);
            var     existedUser = testInfo.GetExitedUser(_mapper);
            UserDto user        = null;

            testInfo.Error = "Creating error";

            Assert.ThrowsAsync <BusinessLogicException>(() => _testObject.ResetPasswordAsync(existedUser.UserName, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()));
            _userManager.Received().ResetPasswordAsync(Arg.Any <int>(), Arg.Any <string>(), Arg.Any <string>());
        }
Пример #5
0
        public void AuthenticateUser_NotFoundUserBusinessLogicExceptionTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _userManager = UserManagerMoqs.GetImplemented(testInfo);
            _testObject  = new UserService(_userManager, _roleManager, _profileService, _mapper);

            Assert.ThrowsAsync <BusinessLogicException>(() => _testObject.AuthenticateUserAsync(testInfo.NewUser));

            _userManager.Received().FindByNameAsync(Arg.Any <string>());
            _userManager.DidNotReceive().IsEmailConfirmedAsync(Arg.Any <int>());
            _userManager.DidNotReceive().CheckPasswordAsync(Arg.Any <User>(), Arg.Any <string>());
            _userManager.DidNotReceive().CreateIdentityAsync(Arg.Any <User>(), Arg.Any <string>());
        }
Пример #6
0
        public void AuthenticateUserTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _userManager = UserManagerMoqs.GetImplemented(testInfo);
            _testObject  = new UserService(_userManager, _roleManager, _profileService, _mapper);

            Assert.DoesNotThrowAsync(() => _testObject.AuthenticateUserAsync(testInfo.GetExitedUser(_mapper)));

            _userManager.Received().FindByNameAsync(Arg.Any <string>());
            _userManager.Received().IsEmailConfirmedAsync(Arg.Any <int>());
            _userManager.Received().CheckPasswordAsync(Arg.Any <User>(), Arg.Any <string>());
            _userManager.Received().CreateIdentityAsync(Arg.Any <User>(), Arg.Any <string>());
        }
Пример #7
0
        public void CreateUserAsync_UserExistsBusinesslogicExceptionTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _userManager = UserManagerMoqs.GetImplemented(testInfo);
            _testObject  = new UserService(_userManager, _roleManager, _profileService, _mapper);

            Assert.ThrowsAsync <BusinessLogicException>(() => _testObject.CreateUserAsync(testInfo.GetExitedUser(_mapper)));

            _userManager.Received().FindByNameAsync(Arg.Any <string>());
            _roleManager.DidNotReceive().FindByNameAsync(Arg.Any <string>());
            _userManager.DidNotReceive().CreateAsync(Arg.Any <User>(), Arg.Any <string>());
            _profileService.DidNotReceive().CreateProfile(Arg.Any <ProfileDto>());
            _userManager.DidNotReceive().GenerateEmailConfirmationTokenAsync(Arg.Any <int>());
            _userManager.DidNotReceive().SendEmailAsync(Arg.Any <int>(), Arg.Any <string>(), Arg.Any <string>());
        }
Пример #8
0
        public void CreateUserAsyncTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _profileService = ProfileServiceMoqs.GetImplemented();
            _roleManager    = RoleManagerMoqs.GetImplemented(testInfo);
            _userManager    = UserManagerMoqs.GetImplemented(testInfo);
            _testObject     = new UserService(_userManager, _roleManager, _profileService, _mapper);

            Assert.DoesNotThrowAsync(() => _testObject.CreateUserAsync(testInfo.NewUser));

            _userManager.Received().FindByNameAsync(Arg.Any <string>());
            _roleManager.Received().FindByNameAsync(Arg.Any <string>());
            _userManager.Received().CreateAsync(Arg.Any <User>(), Arg.Any <string>());
            _profileService.Received().CreateProfile(Arg.Any <ProfileDto>());
            _userManager.Received().GenerateEmailConfirmationTokenAsync(Arg.Any <int>());
            _userManager.Received().SendEmailAsync(Arg.Any <int>(), Arg.Any <string>(), Arg.Any <string>());
        }
Пример #9
0
        public void ConfirmUserEmailAsyncTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _userManager = UserManagerMoqs.GetImplemented(testInfo);
            _testObject  = new UserService(_userManager, _roleManager, _profileService, _mapper);
            var existedUser = testInfo.GetExitedUser(_mapper);

            UserDto user = null;

            Assert.DoesNotThrow(() =>
            {
                user = _testObject.ConfirmUserEmailAsync(existedUser.UserName, Guid.NewGuid().ToString()).Result;
            });

            _userManager.Received().ConfirmEmailAsync(Arg.Any <int>(), Arg.Any <string>());
            Assert.NotNull(user);
        }
Пример #10
0
        public void GetUserByUserNameTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _userManager = UserManagerMoqs.GetImplemented(testInfo);
            _testObject  = new UserService(_userManager, _roleManager, _profileService, _mapper);
            var userName = testInfo.GetExitedUser(_mapper).UserName;

            UserDto user = null;

            Assert.DoesNotThrow(() =>
            {
                user = _testObject.GetUserByUserName(userName);
            });

            Assert.AreEqual(user.UserName, userName);
            _userManager.Received().FindByNameAsync(userName);
        }
Пример #11
0
        public void GetUserByEmailTest()
        {
            TestInfo testInfo = GetDefaultTestInfo();

            _userManager = UserManagerMoqs.GetImplemented(testInfo);
            _testObject  = new UserService(_userManager, _roleManager, _profileService, _mapper);
            var email = testInfo.GetExitedUser(_mapper).Email;

            UserDto user = null;

            Assert.DoesNotThrow(() =>
            {
                user = _testObject.GetUserByEmail(email);
            });

            Assert.AreEqual(user.Email, email);
            _userManager.Received().FindByEmailAsync(email);
        }