Example #1
0
        public virtual void init()
        {
            Orguser = new User { Id = IlluminateDatabase.GenerateId<User>(), NameIdentifier = "nameidentifier", OrgKey = "OrgKey", EmailAddress = "*****@*****.**", DateOfBirth = new DateTime(1990, 1, 1), FirstName = "Test", LastName = "User", Config = new Config { Settings = new Dictionary<string, object>() } };
            Manager = new User { Id = IlluminateDatabase.GenerateId<User>(), NameIdentifier = "managernameidentifier", OrgKey = "OrgKey", EmailAddress = "*****@*****.**", DateOfBirth = new DateTime(1991, 1, 1), FirstName = "Test", LastName = "Manager", Config = new Config { Settings = new Dictionary<string, object>() } };
            //set as manager
            Manager.Roles.Add(Role.GetRole(Role.BuiltInRole.Manager));

            Orguser.AddManager(Manager); 



        }
        private static IEnumerable<IUser> CreateTestUsers()
        {
            var andy = new User
                           {
                               FirstName = "Andy",
                               CreatedDate = DateTime.Now,
                               DateOfBirth = DateTime.Now.AddYears(-40),
                               EmailAddress = "*****@*****.**",
                               Id = IlluminateDatabase.GenerateId<User>(),
                               OrgKey = OrgName,
                               LastName = "Evans",
                               PersonnelNumber = "1",
                               MobilePhoneNumber = "447539363671",
                               Roles =
                                   new List<Role>
                                       {
                                           Role.GetRole(Role.BuiltInRole.Manager),
                                           Role.GetRole(Role.BuiltInRole.Administrator)
                                       },

                           };
            var mark = new User
                           {
                               FirstName = "Mark",
                               CreatedDate = DateTime.Now,
                               DateOfBirth = DateTime.Now.AddYears(-50),
                               EmailAddress = "*****@*****.**",
                               Id = IlluminateDatabase.GenerateId<User>(),
                               OrgKey = OrgName,
                               LastName = "Renyard",
                               PersonnelNumber = "2",
                               MobilePhoneNumber = "447539502244",
                               Roles =
                                   new List<Role>
                                       {
                                           Role.GetRole(Role.BuiltInRole.Manager),
                                           Role.GetRole(Role.BuiltInRole.Administrator)
                                       }
                           };

            var adrian = new User
                             {
                                 FirstName = "Adrian",
                                 CreatedDate = DateTime.Now,
                                 DateOfBirth = DateTime.Now.AddYears(-40),
                                 EmailAddress = "*****@*****.**",
                                 Id = IlluminateDatabase.GenerateId<User>(),
                                 OrgKey = OrgName,
                                 LastName = "Hall",
                                 PersonnelNumber = "3",
                                 MobilePhoneNumber = "447990597396",
                                 Roles =
                                     new List<Role>
                                         {
                                             Role.GetRole(Role.BuiltInRole.Manager),
                                             Role.GetRole(Role.BuiltInRole.Administrator)
                                         }
                             };
            var carl = new User
                           {
                               FirstName = "Carl",
                               CreatedDate = DateTime.Now,
                               DateOfBirth = DateTime.Now.AddYears(-40),
                               EmailAddress = "*****@*****.**",
                               Id = IlluminateDatabase.GenerateId<User>(),
                               OrgKey = OrgName,
                               LastName = "Davies",
                               PersonnelNumber = "4",
                               MobilePhoneNumber = "447446144932",
                               Roles =
                                   new List<Role>
                                       {
                                           Role.GetRole(Role.BuiltInRole.Manager),
                                           Role.GetRole(Role.BuiltInRole.Administrator)
                                       }
                           };
            carl.AddManager(andy);
            mark.AddManager(andy);
            adrian.AddManager(andy);
            andy.AddManager(mark);

            return new List<User>
                                {
                                    carl,
                                    mark,
                                    andy,
                                    adrian,
                                    
                                };
        }
        private void GenerateUsers()
        {
            if(_numUsers>_firstNames.Length)
                throw new ArgumentException(string.Format("Can only create up to {0} users",_firstNames.Length));
            var users = new List<IUser>(_numUsers);
            var rand = new Random();
            for (var count = 0; count < _numUsers; count++)
            {
                var user = new User
                {
                    FirstName = _firstNames[count],
                    LastName = _lastNames[count],
                    CreatedDate = DateTime.Now,
                    DateOfBirth = DateTime.Now.AddYears(GetAge()),
                    EmailAddress = GetEmail(_firstNames[count],_lastNames[count]),
                    Id = IlluminateDatabase.GenerateId<User>(),
                    OrgKey = _orgKey,
                    PersonnelNumber = _rand.Next(1000,10000).ToString(),
                    MobilePhoneNumber = "44756783568",
                    Roles =
                        new List<Role>
                                           {
                                               Role.GetRole(Role.BuiltInRole.Manager),
                                           },
                    Position = _positions[count],
                    
                    Avatar = new Avatar{PublicID = _avatarImages[count],Tags = new []{_orgKey}},


                };
                user.LatestHig= new HIGEntry
                {
                    CaptureDate = DateTime.Now,
                    ConsolidatedCompletionDate = DateTime.Now,
                    Subject = user.ToSimpleUser(),
                    Value =  rand.Next(-2,2),
                    Id = IlluminateDatabase.GenerateId<HIGEntry>(),
                    LastInDay = true
                };
                users.Add(user);
            }

            var ownerUser = new User
            {
                FirstName = _ownerFirstName,
                LastName = _ownerLastName,
                CreatedDate = DateTime.Now,
                DateOfBirth = DateTime.Now.AddYears(GetAge()),
                EmailAddress = _ownerEmail,
                Id = IlluminateDatabase.GenerateId<User>(),
                OrgKey = _orgKey,
                PersonnelNumber = _rand.Next(1000, 10000).ToString(),
                MobilePhoneNumber = "44756783568",
                Roles =
                    new List<Role>
                                           {
                                               Role.GetRole(Role.BuiltInRole.Manager),
                                               Role.GetRole(Role.BuiltInRole.Administrator),
                                               Role.GetRole(Role.BuiltInRole.Analytics),
                                           },
                Position = "Owner",
                RewardPointsLeft = 100000

            };
            foreach (var user in users)
            {
                user.AddManager(ownerUser);
            }
            users.Add(ownerUser);
            _users = users;
            var authUsers = new List<IAuthUser> {ownerUser.ToAuthUser()};
            _authUsers = authUsers;
        }
        public void ManagersForEmployee()
        {
            const string testEmployeeid = "testemployee";
            var testUser = new User()
            {
                Id = testEmployeeid,
                CreatedDate = DateTime.Now
            };
            const string manager1Id = "manager1";
            var manager1 = new User()
            {
                Id = manager1Id,
                CreatedDate = DateTime.Now,
                FirstName = "Bill",
                LastName = "Bunter"
            };
            const string manager2Id = "manager2";
            var manager2= new User()
            {
                Id = manager2Id,
                CreatedDate = DateTime.Now,
                FirstName = "Bob",
                LastName = "Bonter"
            };
           
            manager1.Roles.Add(Role.GetRole( Role.BuiltInRole.Manager));
            manager2.Roles.Add(Role.GetRole(Role.BuiltInRole.Manager));
            testUser.AddManager(manager1);
            testUser.AddManager(manager2);
            using (var session = OrgStore.OpenSession())
            {
                session.Store(testUser);
                session.Store(manager1);
                session.Store(manager2);
                session.SaveChanges();
            }
            //ARRANGE
            var controller = GetAuthenticatedControllerMock<AdministrationController>(Orguser);

            //set controller context. 
            controller.ControllerContext = new ControllerContext(GetContext(false), new RouteData(), controller);

           
            var request = new Request
                              {
                                  filter = new FilterLogic
                                               {
                                                   filters = new []
                                                                 {
                                                                     new Filter { Value = testEmployeeid }
                                                                 }
                                               },
                                               page = 0,
                                               skip = 0,
                                               take = 10

                              };
            var result = controller.ManagersForEmployee(request);
            var jsonresponse = ValidateAndUnwrapJsonResult(result);

            var data = jsonresponse.Data as AccountsManagersAdminViewModel;
            
            Assert.IsNull(jsonresponse.ErrorMessage);
            Assert.AreEqual(data.Count,testUser.Relationships.Count);
            Assert.AreEqual(data.Managers.First().EmployeeId,testUser.Id);
            Assert.AreEqual(data.Managers.First().ManagerEmployeeId, manager1Id);
            Assert.AreEqual(data.Managers.First().ManagerName, manager1.Name);
            Assert.AreEqual(data.Managers.Last().EmployeeId, testUser.Id);
            Assert.AreEqual(data.Managers.Last().ManagerName, manager2.Name);
            Assert.AreEqual(data.Managers.Last().ManagerEmployeeId, manager2Id);
        }
        public void AllManagers()
        {

            var Orguser2 = new User { Id = IlluminateDatabase.GenerateId<User>(), NameIdentifier = "nameidentifier", OrgKey = Testorg.OrgKey, EmailAddress = "*****@*****.**", DateOfBirth = new DateTime(1990, 1, 1), FirstName = "Test", LastName = "User", Config = new Config { Settings = new Dictionary<string, object>() } };
            var Manager2 = new User { Id = IlluminateDatabase.GenerateId<User>(), NameIdentifier = "managernameidentifier", OrgKey = Testorg.OrgKey, EmailAddress = "*****@*****.**", DateOfBirth = new DateTime(1991, 1, 1), FirstName = "Test", LastName = "Manager", Config = new Config { Settings = new Dictionary<string, object>() } };
            //set as manager
            Manager2.Roles.Add(Role.GetRole(Role.BuiltInRole.Manager));
            Orguser2.AddManager(Manager);
            var Orguser3 = new User { Id = IlluminateDatabase.GenerateId<User>(), NameIdentifier = "nameidentifier2", OrgKey = Testorg.OrgKey, EmailAddress = "*****@*****.**", DateOfBirth = new DateTime(1990, 1, 1), FirstName = "Test2", LastName = "User2", Config = new Config { Settings = new Dictionary<string, object>() } };
            var Manager3 = new User { Id = IlluminateDatabase.GenerateId<User>(), NameIdentifier = "managernameidentifier2", OrgKey = Testorg.OrgKey, EmailAddress = "*****@*****.**", DateOfBirth = new DateTime(1991, 1, 1), FirstName = "Test2", LastName = "Manager2", Config = new Config { Settings = new Dictionary<string, object>() } };
            //set as manager
            Manager3.Roles.Add(Role.GetRole(Role.BuiltInRole.Manager));
            Orguser3.AddManager(Manager);
            using (var session = OrgStore.OpenSession())
            {
                session.Store(Orguser2);
                session.Store(Manager2);
                session.Store(Orguser3);
                session.Store(Manager3);
                session.SaveChanges();
                var check = session.Query<User>().ToList();
            }

            //var users = GetAndSaveTestUsers(10, OrgStore);



            //ARRANGE
            var controller = GetAuthenticatedControllerMock<AccountController>(Orguser);

            //set controller context. 
            controller.ControllerContext = new ControllerContext(GetContext(false), new RouteData(), controller);


            var request = new Request
            {

                page = 0,
                skip = 0,
                take = 5

            };
            //var result = controller.AllEmployees(request);
            //var jsonresponse = ValidateAndUnwrapJsonResult(result);

            //var data = jsonresponse.Data as AccountsAdminViewModel;

            //Assert.IsNull(jsonresponse.ErrorMessage);
            //Assert.AreEqual(data.Count, 12);
            //Assert.AreEqual(data.Accounts.Count(), 5);

            var result = controller.AllManagers(request);
            var jsonresponse = ValidateAndUnwrapJsonResult(result);
            var data = jsonresponse.Data as AccountsAdminViewModel;
            // var look = data.Accounts[0];

            Assert.IsNull(jsonresponse.ErrorMessage);
            Assert.AreEqual(data.Count, 6);
            Assert.AreEqual(data.Accounts.Count(), 3);

            //  add a load more users and check this doesn't mess it up
            //var users = GetAndSaveTestUsers(10, OrgStore);

            var request2 = new Request
            {

                page = 0,
                skip = 0,
                take = 0

            };

            var result2 = controller.AllManagers(request2);
            var jsonresponse2 = ValidateAndUnwrapJsonResult(result2);
            var data2 = jsonresponse.Data as AccountsAdminViewModel;

            Assert.IsNull(jsonresponse.ErrorMessage);
            Assert.AreEqual(data.Count, 6);
            Assert.AreEqual(data.Accounts.Count(), 3);

        }