private static SSAuthInterfaces.UserAuth GetUserAuthByUserNameWithFunctionalPermissions(MongoDatabase mongoDatabase, string userNameOrEmail, UserRepository userRepository = null)
		{
			if (userRepository == null)
			{
				// TODO:  Inject UserRepository from Top Level
				Container container = EndpointHost.Config.ServiceManager.Container;
				userRepository = container.Resolve<UserRepository>();
			}

			if (!string.IsNullOrEmpty(userNameOrEmail))
			{
			UserEntity userEntity = userRepository.Read(userNameOrEmail);

			if(!userEntity.Active)
					throw new AccessViolationException("User not Active!");

			SSAuthInterfaces.UserAuth userAuth = TranslateToUserAuth(userEntity);

			if (userAuth != null)
			{
				userAuth.Permissions = PermissionUtility.GetFunctionalPermissionNamesForRoleIdsAndDomainPermissions(userEntity.Roles,
				userEntity.DomainPermissions, userEntity.TimeZoneId);
			}

			return userAuth;
		}

			return null;
		}
		public void ShouldReadUserWithUserName()
		{
			// Arrange
			UserRepository repository = new UserRepository(ConfigSettings.UserDatabaseConnectionName);
			UserEntity entity = UserData.GetUserForInsert();
			repository.ClearCollection();
			entity = repository.Create(entity);

			// Act
			UserEntity actual = repository.Read(entity.UserName);

			// Assert
			Assert.AreEqual(entity.Id, actual.Id);
		}
		private static SSAuthInterfaces.UserAuth GetUserAuthByUserName(MongoDatabase mongoDatabase, string userNameOrEmail, UserRepository userRepository = null)
		{
			if (userRepository == null)
			{
				// TODO:  Inject UserRepository from Top Level
				Container container = EndpointHost.Config.ServiceManager.Container;
				userRepository = container.Resolve<UserRepository>();
			}

			UserEntity userEntity = userRepository.Read(userNameOrEmail);

			SSAuthInterfaces.UserAuth userAuth = TranslateToUserAuth(userEntity);

			if (userAuth != null)
			{
				userAuth.Permissions = PermissionUtility.GetPermissionNamesForRoleIdsAndDomainPermissions(userEntity.Roles,
					userEntity.DomainPermissions, userEntity.TimeZoneId);
				//userAuth.Permissions = new List<string>();
				//userAuth.Permissions.Add("DomainPermission_Get");
				//userAuth.Permissions.Add("DomainPermission_Put");
				//userAuth.Permissions.Add("DomainPermission_Post");
				//userAuth.Permissions.Add("DomainPermission_Delete");
				//userAuth.Permissions.Add("DomainPermissions_Get");
				//userAuth.Permissions.Add("FunctionalPermission_Get");
				//userAuth.Permissions.Add("FunctionalPermission_Put");
				//userAuth.Permissions.Add("FunctionalPermission_Post");
				//userAuth.Permissions.Add("FunctionalPermission_Delete");
				//userAuth.Permissions.Add("CurrentUserAuthRequest_Get");
				//userAuth.Permissions.Add("LevelLists_Get");
				//userAuth.Permissions.Add("LevelLists_Put");
				//userAuth.Permissions.Add("LocalizationDictionaryRequest_Get");
				//userAuth.Permissions.Add("LocalizationDictionaryRequest_Put");
				//userAuth.Permissions.Add("LocalizationDictionaryRequest_Post");
				//userAuth.Permissions.Add("Permission_Get");
				//userAuth.Permissions.Add("Permission_Put");
				//userAuth.Permissions.Add("Permission_Post");
				//userAuth.Permissions.Add("Permissions_Get");
				//userAuth.Permissions.Add("Role_Get");
				//userAuth.Permissions.Add("Role_Put");
				//userAuth.Permissions.Add("Role_Post");
				//userAuth.Permissions.Add("Role_Delete");
				//userAuth.Permissions.Add("Roles_Get");
				//userAuth.Permissions.Add("User_Get");
				//userAuth.Permissions.Add("User_Put");
				//userAuth.Permissions.Add("User_Post");
				//userAuth.Permissions.Add("Users_Get");
				//userAuth.Permissions.Add("Users_Post");
			}

			return userAuth;
		}
		public void ShouldReadUserWithIdList()
		{
			// Arrange
			UserRepository repository = new UserRepository(ConfigSettings.UserDatabaseConnectionName);
			List<UserEntity> entities = UserData.GetUsersForInsert();
			repository.ClearCollection();
			entities = repository.Create(entities);
			List<long> userNames = entities.Select(x => x.Id).ToList();

			// Act
			List<UserEntity> actual = repository.Read(userNames);

			// Assert
			Assert.AreEqual(entities.Count, actual.Count);
		}