public void Add_New_User() { User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true, }; IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork); User addedUser = repository.AddUser(newUser); // Check if a non-null user is returned from the call Assert.IsNotNull(addedUser); // Check id the DbContext cached the user object in its local User collection Assert.IsTrue(testDBContext.Users.Local.Count == 1); // Check if the locally cached user object has the same data as the new User that was added above Assert.AreEqual(testDBContext.Users.Local[0].NameIdentifier, newUser.NameIdentifier); // Check if the state of the added user is set to Added Assert.AreEqual(testDBContext.GetEntityState(addedUser), EntityState.Added); testDBContext.Commit(); User retrieved = testDBContext.Users.Find(1); }
public User RegisterUser(User user) { Check.IsNotNull<User>(user, "user"); Check.IsNotEmptyOrWhiteSpace(user.NameIdentifier, "user.NameIdentifier"); try { User existingUser = this.userRepository.GetUserByNameIdentifier(user.NameIdentifier); if (null != existingUser) { throw new UserAlreadyExistsException() { NameIdentifier = user.NameIdentifier, IdentityProvider = user.IdentityProvider }; } user.CreatedOn = DateTime.UtcNow; user.ModifiedOn = DateTime.UtcNow; user.IsActive = true; user.UserRoles.Add(new UserRole() { RoleId = (int)Roles.User }); User registeredUser = this.userRepository.AddUser(user); unitOfWork.Commit(); // TODO: v-rajask, The code below was added to return the roles. // Entity framework does not pupoulate the complete graph (it only // populates the keys. Role object on UserRole is empty. This // issue needs investigation and proper fix. Role userRole = new Role() { Name = Roles.User.ToString() }; registeredUser.UserRoles.First().Role = userRole; return registeredUser; } catch (UnitOfWorkCommitException uowce) { throw new UserDataUpdateException("Failed to register user.", uowce); } }
public void Get_User_With_Roles_For_Valid_NameIdentifier() { // Prepare User fakeUser = new User() { UserId = 1, NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true, UserRoles = { new UserRole { RoleId=2, UserId=1, Role = new Role(){ Name = "User" } } } }; IUnitOfWork unitOfWork = new Fakes.StubIUnitOfWork(); IUserRepository userRepository = new Fakes.StubIUserRepository() { GetUserByNameIdentifierString = (nameIdentifier) => { return fakeUser; } }; // Perform IUserService userService = new UserServiceProvider(userRepository, unitOfWork); User retrievedUser = userService.GetUserWithRolesByNameIdentifier("s0Me1De9Tf!Er$tRing"); // Assert Assert.IsNotNull(retrievedUser); Assert.AreEqual(retrievedUser.NameIdentifier, fakeUser.NameIdentifier); Assert.IsTrue(retrievedUser.UserRoles.Count > 0); }
public void Initialize() { // Unit of work code this.unitOfWork = new StubIUnitOfWork() { Commit = () => { return; } }; // User repository this.userRepository = new StubIUserRepository() { GetUserbyUserIdInt32 = (userId) => { List<UserRole> userRoles = new List<UserRole>(); userRoles.Add(new UserRole() { Role = null, RoleId = 1, UserId = userId, UserRoleId = 1 }); User userNew = new User() { CreatedOn = DateTime.UtcNow, EmailId = "*****@*****.**", FirstName = "First", IdentityProvider = "identity", IsActive = true, LastName = "Last", MiddleName = "midele", ModifiedOn = DateTime.UtcNow, NameIdentifier = "nameIdentifier", Organization = "Test Org", UserAttributes = null, UserId = userId, UserRoles = userRoles }; return userNew; } }; // File repository implementation this.fileRepository = new StubIFileRepository() { GetFilesByRepositoryInt32 = (repositoryId) => { File fileToAdd = new File() { Citation = "Citation 1", CreatedBy = 1, CreatedOn = DateTime.Now, Description = "Document 1", FileAttributes = null, FileColumns = null, FileId = 1, FileQualityChecks = null, Identifier = "asdahgsdfsghadfsghad", isDeleted = false, MimeType = "Mime type 1", ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Document One", Repository = null, RepositoryId = 1, Size = 20.90, Status = "Uploaded", Title = "Document 1" }; File fileToAdd1 = new File() { Citation = "Citation 2", CreatedBy = 1, CreatedOn = DateTime.Now, Description = "Document 2", FileAttributes = null, FileColumns = null, FileId = 2, FileQualityChecks = null, Identifier = "wrwe23423ewr", isDeleted = false, MimeType = "Mime type 2", ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Document Two", Repository = null, RepositoryId = 1, Size = 20.90, Status = "Posted", Title = "Document 2" }; List<File> lstFiles = new List<File>(); lstFiles.Add(fileToAdd); lstFiles.Add(fileToAdd); return lstFiles; }, DeleteFileInt32StringBooleanBoolean = (fileId, status, isFileData, isHardDelete) => { return true; }, UpdateFileFile = (modifiedFile) => { return null; } }; // Repository details fake implementation this.repositoryDetails = new StubIRepositoryDetails() { RetrieveRepositories = () => { Repository repositoryObject = new Repository() { AllowedFileTypes = "xlsx,nc,csv", CreatedBy = 1, /// Files = null, CreatedOn = DateTime.Now, HttpDeleteUriTemplate = "http://test.com", HttpGetUriTemplate = "http://test.com", HttpIdentifierUriTemplate = "http://test.com", HttpPostUriTemplate = "http://test.com", ImpersonatingPassword = "******", ImpersonatingUserName = "******", IsActive = true, IsImpersonating = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Repository1", RepositoryId = 1, UserAgreement = "Test Agreement1", BaseRepositoryId = 1, IsVisibleToAll = true }; Repository repositoryObject1 = new Repository() { AllowedFileTypes = "xlsx,csv", CreatedBy = 1, //Files = null, CreatedOn = DateTime.Now, HttpDeleteUriTemplate = "http://gmail.com", HttpGetUriTemplate = "http://gmail.com", HttpIdentifierUriTemplate = "http://gmail.com", HttpPostUriTemplate = "http://gmail.com", ImpersonatingPassword = "******", ImpersonatingUserName = "******", IsActive = true, IsImpersonating = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Repository2", RepositoryId = 2, UserAgreement = "Test Agreement1", BaseRepositoryId = 1, IsVisibleToAll = true }; List<Repository> lstRep = new List<Repository>(); lstRep.Add(repositoryObject); lstRep.Add(repositoryObject1); return lstRep; }, RetrieveRepositoryTypes = () => { List<BaseRepository> lstBaseRep = new List<BaseRepository>(); lstBaseRep.Add(new BaseRepository() { BaseRepositoryId = 1, Name = "Merritt" }); lstBaseRep.Add(new BaseRepository() { BaseRepositoryId = 2, Name = "Sky" }); return lstBaseRep; }, AddRepositoryRepository = (repository) => { repository.RepositoryId = 10; repository.Name = "From add method"; return repository; }, UpdateRepositoryRepository = (repository) => { repository.Name = "From update method"; return repository; }, GetRepositoryByIdInt32 = (repositoryId) => { Repository repositoryObject = new Repository() { AllowedFileTypes = "xlsx,nc,csv", CreatedBy = 1, /// Files = null, CreatedOn = DateTime.Now, HttpDeleteUriTemplate = "http://test.com", HttpGetUriTemplate = "http://test.com", HttpIdentifierUriTemplate = "http://test.com", HttpPostUriTemplate = "http://test.com", ImpersonatingPassword = "******", ImpersonatingUserName = "******", IsActive = true, IsImpersonating = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Get by id method", RepositoryId = repositoryId, UserAgreement = "Test Agreement1", BaseRepositoryId = 1, IsVisibleToAll = true }; return repositoryObject; }, GetBaseRepositoryNameInt32 = (baseRepositoryId) => { return "base rep Name"; }, DeleteRepositoryInt32 = (repositoryId) => { Repository repositoryObject = new Repository() { AllowedFileTypes = "xlsx,nc,csv", CreatedBy = 1, /// Files = null, CreatedOn = DateTime.Now, HttpDeleteUriTemplate = "http://test.com", HttpGetUriTemplate = "http://test.com", HttpIdentifierUriTemplate = "http://test.com", HttpPostUriTemplate = "http://test.com", ImpersonatingPassword = "******", ImpersonatingUserName = "******", IsActive = true, IsImpersonating = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Delete rep method", RepositoryId = repositoryId, UserAgreement = "Test Agreement1", BaseRepositoryId = 1, IsVisibleToAll = true }; return repositoryObject; }, GetRepositoryByNameString = (repositoryName) => { Repository repositoryObject = new Repository() { AllowedFileTypes = "xlsx,nc,csv", CreatedBy = 1, /// Files = null, CreatedOn = DateTime.Now, HttpDeleteUriTemplate = "http://test.com", HttpGetUriTemplate = "http://test.com", HttpIdentifierUriTemplate = "http://test.com", HttpPostUriTemplate = "http://test.com", ImpersonatingPassword = "******", ImpersonatingUserName = "******", IsActive = true, IsImpersonating = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = repositoryName, RepositoryId = 12, UserAgreement = "Test Agreement1", BaseRepositoryId = 1, IsVisibleToAll = true }; return repositoryObject; } }; this.repsoitoryService = new RepositoriesService.RepositoryService(repositoryDetails, unitOfWork, userRepository, fileRepository); }
private void AddDefaultData() { User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true, UserAttributes = null }; // User with userid 1 AddUser(newUser); // Adding metadata types MetadataType metaType = new MetadataType() { MetadataTypeId = 1, Name = "Text", Status = true }; MetadataType metaType1 = new MetadataType() { MetadataTypeId = 2, Name = "Numaric", Status = true }; MetadataType metaType2 = new MetadataType() { MetadataTypeId = 3, Name = "Email", Status = true }; AddMetaDataType(metaType); AddMetaDataType(metaType1); AddMetaDataType(metaType2); BaseRepository baseRepo = new BaseRepository() { BaseRepositoryId = 1, Name = "Merrit" }; AddBaseRepository(baseRepo); Repository repositoryObject = new Repository() { AllowedFileTypes = "xlsx,nc,csv", CreatedBy = 1, /// Files = null, CreatedOn = DateTime.Now, HttpDeleteUriTemplate = "http://google.com", HttpGetUriTemplate = "http://google.com", HttpIdentifierUriTemplate = "http://google.com", HttpPostUriTemplate = "http://google.com", ImpersonatingPassword = "******", ImpersonatingUserName = "******", IsActive = true, IsImpersonating = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Repository1", RepositoryId = 1, UserAgreement = "Test Agreement1", BaseRepositoryId = 1, IsVisibleToAll = true }; Repository repositoryObject1 = new Repository() { AllowedFileTypes = "xlsx,csv", CreatedBy = 1, //Files = null, CreatedOn = DateTime.Now, HttpDeleteUriTemplate = "http://gmail.com", HttpGetUriTemplate = "http://gmail.com", HttpIdentifierUriTemplate = "http://gmail.com", HttpPostUriTemplate = "http://gmail.com", ImpersonatingPassword = "******", ImpersonatingUserName = "******", IsActive = true, IsImpersonating = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Repository2", RepositoryId = 2, UserAgreement = "Test Agreement1", BaseRepositoryId = 1, IsVisibleToAll = true }; // Adding 2 new repositories AddRepository(repositoryObject); AddRepository(repositoryObject1); // Adding repository metadata and metadata fields RepositoryMetadata repMetadata = new RepositoryMetadata() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, IsActive = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Merrit Test metadata", RepositoryId = 1, RepositoryMetadataId = 1, RepositoryMetadataFields = null }; AddRepositoryMetadata(repMetadata); RepositoryMetadataField repMDField = new RepositoryMetadataField() { Description = "Create Name", IsRequired = true, Mapping = "Test Mapping", MetadataTypeId = 1, Name = "Create Name", Order = 1, Range = "", RepositoryMetadataFieldId = 1, RepositoryMetadataId = 1 }; RepositoryMetadataField repMDField1 = new RepositoryMetadataField() { Description = "Create Phone", IsRequired = true, Mapping = "Test Mapping", MetadataTypeId = 1, Name = "Create Phone", Order = 2, Range = "", RepositoryMetadataFieldId = 2, RepositoryMetadataId = 1 }; RepositoryMetadataField repMDField2 = new RepositoryMetadataField() { Description = "Create Email", IsRequired = true, Mapping = "Test Mapping", MetadataTypeId = 1, Name = "Create Email", Order = 3, Range = "", RepositoryMetadataFieldId = 3, RepositoryMetadataId = 1 }; AddRepositoryMetadataFields(repMDField); AddRepositoryMetadataFields(repMDField1); AddRepositoryMetadataFields(repMDField2); }
private void AddDefaultData() { User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "TestFirstName", MiddleName = "TestMiddleName", LastName = "TestLastName", IdentityProvider = "Windows Live", Organization = "TestOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true, UserAttributes = null }; // User with userid 1 AddUser(newUser); // RepositoryType repoType1 = new RepositoryType() { IsActive = true, Name = "type1", RepositoryTypeId = 1, Repositories = null }; // Adding new repository types // AddRepositoryType(repoType1); BaseRepository baseRepo = new BaseRepository() { BaseRepositoryId = 1, Name = "Merrit" }; AddBaseRepository(baseRepo); Repository repositoryObject = new Repository() { AllowedFileTypes = "xlsx,nc,csv", CreatedBy = 1, // Files = null, CreatedOn = DateTime.Now, HttpDeleteUriTemplate = "http://google.com", HttpGetUriTemplate = "http://google.com", HttpIdentifierUriTemplate = "http://google.com", HttpPostUriTemplate = "http://google.com", ImpersonatingPassword = "******", ImpersonatingUserName = "******", IsActive = true, IsImpersonating = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Repository1", RepositoryId = 1, UserAgreement = "Test Agreement1", BaseRepositoryId = 1 }; AddRepository(repositoryObject); File fileToAdd = new File() { Citation = "Citation 1", CreatedBy = 1, CreatedOn = DateTime.Now, Description = "Document 1", FileAttributes = null, FileColumns = null, FileId = 1, FileQualityChecks = null, Identifier = "asdahgsdfsghadfsghad", isDeleted = false, MimeType = "Mime type 1", ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Document One", Repository = null, RepositoryId = 1, Size = 20.90, Status = "Uploaded", Title = "Document 1" }; File fileToAdd1 = new File() { Citation = "Citation 2", CreatedBy = 1, CreatedOn = DateTime.Now, Description = "Document 2", FileAttributes = null, FileColumns = null, FileId = 2, FileQualityChecks = null, Identifier = "wrwe23423ewr", isDeleted = false, MimeType = "Mime type 2", ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Document Two", Repository = null, RepositoryId = 1, Size = 20.90, Status = "Uploaded", Title = "Document 2" }; AddFile(fileToAdd); AddFile(fileToAdd1); FileColumnUnit fileUnit = new FileColumnUnit() { Name = "Text", Status = true }; AddFileColumnUnit(fileUnit); FileColumnType fileType = new FileColumnType() { Name = "Acre", Status = true }; AddFileColumnType(fileType); }
public User AddUser(User newUser) { Check.IsNotNull<User>(newUser, "newUser"); return Context.Users.Add(newUser); }
/// <summary> /// Initializes a new instance of the <see cref="UserDataUpdateException"/> class. /// </summary> /// <param name="info">Serialized object data</param> /// <param name="context">Source and destination of a given serialized stream</param> private UserDataUpdateException(SerializationInfo info, StreamingContext context) : base(info, context) { this.user = info.GetValue(UserKeyName, typeof(User)) as User; }
/// <summary> /// Downloads the File from Repository /// </summary> /// <param name="file">File object.</param> /// <param name="repository">Repository instance.</param> /// <param name="user">User instance.</param> /// <param name="credentials">credentials required by the repository.</param> /// <returns>DataFile containing the file data.</returns> public virtual DataFile DownLoadFileFromRepository(DM.File file, Repository repository, User user, RepositoryCredentials credentials) { throw new NotSupportedException(); }
private void AddUserWithDefaultRoles(User user) { Role addedUserRole = testDBContext.Roles.Where(r => r.Name.Equals(UserRoleName)).FirstOrDefault() as Role; Role addedAdminRole = testDBContext.Roles.Where(r => r.Name.Equals(AdministratorRoleName)).FirstOrDefault() as Role; UserRole userUserRole = new UserRole() { RoleId = addedUserRole.RoleId }; UserRole adminUserRole = new UserRole() { RoleId = addedAdminRole.RoleId }; user.UserRoles = new List<UserRole>() { userUserRole, adminUserRole }; AddUser(user); }
public void Allow_New_User_Registration() { // Prepare User fakeUser = new User() { UserId = 1, NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true, UserRoles = { new UserRole { RoleId=2, UserId=1, Role = new Role(){ Name = "User" } } } }; IUserRepository userRepository = new Fakes.StubIUserRepository() { AddUserUser = (user) => { return fakeUser; } }; IUnitOfWork unitOfWork = new Fakes.StubIUnitOfWork() { Commit = () => { return; } }; User userToRegister = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**" }; // Act IUserService userService = new UserServiceProvider(userRepository, unitOfWork); User registeredUser = userService.RegisterUser(userToRegister); // Check if valid user is returned Assert.IsNotNull(registeredUser); // Check is a valid user id is associated with the registered user Assert.IsTrue(registeredUser.UserId > 0); // Check if inbound user data is same as the output Assert.AreEqual(registeredUser.NameIdentifier, userToRegister.NameIdentifier); Assert.AreEqual(registeredUser.UserRoles.Count, 1); Assert.IsNotNull(registeredUser.UserRoles.First().Role); Assert.AreEqual(registeredUser.UserRoles.First().Role.Name, "User"); }
public void Get_User_Attributes_For_Valid_User() { // Prepare UserAttribute userAttribute1 = new UserAttribute() { Key = "Key1", Value = "Value1" }; UserAttribute userAttribute2 = new UserAttribute() { Key = "Key2", Value = "Value2" }; User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true, UserAttributes = new List<UserAttribute>() { userAttribute1, userAttribute2 } }; AddUser(newUser); User addedUser = testDBContext.Users.Find(1); // Perform IUserRepository repository = new UserRepository(testDBContext); IEnumerable<UserAttribute> attributes = repository.GetUserAttributesByUserId(addedUser.UserId); // Check if a valid collection of user attributes is returned Assert.IsNotNull(attributes); // Check if the count of attributes is 2, since we added 2 attributes in the preparation code Assert.AreEqual(attributes.Count(), 2); // Check if attribute 1 is returned Assert.AreEqual(attributes.Count<UserAttribute>(ua => ua.Key.Equals(userAttribute1.Key)), 1); // Check is attribute 2 is returned Assert.AreEqual(attributes.Count<UserAttribute>(ua => ua.Key.Equals(userAttribute2.Key)), 1); }
public void Update_Existing_User() { // Prepare : // 1. Create a new user // 2. Fetch the added user // 3. Update user data User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true }; AddUser(newUser); User userToUpdate = testDBContext.Users.Find(1); userToUpdate.EmailId = "*****@*****.**"; userToUpdate.Organization = "somethingelseorganization"; // Perform update IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork); User updatedUser = repository.UpdateUser(userToUpdate); // Assert if the updated user object is valid Assert.IsNotNull(updatedUser); // Asset that the updated user is added to the tracked object in the context Assert.IsTrue(testDBContext.Users.Local.Count == 1); // Assert email id before and after update are same Assert.AreEqual(testDBContext.Users.Local[0].EmailId, userToUpdate.EmailId); // Assert organization before and after is the same Assert.AreEqual(testDBContext.Users.Local[0].Organization, userToUpdate.Organization); // Assert that the locally tracked user object to update has the modified entity state Assert.AreEqual(testDBContext.GetEntityState(updatedUser), EntityState.Modified); }
public void Get_UserRoles_For_Valid_UserId() { // Prepare AddDefaultRoles(); User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true }; AddUserWithDefaultRoles(newUser); User addedUser = testDBContext.Users.Find(1); // Perform IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork); IEnumerable<UserRole> userRoles = repository.GetUserRolesByUserId(addedUser.UserId); // Check if valid user roles collection is returned Assert.IsNotNull(userRoles); // Check if the count of items in user role collection is 2, since the preparation code // added 2 roles to user Assert.AreEqual(userRoles.Count(), 2); // Check if the administrator role exists Assert.AreEqual(userRoles.Count<UserRole>(r => r.RoleId.Equals(GetAdministratorRoleId())), 1); // Check if the user role exists Assert.AreEqual(userRoles.Count<UserRole>(r => r.RoleId.Equals(GetUserRoleId())), 1); }
public void Get_Existing_User_By_NameIdentifier() { AddDefaultRoles(); User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true }; AddUser(newUser); UserRole userRole = new UserRole() { UserId = 1, RoleId = 1 }; testDBContext.UserRoles.Add(userRole); testDBContext.Commit(); // Perform get IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork); User retrievedUser = repository.GetUserByNameIdentifier(newUser.NameIdentifier); // Check if a valid user is returned Assert.IsNotNull(retrievedUser); // Check if the name identifier matches Assert.AreEqual(newUser.NameIdentifier, retrievedUser.NameIdentifier); }
public void Add_User_Role() { // Prepare AddDefaultRoles(); User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true }; AddUser(newUser); User addedUser = testDBContext.Users.Find(1); UserRole userRole = new UserRole() { UserId = addedUser.UserId, RoleId = GetUserRoleId() }; // Perform IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork); UserRole addedUserRole = repository.AddUserRole(userRole); // Check if a valid user role is returned Assert.IsNotNull(addedUserRole); // Check if the count of tracked objects is 1 Assert.IsTrue(testDBContext.UserRoles.Local.Count == 1); // Check is the entity state of the added object is set to Added Assert.AreEqual(testDBContext.GetEntityState(addedUserRole), EntityState.Added); }
public void Throw_Exception_if_NameIdentifier_Is_Null_Empty_Or_Whitespace() { // Prepare IUserRepository userRepository = new Microsoft.Research.DataOnboarding.DataAccessService.Fakes.StubIUserRepository(); IUnitOfWork unitOfWork = new Fakes.StubIUnitOfWork(); User userToRegister = new User() { NameIdentifier = string.Empty, // Invalid name identifier FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**" }; // Act IUserService userService = new UserServiceProvider(userRepository, unitOfWork); User registeredUser = userService.RegisterUser(userToRegister); }
/// <summary> /// Downloads the File from Repository /// </summary> /// <param name="file">File object.</param> /// <param name="repository">Repository instance.</param> /// <param name="user">User instance.</param> /// <param name="credentials">credentials required by the repository.</param> /// <returns>DataFile containing the file data.</returns> public override DataFile DownLoadFileFromRepository(File file, Repository repository, User user, RepositoryCredentials credentials) { // construct the AuthToken object AuthToken authToken = new AuthToken() { UserId = user.UserId, RespositoryId = repository.RepositoryId }; if (credentials != null) { authToken.AccessToken = credentials[WindowsLiveAuthenticationCredentialKeys.AccessToken]; authToken.RefreshToken = credentials[WindowsLiveAuthenticationCredentialKeys.RefreshToken]; if (credentials[WindowsLiveAuthenticationCredentialKeys.TokenExpiresOn] != null) { DateTime tokenExpiryDate; if (DateTime.TryParse(credentials[WindowsLiveAuthenticationCredentialKeys.TokenExpiresOn], out tokenExpiryDate)) { authToken.TokenExpiresOn = tokenExpiryDate; }; } } this.RepositoryAdapter = this.RepositoryAdapterFactory.GetRepositoryAdapter(repository.BaseRepository.Name); // Retreive the AuthToken from database or save the token to database if access token is present in the credentials. authToken = this.GetOrUpdateAuthTokens(repository, authToken); DataFile dataFile = this.RepositoryAdapter.DownloadFile(file.Identifier, authToken.AccessToken, file.Name); return dataFile; }
public void Throw_Exception_On_Registering_Duplicate_NameIdentifier() { // Prepare User fakeUser = new User() { UserId = 1, NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true }; IUserRepository userRepository = new Microsoft.Research.DataOnboarding.DataAccessService.Fakes.StubIUserRepository() { GetUserByNameIdentifierString = (nameIdentifier) => { return fakeUser; } }; IUnitOfWork unitOfWork = new Fakes.StubIUnitOfWork() { Commit = () => { return; } }; User userToRegister = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**" }; // Act IUserService userService = new UserServiceProvider(userRepository, unitOfWork); try { User registeredUser = userService.RegisterUser(userToRegister); } catch (UserAlreadyExistsException uaee) { Assert.AreEqual(uaee.NameIdentifier, userToRegister.NameIdentifier); throw; } }
/// <summary> /// Initializes a new instance of the <see cref="UserDataUpdateException"/> class. /// </summary> /// <param name="message">Error message</param> /// <param name="user">user object</param> /// <param name="errors">Error collection</param> public UserDataUpdateException(string message, User user, ICollection<string> errors) : base(message, errors) { this.user = user; }
public void Throw_Exception_When_New_User_Registration_Fails() { // Prepare IUnitOfWork unitOfWork = new Fakes.StubIUnitOfWork(); IUserRepository userRepository = new Fakes.StubIUserRepository() { AddUserUser = (user) => { throw new UnitOfWorkCommitException("Some data update issue"); } }; User userToRegister = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**" }; // Perform IUserService userService = new UserServiceProvider(userRepository, unitOfWork); userService.RegisterUser(userToRegister); }
public void Add_User_Attribute() { // Prepare User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true }; AddUser(newUser); User addedUser = testDBContext.Users.Find(1); UserAttribute userAttribute = new UserAttribute() { UserId = addedUser.UserId, Key = "Key1", Value = "Value1" }; // Perform IUserRepository repository = new UserRepository(testDBContext as IUnitOfWork); UserAttribute addedUserAttribute = repository.AddUserAttribute(userAttribute); // Invalid user id passed // Check is a valid user attribute is returned Assert.IsNotNull(addedUserAttribute); // Check if the count of tracked objects in the data context is 1 Assert.IsTrue(testDBContext.UserAttributes.Local.Count == 1); // Check if the tracked object is the same one as the added user attribute Assert.AreEqual(testDBContext.UserAttributes.Local[0].Key, userAttribute.Key); // Check the entity state Assert.AreEqual(testDBContext.GetEntityState(addedUserAttribute), EntityState.Added); }
/// <summary> /// Downloads the File from Repository /// </summary> /// <param name="file">File object.</param> /// <param name="repository">Repository instance.</param> /// <param name="user">User instance.</param> /// <param name="credentials">credentials required by the repository.</param> /// <returns>DataFile containing the file data.</returns> public override DataFile DownLoadFileFromRepository(DomainModel.File file, Repository repository, User user, RepositoryCredentials credentials) { string userName = string.Empty; string password = string.Empty; if ((bool)repository.IsImpersonating) { userName = repository.ImpersonatingUserName; password = repository.ImpersonatingPassword; } else { userName = credentials[BasicAuthenticationCredentialKeys.UserName]; password = credentials[BasicAuthenticationCredentialKeys.Password]; if (string.IsNullOrEmpty(userName)) { throw new ArgumentNullException(BasicAuthenticationCredentialKeys.UserName); } if (string.IsNullOrEmpty(password)) { throw new ArgumentNullException(BasicAuthenticationCredentialKeys.Password); } } var authorization = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(userName /*UserName*/ + ":" + password/*Password*/)); if (string.IsNullOrEmpty(repository.HttpGetUriTemplate)) { throw new FileDownloadException() { FileId = file.FileId, RepositoryId = repository.RepositoryId, FileDownloadExceptionType = FileDownloadExceptionType.DownloadUrlNotFound.ToString() }; } var downloadURL = string.Join(string.Empty, repository.HttpGetUriTemplate, HttpUtility.UrlEncode(file.Identifier)); IRepositoryAdapter repAdapter = this.RepositoryAdapterFactory.GetRepositoryAdapter(repository.BaseRepository.Name); DataFile dataFile = repAdapter.DownloadFile(downloadURL, authorization, file.Name); return dataFile; }
public void Allow_Download() { BaseRepository baseRepository = new BaseRepository() { BaseRepositoryId = 2, Name = "SkyDrive" }; this.repository = new Repository() { BaseRepositoryId = 2, Name = "test", IsImpersonating = false, BaseRepository = baseRepository }; RepositoryCredentials repositoryCredentials = new RepositoryCredentials(); File file = new File() { FileId = 1 }; User user = new User() { UserId = 1 }; var fileProvider = this.GetSkyDriveFileService(); this.skyDriveAdapter = new Microsoft.Research.DataOnboarding.RepositoryAdapters.Interfaces.Fakes.StubIRepositoryAdapter() { PostFilePublishFileModel = (publishFileModel) => { OperationStatus status = OperationStatus.CreateFailureStatus("error"); return status; }, DownloadFileStringStringString = (identifier, accessToken, fileName) => { return new DataFile(); } }; DataFile result; using (ShimsContext.Create()) { ShimSkyDriveFileService.AllInstances.GetOrUpdateAuthTokensRepositoryAuthToken = (skyDriveFileService, repository, authToken) => new AuthToken(); result = fileProvider.DownLoadFileFromRepository(file, this.repository, user, repositoryCredentials); } Assert.IsNotNull(result); }
public void Initialize() { List<QualityCheckColumnRule> lstCol = new List<QualityCheckColumnRule>(); QualityCheckColumnRule colRule = new QualityCheckColumnRule() { Description = "Column 1 desc", ErrorMessage = "error msg", HeaderName = "Column 1", IsActive = true, IsRequired = true, Order = 1, QualityCheck = null, QualityCheckColumnRuleId = 1, QualityCheckColumnTypeId = 1, QualityCheckId = 1, Range = "" }; QualityCheckColumnRule colRule1 = new QualityCheckColumnRule() { Description = "Column 2 desc", ErrorMessage = "error msg1", HeaderName = "Column 2", IsActive = true, IsRequired = true, Order = 2, QualityCheck = null, QualityCheckColumnRuleId = 2, QualityCheckColumnTypeId = 2, QualityCheckId = 1, Range = "" }; lstCol.Add(colRule); lstCol.Add(colRule1); // Unit of work code this.unitOfWork = new StubIUnitOfWork() { Commit = () => { return; } }; // User repository this.userRepository = new StubIUserRepository() { GetUserbyUserIdInt32 = (userId) => { List<UserRole> userRoles = new List<UserRole>(); userRoles.Add(new UserRole() { Role = null, RoleId = 1, UserId = userId, UserRoleId = 1 }); User userNew = new User() { CreatedOn = DateTime.UtcNow, EmailId = "*****@*****.**", FirstName = "First", IdentityProvider = "identity", IsActive = true, LastName = "Last", MiddleName = "midele", ModifiedOn = DateTime.UtcNow, NameIdentifier = "nameIdentifier", Organization = "Test Org", UserAttributes = null, UserId = userId, UserRoles = userRoles }; return userNew; } }; // file Service implementation this.fileService = new StubIFileService() { GetFileByFileIdInt32 = (fileId) => { File fileToAdd = new File() { Citation = "Citation 1", CreatedBy = 1, CreatedOn = DateTime.Now, Description = "Document 1", FileAttributes = null, FileColumns = null, FileId = fileId, FileQualityChecks = null, Identifier = "asdahgsdfsghadfsghad", isDeleted = false, MimeType = "Mime type 1", ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Document One", Repository = null, RepositoryId = null, Size = 20.90, Status = "Uploaded", Title = "Document 1" }; return null; } }; // Quality check repository implementation this.qcRepository = new StubIQualityCheckRepository() { RetrieveQualityCheckRules = () => { List<QualityCheck> lstQCRule = new List<QualityCheck>(); lstQCRule.Add(new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Test Rule", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Test Rule", QualityCheckColumnRules = lstCol, QualityCheckId = 1 }); // lstQCRule.Add(new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Test Rule1", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Test Rule1", QualityCheckColumnRules = lstCol, QualityCheckId = 1 }); return lstQCRule; }, RetrieveQCColumnTypes = () => { List<QualityCheckColumnType> qcTypes = new List<QualityCheckColumnType>(); qcTypes.Add(new QualityCheckColumnType() { Description = "No check", Name = "None", QualityCheckColumnTypeId = 1 }); qcTypes.Add(new QualityCheckColumnType() { Description = "Number type", Name = "Numeric", QualityCheckColumnTypeId = 2 }); return qcTypes; }, GetQualityCheckByIDInt32 = (qualityCheckId) => { QualityCheck qc = new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Get by id desc", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Get by id Rule", QualityCheckColumnRules = lstCol, QualityCheckId = qualityCheckId }; return qc; }, AddQualityCheckRuleQualityCheck = (qualityCheck) => { qualityCheck.QualityCheckId = 2; return qualityCheck; }, UpdateQualityCheckRuleQualityCheck = (qualityCheck) => { qualityCheck.Name = "Updated rule From rep"; return qualityCheck; }, DeleteQualityCheckRuleInt32 = (qualityCheckId) => { QualityCheck qc = new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Delete", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Delete Rule", QualityCheckColumnRules = lstCol, QualityCheckId = qualityCheckId }; return qc; }, DeleteColumnRulesInt32 = (qualityCheckId) => { return true; }, AddFileQualityCheckFileQualityCheck = (fileQualityCheck) => { fileQualityCheck.Status = true; return fileQualityCheck; }, GetQualityCheckByNameString = (ruleName) => { QualityCheck qc = new QualityCheck() { CreatedBy = 1, CreatedOn = DateTime.UtcNow, Description = "Get by rule name", EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = ruleName, QualityCheckColumnRules = lstCol, QualityCheckId = 10 }; return qc; } }; qcService = new QCS.QCService(this.qcRepository, this.unitOfWork, this.userRepository, this.fileService, this.blobRepository); }
private void AddDefaultData() { User newUser = new User() { NameIdentifier = "s0Me1De9Tf!Er$tRing", FirstName = "SomeFirstName", MiddleName = "SomeMiddleName", LastName = "SomeLastName", IdentityProvider = "Windows Live", Organization = "SomeOrganization", EmailId = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, IsActive = true, UserAttributes = null }; // User with userid 1 AddUser(newUser); //Adding Quality check column rules data QualityCheckColumnType qcColType = new QualityCheckColumnType() { Description = "No type check", Name = "None", QualityCheckColumnTypeId = 1, QualityCheckColumnRules = null }; QualityCheckColumnType qcColType1 = new QualityCheckColumnType() { Description = "Number type", Name = "Numeric", QualityCheckColumnTypeId = 2, QualityCheckColumnRules = null }; AddQualityCheckColumnType(qcColType); AddQualityCheckColumnType(qcColType1); QualityCheck qcRule = new QualityCheck() { CreatedBy = 1, Description = "Test rule", CreatedOn = DateTime.UtcNow, EnforceOrder = true, FileQualityChecks = null, IsActive = true, IsVisibleToAll = true, ModifiedBy = 1, ModifiedOn = DateTime.UtcNow, Name = "Test Rule", QualityCheckId = 1, QualityCheckColumnRules = null }; AddQualityCheckRule(qcRule); QualityCheckColumnRule colRule = new QualityCheckColumnRule() { Description = "Column 1", ErrorMessage = "Col1 is required", HeaderName = "Col1", IsActive = true, IsRequired = true, Order = 1, QualityCheckColumnRuleId = 1, QualityCheckColumnTypeId = 1, QualityCheckId = 1, Range = "" }; QualityCheckColumnRule colRule1 = new QualityCheckColumnRule() { Description = "Column 2", ErrorMessage = "Col2 is required", HeaderName = "Col2", IsActive = true, IsRequired = false, Order = 2, QualityCheckColumnRuleId = 1, QualityCheckColumnTypeId = 2, QualityCheckId = 1, Range = "1-19999" }; AddQualityCheckColumnRule(colRule); AddQualityCheckColumnRule(colRule1); }
private void AddUser(User user) { IUserRepository repository = new UserRepository(testDBContext); User addedUser = repository.AddUser(user); testDBContext.Commit(); }
public User UpdateUser(User modifiedUser) { Check.IsNotNull<User>(modifiedUser, "modifiedUser"); User updatedUser = Context.Users.Attach(modifiedUser); Context.SetEntityState<User>(updatedUser, EntityState.Modified); return updatedUser; }