コード例 #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());
        }