예제 #1
0
        public async Task AuthenticationFailureTest(UserProfileEntity userProfile)
        {
            var mockUserProfileRepository = new Mock <IUserProfileRepository>();

            mockUserProfileRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <UserProfileEntity, bool> > >()))
            .Returns(Task.FromResult(EntityCollection.Where(x => userProfile.UserName.ToLower() == x.UserName.ToLower() && userProfile.PassKey == x.PassKey && !x.IsDeleted)));

            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.SetupGet(x => x.UserProfileRepository).Returns(mockUserProfileRepository.Object);

            var userProfileService = new Nt.Application.Services.User.UserProfileService(mockUnitOfWork.Object, null);
            await Assert.ThrowsAsync <InvalidPasswordOrUsernameException>(() => userProfileService.AuthenticateAsync(userProfile));
        }
예제 #2
0
        public async Task AuthenticationSuccessTest(UserProfileEntity userProfile)
        {
            var mockUserProfileRepository = new Mock <IUserProfileRepository>();

            mockUserProfileRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <UserProfileEntity, bool> > >()))
            .Returns(Task.FromResult(EntityCollection.Where(x => userProfile.UserName.ToLower() == x.UserName.ToLower() && userProfile.PassKey == x.PassKey && !x.IsDeleted)));

            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.SetupGet(x => x.UserProfileRepository).Returns(mockUserProfileRepository.Object);

            var userProfileService = new Nt.Application.Services.User.UserProfileService(mockUnitOfWork.Object, null);
            var result             = await userProfileService.AuthenticateAsync(userProfile);

            Assert.Equal(userProfile.UserName.ToLower(), result.UserName.ToLower());
        }
예제 #3
0
        public async Task CreateUserTestException(UserProfileEntity request, UserProfileEntity response)
        {
            var mockUserProfileRepository = new Mock <IUserProfileRepository>();

            mockUserProfileRepository.Setup(x => x.GetAsync(It.IsAny <Expression <Func <UserProfileEntity, bool> > >()))
            .Returns(Task.FromResult(EntityCollection.Where(x => x.UserName.Equals(request.UserName, StringComparison.InvariantCultureIgnoreCase) && !x.IsDeleted)));
            mockUserProfileRepository.Setup(x => x.CreateAsync(request))
            .Returns((UserProfileEntity req) => Task.FromResult(request));

            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.SetupGet(x => x.UserProfileRepository).Returns(mockUserProfileRepository.Object);

            var userProfileService = new Nt.Application.Services.User.UserProfileService(mockUnitOfWork.Object, null);
            await Assert.ThrowsAsync <UserNameExistsException>(() => userProfileService.CreateUserAsync(request));

            mockUserProfileRepository.Verify(mock => mock.GetAsync(It.IsAny <Expression <Func <UserProfileEntity, bool> > >()), Times.Once());
            mockUserProfileRepository.Verify(mock => mock.CreateAsync(It.IsAny <UserProfileEntity>()), Times.Never());
        }