public void Can_Perform_Update_On_UserTypeRepository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = CreateRepository(unitOfWork))
            {
                var userType = MockedUserType.CreateUserType();
                repository.AddOrUpdate(userType);
                unitOfWork.Commit();

                // Act
                var resolved = repository.Get(userType.Id);
                resolved.Name        = "New Name";
                resolved.Permissions = "ZYX";
                repository.AddOrUpdate(resolved);
                unitOfWork.Commit();
                var updatedItem = repository.Get(userType.Id);

                // Assert
                Assert.That(updatedItem.Id, Is.EqualTo(resolved.Id));
                Assert.That(updatedItem.Name, Is.EqualTo(resolved.Name));
                Assert.That(updatedItem.Permissions, Is.EqualTo(resolved.Permissions));
            }
        }
Exemple #2
0
        public void Can_Perform_Delete_On_UserTypeRepository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = CreateRepository(unitOfWork))
            {
                var userType = MockedUserType.CreateUserType();

                // Act
                repository.AddOrUpdate(userType);
                unitOfWork.Commit();
                var id = userType.Id;

                using (var repository2 = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax))
                {
                    repository2.Delete(userType);
                    unitOfWork.Commit();

                    var resolved = repository2.Get(id);

                    // Assert
                    Assert.That(resolved, Is.Null);
                }
            }
        }
        public void Can_Perform_Delete_On_UserTypeRepository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = CreateRepository(unitOfWork))
            {
                var userType = MockedUserType.CreateUserType();

                // Act
                repository.AddOrUpdate(userType);
                unitOfWork.Commit();
                var id = userType.Id;

                var repository2 = RepositoryResolver.Current.ResolveByType <IUserTypeRepository>(unitOfWork);
                repository2.Delete(userType);
                unitOfWork.Commit();

                var resolved = repository2.Get(id);

                // Assert
                Assert.That(resolved, Is.Null);
            }
        }
        public void Get_By_Object_Id()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "*****@*****.**", userType);

            Assert.IsNotNull(ServiceContext.UserService.GetUserById(user.Id));
            Assert.IsNull(ServiceContext.UserService.GetUserById(9876));
        }
 private IUserType CreateAndCommitUserType()
 {
     var provider = new PetaPocoUnitOfWorkProvider();
     var unitOfWork = provider.GetUnitOfWork();
     var repository = RepositoryResolver.Current.ResolveByType<IUserTypeRepository>(unitOfWork);
     var userType = MockedUserType.CreateUserType();
     repository.AddOrUpdate(userType);
     unitOfWork.Commit();
     return userType;
 }
        public void Get_By_Email()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "*****@*****.**", userType);

            Assert.IsNotNull(ServiceContext.UserService.GetByEmail(user.Email));
            Assert.IsNull(ServiceContext.UserService.GetByEmail("*****@*****.**"));
        }
        public void Get_By_Username_With_Backslash()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var user = ServiceContext.UserService.CreateUserWithIdentity("mydomain\\JohnDoe", "*****@*****.**", userType);

            Assert.IsNotNull(ServiceContext.UserService.GetByUsername(user.Username));
            Assert.IsNull(ServiceContext.UserService.GetByUsername("notFound"));
        }
        public void Can_Persist_New_User_Type()
        {
            // Arrange
            var userService = ServiceContext.UserService;
            var userType    = MockedUserType.CreateUserType();

            // Act
            userService.SaveUserType(userType);

            // Assert
            Assert.That(userType.HasIdentity, Is.True);
        }
        private IUserType[] CreateAndCommitMultipleUserTypes(IUserTypeRepository repository, IUnitOfWork unitOfWork)
        {
            var userType1 = MockedUserType.CreateUserType("1");
            var userType2 = MockedUserType.CreateUserType("2");
            var userType3 = MockedUserType.CreateUserType("3");

            repository.AddOrUpdate(userType1);
            repository.AddOrUpdate(userType2);
            repository.AddOrUpdate(userType3);
            unitOfWork.Commit();
            return(new IUserType[] { userType1, userType2, userType3 });
        }
        public void Exists_By_Username()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var user  = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "*****@*****.**", userType);
            var user2 = ServiceContext.UserService.CreateUserWithIdentity("*****@*****.**", "*****@*****.**", userType);

            Assert.IsTrue(ServiceContext.UserService.Exists("JohnDoe"));
            Assert.IsFalse(ServiceContext.UserService.Exists("notFound"));
            Assert.IsTrue(ServiceContext.UserService.Exists("*****@*****.**"));
        }
        public void Count_All_Online_Users()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var users = MockedUser.CreateUser(userType, 10, (i, member) => member.LastLoginDate = DateTime.Now.AddMinutes(i * -2));

            ServiceContext.UserService.Save(users);

            var customUser = MockedUser.CreateUser(userType);

            throw new NotImplementedException();
        }
        private IUserType CreateAndCommitUserType()
        {
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = new UserTypeRepository(unitOfWork, CacheHelper.CreateDisabledCacheHelper(), Logger, SqlSyntax))
            {
                var userType = MockedUserType.CreateUserType();
                repository.AddOrUpdate(userType);
                unitOfWork.Commit();
                return(userType);
            }
        }
        public void Disables_User_Instead_Of_Deleting_If_Flag_Not_Set()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "*****@*****.**", userType);

            ServiceContext.UserService.Delete(user);
            var deleted = ServiceContext.UserService.GetUserById(user.Id);

            // Assert
            Assert.That(deleted, Is.Not.Null);
        }
        public void Can_Delete_User()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var user = ServiceContext.UserService.CreateUserWithIdentity("JohnDoe", "*****@*****.**", userType);

            ServiceContext.UserService.Delete(user, true);
            var deleted = ServiceContext.UserService.GetUserById(user.Id);

            // Assert
            Assert.That(deleted, Is.Null);
        }
        public void Can_Perform_Add_On_UserTypeRepository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            var repository = RepositoryResolver.Current.ResolveByType <IUserTypeRepository>(unitOfWork);

            var userType = MockedUserType.CreateUserType();

            // Act
            repository.AddOrUpdate(userType);
            unitOfWork.Commit();

            // Assert
            Assert.That(userType.HasIdentity, Is.True);
        }
        public void Count_All_Users()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var users = MockedUser.CreateUser(userType, 10);

            ServiceContext.UserService.Save(users);
            var customUser = MockedUser.CreateUser(userType);

            ServiceContext.UserService.Save(customUser);

            var found = ServiceContext.UserService.GetCount(MemberCountType.All);

            // + 1 because of the built in admin user
            Assert.AreEqual(12, found);
        }
        public void Count_All_Locked_Users()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var users = MockedUser.CreateUser(userType, 10, (i, member) => member.IsLockedOut = i % 2 == 0);

            ServiceContext.UserService.Save(users);

            var customUser = MockedUser.CreateUser(userType);

            customUser.IsLockedOut = true;
            ServiceContext.UserService.Save(customUser);

            var found = ServiceContext.UserService.GetCount(MemberCountType.LockedOut);

            Assert.AreEqual(6, found);
        }
        public void Get_All_Paged_Users()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var users = MockedUser.CreateUser(userType, 10);

            ServiceContext.UserService.Save(users);

            int totalRecs;
            var found = ServiceContext.UserService.GetAll(0, 2, out totalRecs);

            Assert.AreEqual(2, found.Count());
            // + 1 because of the built in admin user
            Assert.AreEqual(11, totalRecs);
            Assert.AreEqual("admin", found.First().Username);
            Assert.AreEqual("test0", found.Last().Username);
        }
        public void Can_Verify_Fresh_Entity_Is_Not_Dirty()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            var repository = RepositoryResolver.Current.ResolveByType <IUserTypeRepository>(unitOfWork);
            var userType   = MockedUserType.CreateUserType();

            repository.AddOrUpdate(userType);
            unitOfWork.Commit();

            // Act
            var  resolved = repository.Get(userType.Id);
            bool dirty    = ((UserType)resolved).IsDirty();

            // Assert
            Assert.That(dirty, Is.False);
        }
