Esempio n. 1
0
        public async Task CheckIfUserExist_GivenUserModelAndLdapAuthMode_ReturnsFalse()
        {
            // Arrange
            var ldapAuthenticationModeRepository = Substitute.For <ILdapAuthenticationModeRepository>();
            var userRepository = Substitute.For <IUserRepository>();

            ldapAuthenticationModeRepository.GetByIdAsync(mockUserModel.LdapAuthenticationMode.Id, Arg.Any <bool>(), Arg.Any <bool>()).Returns(mockUserModel.LdapAuthenticationMode);
            var ldapConnectionService = new LdapConnectionService(ldapAuthenticationModeRepository, userRepository, mockedLdapConnectionClient, mockedLdapConnectionClient);

            // Act
            var checkResult = await ldapConnectionService.CheckIfUserExist(mockUserModel.UserName, mockUserModel.LdapAuthenticationMode.Id);

            // Assert
            Assert.False(checkResult, "Checking if an LDAP user exist should return false.");
        }
Esempio n. 2
0
        public async Task CheckIfUserExist_GivenUnfindableLdapAuthMode_ThrowsItemNotFoundException()
        {
            // Arrange
            var ldapAuthenticationModeRepository = Substitute.For <ILdapAuthenticationModeRepository>();
            var userRepository = Substitute.For <IUserRepository>();

            var ldapConnectionService = new LdapConnectionService(ldapAuthenticationModeRepository, userRepository, mockedLdapConnectionClient, mockedLdapConnectionClient);

            // Act
            Exception caughtEx = null;

            try
            {
                var checkResult = await ldapConnectionService.CheckIfUserExist(mockUserModel.UserName, mockUserModel.LdapAuthenticationMode.Id);
            }
            catch (Exception ex)
            {
                caughtEx = ex;
            }

            // Assert
            Assert.True(caughtEx is ItemNotFoundException, "Attempted user check with an unfindable LdapAuthMode must throw an ItemNotFoundException.");
        }