コード例 #1
0
        public void Check_File_Exists()
        {
            StubIFileRepository fileRepository = new StubIFileRepository()
            {
                GetItemInt32String = (userId, fileName) =>
                {
                    return new File() { Name = "test", FileId = 100, Status = "Uploaded" };
                }
            };


            IUnitOfWork unitOfWork =
                new Fakes.StubIUnitOfWork()
                {
                    Commit = () => { return; }
                };
            StubIBlobDataRepository blobDataRepository = new StubIBlobDataRepository()
            {
                GetBlobContentString = (name) =>
                {
                    return new DataDetail();
                }
            };
            IRepositoryDetails repositoryDetails = new StubIRepositoryDetails();
            IRepositoryService repositoryService = new StubIRepositoryService();
            IRepositoryAdapterFactory repositoryAdapterFactory = new StubIRepositoryAdapterFactory();

            var fileProvider = new FileServiceProvider(fileRepository, blobDataRepository, unitOfWork, repositoryDetails, repositoryService, repositoryAdapterFactory);
            var result = fileProvider.CheckFileExists("test", 100);
            Assert.AreEqual(true, result);
            Assert.AreEqual(true, true);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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");
        }
コード例 #4
0
        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;
            }
        }
コード例 #5
0
        public void Throw_Exception_If_User_With_Given_Id_Does_Not_Exist()
        {
            // Prepare
            IUnitOfWork unitOfWork = new Fakes.StubIUnitOfWork();
            IUserRepository userRepository =
                new Fakes.StubIUserRepository()
                {
                    GetUserbyUserIdInt32 = (userId) => { return null; }
                };

            // Perform
            IUserService userService = new UserServiceProvider(userRepository, unitOfWork);
            userService.GetUserById(1);
        }
コード例 #6
0
        public void Throw_Exception_If_NameIdentifier_Is_Null_Empty_Or_Whitespace()
        {
            // Prepare
            IUnitOfWork unitOfWork = new Fakes.StubIUnitOfWork();
            IUserRepository userRepository = new Fakes.StubIUserRepository();

            // Perform
            IUserService userService = new UserServiceProvider(userRepository, unitOfWork);
            userService.GetUserWithRolesByNameIdentifier(" ");
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public void Throw_Exception_If_NameIdentifier_Does_Not_Exist()
        {
            // Prepare
            IUnitOfWork unitOfWork = new Fakes.StubIUnitOfWork();
            IUserRepository userRepository =
                new Fakes.StubIUserRepository()
                {
                    GetUserByNameIdentifierString = (nameIdentifier) => { return null; }
                };

            // Perform
            IUserService userService = new UserServiceProvider(userRepository, unitOfWork);
            userService.GetUserWithRolesByNameIdentifier("somenameidentifier");
        }
コード例 #9
0
        public void Throw_Exception_For_Null_Input_Parameter()
        {
            // Prepare
            IUserRepository userRepository =
                new Microsoft.Research.DataOnboarding.DataAccessService.Fakes.StubIUserRepository();
            IUnitOfWork unitOfWork = new Fakes.StubIUnitOfWork();
            User userToRegister = default(User);

            // Act
            IUserService userService = new UserServiceProvider(userRepository, unitOfWork);
            User registeredUser = userService.RegisterUser(userToRegister);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        /// <summary>
        /// Returns the instance of SkyDriveFile Service
        /// </summary>
        /// <returns>SkyDriveFileService</returns>
        private SkyDriveFileService GetSkyDriveFileService()
        {

            this.repositoryService = new StubIRepositoryService()
            {
                GetRepositoryByIdInt32 = (repositoryId) =>
                {
                    return this.repository;
                },
            };

            this.userService = new StubIUserService()
             {
                 GetUserAuthTokenInt32Int32 = (userId, RepositoryId) =>
                 {
                     return this.userAuthToken;
                 },

                 AddUpdateAuthTokenAuthToken = authToken =>
                 {
                     return authToken;
                 }
             };

            this.fileRepository = new StubIFileRepository()
            {
                GetItemInt32Int32 = (userId, fileName) =>
                {
                    return new File() { Name = "test", FileId = 100, Status = "Uploaded" };
                },

                UpdateFileFile = (file) =>
                {
                    return file;
                }
            };

            IUnitOfWork unitOfWork =
                new Fakes.StubIUnitOfWork()
                {
                    Commit = () => { return; }
                };

            this.blobDataRepository = new StubIBlobDataRepository()
            {
                GetBlobContentString = (name) =>
                {
                    return new DataDetail();
                },

                DeleteFileString = (fileName) =>
                {
                    return true;
                }
            };


            this.skyDriveAdapter = new StubIRepositoryAdapter()
            {
                PostFilePublishFileModel = (publishFileModel) =>
                    {
                        OperationStatus status = OperationStatus.CreateSuccessStatus();
                        status.CustomReturnValues = "x1234";
                        return status;
                    },

                RefreshTokenString = (accessToken) =>
                    {
                        AuthToken authToken = new AuthToken()
                        {
                            AccessToken = "accessToken",
                            RefreshToken = "refreshToken",
                            TokenExpiresOn = DateTime.UtcNow.AddHours(1)
                        };

                        return authToken;
                    }
            };

            IRepositoryAdapterFactory adapterFactory = new StubIRepositoryAdapterFactory()
            {
                GetRepositoryAdapterString = (baseRepositoryName) =>
                {
                    return skyDriveAdapter;
                }
            };

            this.repositoryDetails = new StubIRepositoryDetails()
            {
                GetRepositoryByIdInt32 = id => new Repository() { BaseRepository = new BaseRepository() { Name = "Repository Type 1" } }
            };

            SkyDriveFileService skyDriveFileService;
            using (ShimsContext.Create())
            {
                ShimDiagnosticsProvider.ConstructorType = (dp, type) => { };
                skyDriveFileService = new SkyDriveFileService(fileRepository, blobDataRepository, unitOfWork, repositoryDetails, repositoryService, userService, adapterFactory);
            }

            return skyDriveFileService;
        }