Exemple #20
0
        public void Can_Perform_Add_On_UserTypeRepository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider(Logger);
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = CreateRepository(unitOfWork))
            {
                var userType = MockedUserType.CreateUserType();

                // Act
                repository.AddOrUpdate(userType);
                unitOfWork.Commit();

                // Assert
                Assert.That(userType.HasIdentity, Is.True);
            }
        }
        public void Find_By_Email_Starts_With()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var users = MockedUser.CreateUser(userType, 10);

            ServiceContext.UserService.Save(users);
            //don't find this
            var customUser = MockedUser.CreateUser(userType);

            customUser.Email = "*****@*****.**";
            ServiceContext.UserService.Save(customUser);

            int totalRecs;
            var found = ServiceContext.UserService.FindByEmail("tes", 0, 100, out totalRecs, StringPropertyMatchType.StartsWith);

            Assert.AreEqual(10, found.Count());
        }
        public void Find_By_Email_Exact()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var users = MockedUser.CreateUser(userType, 10);

            ServiceContext.UserService.Save(users);
            //include this
            var customUser = MockedUser.CreateUser(userType);

            customUser.Email = "*****@*****.**";
            ServiceContext.UserService.Save(customUser);

            int totalRecs;
            var found = ServiceContext.UserService.FindByEmail("*****@*****.**", 0, 100, out totalRecs, StringPropertyMatchType.Exact);

            Assert.AreEqual(1, found.Count());
        }
        public void Count_All_Approved_Users()
        {
            var userType = MockedUserType.CreateUserType();

            ServiceContext.UserService.SaveUserType(userType);
            var users = MockedUser.CreateUser(userType, 10, (i, member) => member.IsApproved = i % 2 == 0);

            ServiceContext.UserService.Save(users);

            var customUser = MockedUser.CreateUser(userType);

            customUser.IsApproved = false;
            ServiceContext.UserService.Save(customUser);

            var found = ServiceContext.UserService.GetCount(MemberCountType.Approved);

            // + 1 because of the built in admin user
            Assert.AreEqual(6, found);
        }
        public void Can_Perform_Multiple_Adds_On_UserTypeRepository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();

            using (var repository = CreateRepository(unitOfWork))
            {
                var userType1 = MockedUserType.CreateUserType("1");
                var userType2 = MockedUserType.CreateUserType("2");

                // Act
                repository.AddOrUpdate(userType1);
                unitOfWork.Commit();
                repository.AddOrUpdate(userType2);
                unitOfWork.Commit();

                // Assert
                Assert.That(userType1.HasIdentity, Is.True);
                Assert.That(userType2.HasIdentity, Is.True);
            }
        }
        public void Can_Perform_Get_On_UserTypeRepository()
        {
            // Arrange
            var provider   = new PetaPocoUnitOfWorkProvider();
            var unitOfWork = provider.GetUnitOfWork();
            var repository = RepositoryResolver.Current.ResolveByType <IUserTypeRepository>(unitOfWork);
            var userType   = MockedUserType.CreateUserType();

            repository.AddOrUpdate(userType);
            unitOfWork.Commit();

            // Act
            var resolved = repository.Get(userType.Id);

            // Assert
            Assert.That(resolved.Id, Is.EqualTo(userType.Id));
            //Assert.That(resolved.CreateDate, Is.GreaterThan(DateTime.MinValue));
            //Assert.That(resolved.UpdateDate, Is.GreaterThan(DateTime.MinValue));
            Assert.That(resolved.Name, Is.EqualTo(userType.Name));
            Assert.That(resolved.Alias, Is.EqualTo(userType.Alias));
            Assert.That(resolved.Permissions, Is.EqualTo(userType.Permissions));
        }