Example #1
0
        public async Task RemoveTwoFactorAuthenticationAsync_GivenCorrectGuid_ThrowsNoException()
        {
            var userRepository       = Substitute.For <IUserRepository>();
            var twoFactorAuthService = new TwoFactorAuthService(userRepository, customUserManagerFake);

            userRepository.GetByIdAsync(Guid.Parse(mockedUserModel.Id), Arg.Any <bool>()).Returns(mockedUserModel);

            var testGuid = Guid.NewGuid();

            userRepository.GetByIdAsync(testGuid, Arg.Any <bool>()).Returns(
                new UserModel()
            {
                Id         = testGuid.ToString(),
                UserTokens = new List <UserTokenModel>()
                {
                    new UserTokenModel(),
                    new UserTokenModel(),
                    new UserTokenModel(),
                }
            });

            await twoFactorAuthService.RemoveTwoFactorAuthenticationAsync(testGuid);

            Exception catchingException = null;

            try
            {
                await twoFactorAuthService.RemoveTwoFactorAuthenticationAsync(Guid.Parse(mockedUserModel.Id));
            }
            catch (Exception ex)
            {
                catchingException = ex;
                Assert.True(false);
            }

            Assert.True(catchingException is null);
        }
Example #2
0
        public async Task RemoveTwoFactorAuthenticationAsync_GivenEmptyGuid_ThrowsNotFoundException()
        {
            var userRepository       = Substitute.For <IUserRepository>();
            var twoFactorAuthService = new TwoFactorAuthService(userRepository, customUserManagerFake);

            Exception catchingException = null;

            try
            {
                await twoFactorAuthService.RemoveTwoFactorAuthenticationAsync(Guid.Empty);
            }
            catch (Exception ex)
            {
                catchingException = ex;
            }

            Assert.True(catchingException is ItemNotFoundException);
        }