public async Task ViolationsForMultipleFieldsAreReturnedCorrectly()
        {
            var user    = new UserAdminObject();
            var columns = await GetUserDictionary();

            await user.MapObjectColumnsAsync(columns);

            //Get the required Fields
            var requiredFields = (await user.GetColumnsAsync()).Where(x => x.Validations.Count(y => y.GetType() == typeof(ValidationNotNull)) > 0);

            //Blank out their Data property
            foreach (var field in requiredFields)
            {
                field.Data = String.Empty;
            }

            // Validate the user
            var validationResults = await user.ValidateAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            // Make sure each blanked out required column exists in the returned validation violations
            foreach (var field in requiredFields)
            {
                Assert.IsTrue(validationResults.FirstOrDefault(x => x.Contains(field.ColumnName)) != null);
            }
        }
        public async Task UserArtifactIDIsSetAfterSuccessfullyImported()
        {
            var user       = new UserAdminObject();
            var userValues = await GetUserDictionary();

            await user.MapObjectColumnsAsync(userValues);

            await user.ImportAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockHelper.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            Assert.AreEqual(MockUserArtifactID, user.ArtifactId);
        }
        public async Task NoViolationsReturnedWhenUserSuccessfullyImported()
        {
            var user       = new UserAdminObject();
            var userValues = await GetUserDictionary();

            await user.MapObjectColumnsAsync(userValues);

            var result = await user.ImportAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockHelper.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            MockUserRepo.Verify(x => x.CreateSingle(It.IsAny <kCura.Relativity.Client.DTOs.User>()), Times.AtLeastOnce);
            Assert.IsTrue(!result.Any());
        }
        public async Task NoViolationsReturnedForValidUserModel()
        {
            var user    = new UserAdminObject();
            var columns = await GetUserDictionary();

            await user.MapObjectColumnsAsync(columns);

            var validationResult = await user.ValidateAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            Assert.IsTrue(!validationResult.Any());
            Assert.IsTrue(user.Validated);
        }
        public async Task ViolationReturnedForUserWithNullEmailAddress()
        {
            var user       = new UserAdminObject();
            var userValues = await GetUserDictionary();

            await user.MapObjectColumnsAsync(userValues);

            user.EmailAddress.Data = null;

            var result = await user.ImportAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockHelper.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            Assert.IsTrue(result.Any(x => x.Contains(Constant.Messages.Violations.NullValue)));
        }
        public async Task LoginMethodNotCreatedWhenViolationsExist()
        {
            var user       = new UserAdminObject();
            var userValues = await GetUserDictionary();

            // Remove Auth Fields to force a violation
            await CorruptUserValues(userValues);

            await user.MapObjectColumnsAsync(userValues);

            await user.ImportAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockHelper.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            MockLoginManager.Verify(x => x.SaveLoginProfileAsync(It.IsAny <LoginProfile>()), Times.Never());
        }
        public async Task ViolationReturnedWhenUserNotImported()
        {
            var user       = new UserAdminObject();
            var userValues = await GetUserDictionary();

            await CorruptUserValues(userValues);

            await user.MapObjectColumnsAsync(userValues);

            var result = await user.ImportAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockHelper.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            Assert.IsTrue(result != null);
            Assert.IsTrue(result.Any());
        }
        public async Task PasswordValidationAutomaticallyAddedAfterValidateAsyncCalled()
        {
            var user    = new UserAdminObject();
            var columns = await GetUserDictionary();

            await user.MapObjectColumnsAsync(columns);

            var passwordColumns = (await user.GetColumnsAsync()).Where(x => x.ObjectFieldType == Constant.Enums.ObjectFieldType.PasswordLoginMethod);

            Assert.IsFalse(await ValidationExistsInSelectedColumns(passwordColumns, typeof(ValidationPasswordLoginMethod)));
            await user.ValidateAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            Assert.IsTrue(await ValidationExistsInSelectedColumns(passwordColumns, typeof(ValidationPasswordLoginMethod)));
        }
        public async Task UserNotCreatedWhenViolationsExist()
        {
            var user       = new UserAdminObject();
            var userValues = await GetUserDictionary();

            // Remove Auth Fields to force a violation
            await CorruptUserValues(userValues);

            await user.MapObjectColumnsAsync(userValues);

            await user.ImportAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockHelper.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            MockUserRepo.Verify(x => x.CreateSingle(It.IsAny <kCura.Relativity.Client.DTOs.User>()), Times.Never());
            MockUserRepo.Verify(x => x.Create(It.IsAny <kCura.Relativity.Client.DTOs.User>()), Times.Never());
        }
