Пример #1
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);
        }
Пример #2
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");
        }
Пример #3
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);
        }
Пример #4
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(" ");
        }
Пример #5
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");
        }
Пример #6
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);
        }