Esempio n. 10
0
        public async Task GroupValidationAutomaticallyAddedAfterValidateAsyncCalled()
        {
            var user    = new UserAdminObject();
            var columns = await GetUserDictionary();

            await user.MapObjectColumnsAsync(columns);

            var codeNameColumns = new List <IObjectColumn> {
                user.Groups
            };

            Assert.IsFalse(await ValidationExistsInSelectedColumns(codeNameColumns, typeof(ValidationGroup)));
            await user.ValidateAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            Assert.IsTrue(await ValidationExistsInSelectedColumns(codeNameColumns, typeof(ValidationGroup)));
        }
Esempio n. 11
0
        public async Task CodeValidationAutomaticallyAddedAfterValidateAsyncCalled()
        {
            var user    = new UserAdminObject();
            var columns = await GetUserDictionary();

            await user.MapObjectColumnsAsync(columns);

            var codeNameColumns = new List <IObjectColumn> {
                user.Type, user.DocumentSkip, user.DefaultSelectedFileType, user.SkipDefaultPreference, user.DocumentViewer
            };

            Assert.IsFalse(await ValidationExistsInSelectedColumns(codeNameColumns, typeof(ValidationCodeName)));
            await user.ValidateAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            Assert.IsTrue(await ValidationExistsInSelectedColumns(codeNameColumns, typeof(ValidationCodeName)));
        }
Esempio n. 12
0
        public async Task UserIsPromptedToDeletePartiallyCreatedUserWhenSaveLoginMethodThrowsButUserWasStillPartiallyCreated()
        {
            // An exception being thrown from the SaveLoginProfileAsync() method indicates the login method was unable to be saved
            MockLoginManager.Setup(x => x.SaveLoginProfileAsync(It.IsAny <LoginProfile>())).Throws(new Exception());

            MockArtifactQueries
            .SetupSequence(x => x.FindUserByEmailAddressAsync(It.IsAny <APIOptions>(), It.IsAny <IGenericRepository <kCura.Relativity.Client.DTOs.User> >(), It.IsAny <String>()))
            .Returns(Task.FromResult((Int32?)null))                                     // First the user doesn't exist
            .Returns(Task.FromResult((Int32?)MockUserArtifactID));                      // After SaveLoginMethod throws, we want the 2nd call to find the user

            var user       = new UserAdminObject();
            var userValues = await GetUserDictionary();

            await user.MapObjectColumnsAsync(userValues);

            var result = await user.ImportAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockHelper.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            // Violations should be returned
            Assert.IsTrue(result.Any(x => x.Contains(Constant.ErrorMessages.UserPartiallyImportedPrepend)));
        }
Esempio n. 13
0
        public async Task UserNotAttemptedToBeImportedWhenUserAlreadyExists()
        {
            MockArtifactQueries
            .Setup(x => x.FindUserByEmailAddressAsync(It.IsAny <APIOptions>(), It.IsAny <IGenericRepository <kCura.Relativity.Client.DTOs.User> >(), It.IsAny <String>()))
            .Returns(Task.FromResult((Int32?)MockUserArtifactID));

            var user       = new UserAdminObject();
            var userValues = await GetUserDictionary();

            await user.MapObjectColumnsAsync(userValues);

            var result = await user.ImportAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockHelper.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            var expectedMsg = String.Format(Constant.ErrorMessages.UserAlreadyExists, (String)await user.EmailAddress.GetDataValueAsync());

            Assert.IsTrue(result.Contains(expectedMsg));

            // Create Single should not be called
            MockUserRepo.Verify(x => x.CreateSingle(It.IsAny <kCura.Relativity.Client.DTOs.User>()), Times.Never);
        }
Esempio n. 14
0
        public async Task UserIsNotPromptedToDeletePartiallyCreatedUserWhenRsapiCreateSingleSaysUserAlreadyExists()
        {
            MockUserRepo
            .Setup(x => x.CreateSingle(It.IsAny <kCura.Relativity.Client.DTOs.User>()))
            .Throws(new Exception("The entered E-Mail Address is already associated with a user"));

            MockArtifactQueries
            .SetupSequence(x => x.FindUserByEmailAddressAsync(It.IsAny <APIOptions>(), It.IsAny <IGenericRepository <kCura.Relativity.Client.DTOs.User> >(), It.IsAny <String>()))
            .Returns(Task.FromResult((Int32?)null))                                     // First the user doesn't exist
            .Returns(Task.FromResult((Int32?)MockUserArtifactID));                      // After Create single throws, we want the 2nd call to find the user

            var user       = new UserAdminObject();
            var userValues = await GetUserDictionary();

            await user.MapObjectColumnsAsync(userValues);

            var result = await user.ImportAsync(new APIOptions(), MockRSAPIRepositoryGroup.Object, MockArtifactQueries.Object, MockHelper.Object, MockDbContext.Object, MockSqlQueryHelper.Object);

            // Violations should be returned
            Assert.IsFalse(result.Any(x => x.Contains(Constant.ErrorMessages.UserPartiallyImportedPrepend)));
        }