public void User_Not_Authorized_When_Contact_Doesnt_Belong_To_User_Jobsearch()
        {
            // Setup
            var user = new User();
            var user2 = new User();
            var search = new JobSearch { User = user };
            var company = new Company { JobSearch = search };
            var contact = new Contact { Company = company };

            _context.Contacts.Add(contact);
            _context.Users.Add(user2);
            _context.SaveChanges();

            IProcess<ContactAutorizationParams, AuthorizationResultViewModel> process = new AuthorizationProcesses(_context);

            // Act
            AuthorizationResultViewModel result = process.Execute(new ContactAutorizationParams
            {
                ContactId = contact.Id,
                RequestingUserId = user2.Id
            });

            // Verify
            Assert.IsNotNull(result, "Result was null");
            Assert.IsFalse(result.UserAuthorized, "User was incorrectly authorized");
        }
        public TaskDashboardViewModel(User user)
        {
            if (user == null)
                throw new ArgumentNullException("user");

            var allTasks = user.LastVisitedJobSearch.Companies.SelectMany(x => x.Tasks).ToList();
            OverdueTasks = allTasks.Where(x => (x.TaskDate.HasValue && x.TaskDate.Value.Date < DateTime.Today) || !x.TaskDate.HasValue)
                                   .Where(x => x.CompletionDate == null)
                                   .OrderBy(x => x.TaskDate)
                                   .ThenBy(x => x.Name)
                                   .ToList();

            TodaysTasks = allTasks.Where(x => x.TaskDate.HasValue && x.TaskDate.Value.Date == DateTime.Today)
                                  .Where(x => x.CompletionDate == null)
                                  .OrderBy(x => x.Name)
                                  .ToList();

            FutureTasks = allTasks.Where(x => x.TaskDate.HasValue && x.TaskDate.Value.Date > DateTime.Today)
                                  .Where(x => x.CompletionDate == null)
                                  .OrderBy(x => x.TaskDate)
                                  .ToList();

            CurrentMilestone = user.LastVisitedJobSearch.CurrentMilestone;

            if (CurrentMilestone != null)
                MilestoneProgress = new JobSearchMilestoneProgress(user.LastVisitedJobSearch);
        }
        public void Init()
        {
            _verifyTokenMock = new Mock<IProcess<VerifyUserLinkedInAccessTokenParams,UserAccessTokenResultViewModel>>();
            _verifyTokenMock.Setup(x => x.Execute(It.IsAny<VerifyUserLinkedInAccessTokenParams>())).Returns(new UserAccessTokenResultViewModel { AccessTokenValid = true });

            _createPositionMock = new Mock<IProcess<CreatePositionParams, PositionDisplayViewModel>>();
            var createCompanyCmd = new CreateCompanyCommand(_serviceFactory.Object);

            _process = new LinkedInPositionSearchProcesses(_context, _verifyTokenMock.Object, createCompanyCmd, _createPositionMock.Object, null);

            // Initialize user with test (but valid) access token data
            _user = new User();
            var oauth = new OAuthData
            {
                Token = "bfcf3fe4-b4d4-4f37-9d32-292ae9d45347",
                Secret = "f66673b2-5877-4fbf-80e0-3826ca9f7eed",
                TokenProvider = TokenProvider.LinkedIn,
                TokenType = TokenType.AccessToken,
            };

            oauth.LinkedInUsers.Add(_user);
            _user.LinkedInOAuthData = oauth;
            _context.Users.Add(_user);
            _context.OAuthData.Add(oauth);
            _context.SaveChanges();
        }
        public void Jigsaw_Credentials_Gets_Updated_If_One_Exists_For_User()
        {
            // Setup
            var encryptionMock = new Mock<EncryptionUtils>();
            encryptionMock.Setup(x => x.EncryptStringToBytes_AES(It.IsAny<string>(), It.IsAny<byte[]>(), It.IsAny<byte[]>())).Returns(new byte[] { Convert.ToByte(true) });

            var user = new User { JigsawAccountDetails = new JigsawAccountDetails { Username = "******", EncryptedPassword = "******" } };
            _context.Users.Add(user);
            _context.SaveChanges();

            _process = new JigsawAuthProcesses(_context, encryptionMock.Object);

            // Act
            var result = _process.Execute(new SaveJigsawUserCredentialsParams
            {
                RequestingUserId = user.Id,
                JigsawUsername = "******",
                JigsawPassword = "******"
            });

            // Verify
            Assert.AreEqual(1, _context.JigsawAccountDetails.Count(), "Incorrect number of jigsaw records exist");
            Assert.AreEqual("a", user.JigsawAccountDetails.Username, "Jigsaw username was incorrect");
            Assert.AreEqual(Convert.ToBase64String(new byte[] { Convert.ToByte(true) }), user.JigsawAccountDetails.EncryptedPassword, "Jigsaw password was incorrect");
        }
        public void Can_Save_Jigsaw_Encrypted_Credentials_For_User()
        {
            // Setup
            string username = "******";
            string unencryptedPass = "******";
            byte[] expectedKey = Convert.FromBase64String("LHRqdBadRUVh3cdMYoeuYVng/qQlgvBReEAg5JvO48E=");
            byte[] expectedIV = Convert.FromBase64String("CB7hOrmWxs2riRF26Imn7w==");

            var encryptionMock = new Mock<EncryptionUtils>();
            encryptionMock.Setup(x => x.EncryptStringToBytes_AES(unencryptedPass, expectedKey, expectedIV)).Returns(new byte[] { Convert.ToByte(true) });

            var user = new User();
            _context.Users.Add(user);
            _context.SaveChanges();

            _process = new JigsawAuthProcesses(_context, encryptionMock.Object);

            // Act
            var result = _process.Execute(new SaveJigsawUserCredentialsParams
            {
                RequestingUserId = user.Id,
                JigsawUsername = username,
                JigsawPassword = unencryptedPass
            });

            // Verify
            Assert.IsNotNull(result, "Process returned a null result");
            Assert.IsTrue(result.WasSuccessful, "Process' result was not successful");

            var jigsaw = _context.JigsawAccountDetails.SingleOrDefault();
            Assert.IsNotNull(jigsaw, "No jigsaw credentials entity was created");
            Assert.AreEqual(username, jigsaw.Username, "Jigsaw username was incorrect");
            Assert.AreEqual(Convert.ToBase64String(new byte[] { Convert.ToByte(true) }), jigsaw.EncryptedPassword, "Jigsaw password was incorrect");
        }
        public void Init()
        {
            _createPositionMock = new Mock<IProcess<CreatePositionParams, PositionDisplayViewModel>>();
            _createPositionMock.Setup(x => x.Execute(It.IsAny<CreatePositionParams>())).Returns(new PositionDisplayViewModel());

            _verifyTokenMock = new Mock<IProcess<VerifyUserLinkedInAccessTokenParams, UserAccessTokenResultViewModel>>();
            _verifyTokenMock.Setup(x => x.Execute(It.IsAny<VerifyUserLinkedInAccessTokenParams>())).Returns(new UserAccessTokenResultViewModel { AccessTokenValid = true });

            _createCompanyCmdMock = CommandTestUtils.GenerateCreateCompanyCommandMock();
            _createCompanyCmdMock.Setup(x => x.Execute()).Returns(new Company { Id = NEW_COMPANY_ID });

            _companyQueryMock = QueryTestUtils.GenerateCompanyByIdQueryMock();
            _process = new LinkedInPositionSearchProcesses(_context, _verifyTokenMock.Object, _createCompanyCmdMock.Object, _createPositionMock.Object, _companyQueryMock.Object);

            // Initialize user with test (but valid) access token data
            _user = new User { LastVisitedJobSearch = new JobSearch() };
            var oauth = new OAuthData
            {
                Token = "bfcf3fe4-b4d4-4f37-9d32-292ae9d45347",
                Secret = "f66673b2-5877-4fbf-80e0-3826ca9f7eed",
                TokenProvider = TokenProvider.LinkedIn,
                TokenType = TokenType.AccessToken,
            };

            oauth.LinkedInUsers.Add(_user);
            _user.LinkedInOAuthData = oauth;
            _context.Users.Add(_user);
            _context.OAuthData.Add(oauth);
            _context.SaveChanges();
        }
        public void Position_Creation_Returns_Display_View_Model()
        {
            // Setup
            var positionAuthMock = new Mock<IProcess<PositionAuthorizationParams, AuthorizationResultViewModel>>();
            positionAuthMock.Setup(x => x.Execute(It.IsAny<PositionAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true });

            var companyAuthMock = new Mock<IProcess<CompanyQueryAuthorizationParams, AuthorizationResultViewModel>>();
            companyAuthMock.Setup(x => x.Execute(It.IsAny<CompanyQueryAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true });

            IProcess<CreatePositionParams, PositionDisplayViewModel> process = new PositionProcesses(_context, positionAuthMock.Object, companyAuthMock.Object);

            User user = new User();
            Company company = new Company();
            _context.Users.Add(user);
            _context.Companies.Add(company);
            _context.SaveChanges();

            // Act
            PositionDisplayViewModel result = process.Execute(new CreatePositionParams
            {
                CompanyId = company.Id,
                Title = "title",
                HasApplied = true,
                Notes = "Notes",
                LinkedInId = "ABC123",
                RequestingUserId = user.Id
            });

            // Verify
            Assert.AreEqual("title", result.Title, "Position had an incorrect title");
            Assert.IsTrue(result.HasApplied, "Position had an incorrect HasApplied value");
            Assert.AreEqual("Notes", result.Notes, "Position had an incorrect note");
            Assert.AreEqual("ABC123", result.LinkedInId, "Position had an incorrect LinkedIn id");
        }
        public void Can_Get_Decrypted_Credentials()
        {
            // Setup
            string decryptedString = "decrypted string";
            string username = "******";
            string encryptedString = "w6AnE3eWg1urf54jkTejCku+JT3gPT78e9MAkUa8fsI=";
            byte[] expectedKey = Convert.FromBase64String("LHRqdBadRUVh3cdMYoeuYVng/qQlgvBReEAg5JvO48E=");
            byte[] expectedIV = Convert.FromBase64String("CB7hOrmWxs2riRF26Imn7w==");
            byte[] expectedEncryptedPass = Convert.FromBase64String(encryptedString);

            var encryptionMock = new Mock<EncryptionUtils>();
            encryptionMock.Setup(x => x.DecryptStringFromBytes_AES(expectedEncryptedPass, expectedKey, expectedIV)).Returns(decryptedString);

            var user = new User();
            var jigsaw = new JigsawAccountDetails { AssociatedUser = user, Username = username, EncryptedPassword = encryptedString };
            _context.JigsawAccountDetails.Add(jigsaw);
            _context.SaveChanges();

            _process = new JigsawAuthProcesses(_context, encryptionMock.Object);

            // Act
            var result = _process.Execute(new GetUserJigsawCredentialsParams { RequestingUserId = user.Id });

            // Verify
            Assert.IsNotNull(result, "Process returned a null result");
            Assert.AreEqual(username, result.JigsawUsername, "An incorrect username was returned");
            Assert.AreEqual(decryptedString, result.JigsawPassword, "An incorrect password was returned");
        }
 public void InitializeTestEntities()
 {
     _user = new User { JobSearches = new List<JobSearch>() };
     _unitOfWork.Users.Add(new User());
     _unitOfWork.Users.Add(_user);
     _unitOfWork.Users.Add(new User());
     _unitOfWork.Commit();
 }
        private void InitializeTestEntities()
        {
            _changedDate = new DateTime(2011, 1, 2, 3, 4, 5);
            _startDate = new DateTime(2011, 2, 3, 4, 5, 6);

            _jobSearch = new JobSearch();
            Company company = new Company { JobSearch = _jobSearch };
            _user = new User();
            _contact = new Contact { Company = company };

            _task = new Task
            {
                Name = "Starting Name",
                CompletionDate = null,
                TaskDate = _startDate,
                Category = "Starting Category",
                Company = company,
                Notes = "Starting Notes",
                History = new List<TaskHistory>()
            };

            _unitOfWork.Users.Add(_user);
            _unitOfWork.Tasks.Add(_task);
            _unitOfWork.Contacts.Add(_contact);
            _unitOfWork.Commit();

            // Mocks
            _contactAuthMock = new Mock<IProcess<ContactAutorizationParams, AuthorizationResultViewModel>>();
            _contactAuthMock.Setup(x => x.Execute(It.IsAny<ContactAutorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true });

            _taskAuthMock = new Mock<IProcess<TaskAuthorizationParams, AuthorizationResultViewModel>>();
            _taskAuthMock.Setup(x => x.Execute(It.IsAny<TaskAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true });

            _serviceFactory = new Mock<IServiceFactory>();
            _serviceFactory.Setup(x => x.GetService<IUnitOfWork>()).Returns(_unitOfWork);

            _searchProvider = new Mock<ISearchProvider>();
            _serviceFactory.Setup(x => x.GetService<ISearchProvider>()).Returns(_searchProvider.Object);

            _userQuery = new Mock<UserByIdQuery>(_unitOfWork);
            _userQuery.Setup(x => x.Execute()).Returns(_user);
            _serviceFactory.Setup(x => x.GetService<UserByIdQuery>()).Returns(_userQuery.Object);

            _contactQuery = new Mock<ContactByIdQuery>(_unitOfWork, _contactAuthMock.Object);
            _contactQuery.Setup(x => x.Execute()).Returns(_contact);
            _serviceFactory.Setup(x => x.GetService<ContactByIdQuery>()).Returns(_contactQuery.Object);

            _taskQuery = new Mock<TaskByIdQuery>(_unitOfWork, _taskAuthMock.Object);
            _taskQuery.Setup(x => x.Execute()).Returns(_task);
            _serviceFactory.Setup(x => x.GetService<TaskByIdQuery>()).Returns(_taskQuery.Object);

            _updateMetricsCmd = new Mock<UpdateJobSearchMetricsCommand>(_serviceFactory.Object);
            _serviceFactory.Setup(x => x.GetService<UpdateJobSearchMetricsCommand>()).Returns(_updateMetricsCmd.Object);

            _validator = new Mock<IValidator<Task>>();
            _validator.Setup(x => x.Validate(It.IsAny<Task>())).Returns(new ValidationResult());
            _serviceFactory.Setup(x => x.GetService<IValidator<Task>>()).Returns(_validator.Object);
        }
        private void InitializeTestEntities()
        {
            _jobSearch = new JobSearch { Name = "Test Name", Description = "Test Description", History = new List<JobSearchHistory>() };
            _user = new User();

            _unitOfWork.Users.Add(_user);
            _unitOfWork.JobSearches.Add(_jobSearch);
            _unitOfWork.Commit();
        }
        private void InitializeTestEntities()
        {
            _user1 = new User { Email = "*****@*****.**" };
            _user2 = new User { Email = "*****@*****.**" };
            _user3 = new User { Email = "*****@*****.**" };

            _unitOfWork.Users.Add(_user1);
            _unitOfWork.Users.Add(_user2);
            _unitOfWork.Users.Add(_user3);

            _unitOfWork.Commit();
        }
        public UserSidebarViewModel(User user)
        {
            Id = user.Id;
            DisplayName = user.FullName;
            HasCurrentJobSearchId = user.LastVisitedJobSearchId != null;

            if (user.IsOrganizationAdmin)
                UserType = UserSidebarViewModel.AccountType.OrganizationAdmin;
            else
                UserType = UserSidebarViewModel.AccountType.User;

            if (user.IsSiteAdmin)
                IsSiteAdmin = true;
        }
        private void InitializeTestEntities()
        {
            _search = new JobSearch();

            _user = new User
            {
                Email = _startingEmail ,
                Password = PasswordUtils.CreatePasswordHash(_startingEmail, _oldPassword),
                LastVisitedJobSearch = _search,
                FullName = "starting name"
            };

            _unitOfWork.Users.Add(_user);
            _unitOfWork.Commit();
        }
 public MyJobLeadsMembershipUser(User mjlUser)
     : base("MyJobLeadsMembershipProvider"
     , mjlUser.Email
     , mjlUser.Id
     , mjlUser.Email
     , string.Empty // Not implemented
     , string.Empty // Not Implemented
     , true  // Not Implemented
     , false  // Not Implemented
     , DateTime.MinValue  // Not Implemented
     , DateTime.MinValue  // Not Implemented
     , DateTime.MinValue  // Not Implemented
     , DateTime.MinValue  // Not Implemented
     , DateTime.MinValue  // Not Implemented
     ) { }   
        public void User_Associated_With_Contacts_JobSearch_Is_Authorized()
        {
            // Setup
            User user = new User();
            JobSearch jobSearch = new JobSearch { User = user };

            _unitOfWork.JobSearches.Add(jobSearch);
            _unitOfWork.Commit();

            // Act
            bool result = new IsUserAuthorizedForJobSearchQuery(_unitOfWork).WithUserId(user.Id).WithJobSearchId(jobSearch.Id).Execute();

            // Verify
            Assert.IsTrue(result, "User was incorrectly not authorized for the job search");
        }
        public void Init()
        {
            _activationProc = new FillPerfectLicenseProcesses(_context);

            _user = new User { FillPerfectKey = Guid.NewGuid(), FullName = "Test Name", Email = "*****@*****.**" };
            var order = new Order { OrderDate = DateTime.Now };
            order.FillPerfectLicenses.Add(new FpUserLicense
            {
                EffectiveDate = DateTime.Now.AddMonths(-1),
                ExpirationDate = DateTime.Now.AddMonths(1),
                LicenseType = FillPerfectLicenseType.IndividualPaid
            });

            _user.OwnedOrders.Add(order);
            _context.Users.Add(_user);
            _context.SaveChanges();
        }
        private void InitializeTestEntities()
        {
            _user = new User();
            _contact = new Contact
            {
                Name = "Starting Name",
                DirectPhone = "444-444-4444",
                MobilePhone = "555-555-5555",
                Extension = "11",
                Email = "*****@*****.**",
                Assistant = "Starting Assistant",
                ReferredBy = "Starting Referred",
                Notes = "Starting Notes",
                JigsawId = 1234,
                HasJigsawAccess = true,

                History = new List<ContactHistory>()
            };

            _unitOfWork.Users.Add(_user);
            _unitOfWork.Contacts.Add(_contact);
            _unitOfWork.Commit();

            // Mocks
            _contactAuthMock = new Mock<IProcess<ContactAutorizationParams, AuthorizationResultViewModel>>();
            _contactAuthMock.Setup(x => x.Execute(It.IsAny<ContactAutorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true });

            _serviceFactory = new Mock<IServiceFactory>();
            _serviceFactory.Setup(x => x.GetService<IUnitOfWork>()).Returns(_unitOfWork);

            _searchProvider = new Mock<ISearchProvider>();
            _serviceFactory.Setup(x => x.GetService<ISearchProvider>()).Returns(_searchProvider.Object);

            _userQuery = new Mock<UserByIdQuery>(_unitOfWork);
            _userQuery.Setup(x => x.Execute()).Returns(_user);
            _serviceFactory.Setup(x => x.GetService<UserByIdQuery>()).Returns(_userQuery.Object);

            _contactQuery = new Mock<ContactByIdQuery>(_unitOfWork, _contactAuthMock.Object);
            _contactQuery.Setup(x => x.Execute()).Returns(_contact);
            _serviceFactory.Setup(x => x.GetService<ContactByIdQuery>()).Returns(_contactQuery.Object);

            _validator = new Mock<IValidator<Contact>>();
            _validator.Setup(x => x.Validate(It.IsAny<Contact>())).Returns(new ValidationResult());
            _serviceFactory.Setup(x => x.GetService<IValidator<Contact>>()).Returns(_validator.Object);
        }
        public void Init()
        {
            _getKeyProc = new FillPerfectLicenseProcesses(_context);

            // Db Entities
            _user = new User { FillPerfectKey = Guid.NewGuid(), FullName = "Test Name", Email = "*****@*****.**" };
            _user.Organization = new Organization { Name = _orgName };
            var order = new Order { OrderDate = DateTime.Now };
            order.FillPerfectLicenses.Add(new FpUserLicense
            {
                ActivatedComputerId = "1234",
                EffectiveDate = DateTime.Now.AddMonths(-1),
                ExpirationDate = DateTime.Now.AddMonths(1),
                LicenseType = FillPerfectLicenseType.IndividualPaid
            });

            _user.OwnedOrders.Add(order);
            _context.Users.Add(_user);
            _context.SaveChanges();
        }
        public void Throws_UserNotAuthorizedForEntityException_If_Not_Organization_Admin()
        {
            // Setup
            var org = new Organization();
            var user = new User { Organization = org };
            _context.Users.Add(user);
            _context.SaveChanges();

            var authMock = new Mock<IProcess<OrganizationAdminAuthorizationParams, AuthorizationResultViewModel>>();
            authMock.Setup(x => x.Execute(It.IsAny<OrganizationAdminAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = false });
            IProcess<OrganizationMemberStatisticsParams, OrganizationMemberStatisticsViewModel> process = new OrganizationMetricQueryProcesses(_context, authMock.Object);

            // Act
            try
            {
                process.Execute(new OrganizationMemberStatisticsParams { OrganizationId = org.Id, RequestingUserId = user.Id });
                Assert.Fail("No exception was thrown");
            }

            // Verify
            catch (UserNotAuthorizedForEntityException ex)
            {
                Assert.AreEqual(typeof(Organization), ex.EntityType, "Exception's entity type was incorrect");
                Assert.AreEqual(org.Id, ex.IdValue, "Exception's id value was incorrect");
                Assert.AreEqual(user.Id, ex.UserId, "Exception's user id value was incorrect");
            }
        }
示例#21
0
        public void Position_Gets_Created_With_History_Record()
        {
            // Setup
            var positionAuthMock = new Mock<IProcess<PositionAuthorizationParams, AuthorizationResultViewModel>>();
            positionAuthMock.Setup(x => x.Execute(It.IsAny<PositionAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true });

            var companyAuthMock = new Mock<IProcess<CompanyQueryAuthorizationParams, AuthorizationResultViewModel>>();
            companyAuthMock.Setup(x => x.Execute(It.IsAny<CompanyQueryAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true });

            IProcess<CreatePositionParams, PositionDisplayViewModel> process = new PositionProcesses(_context, positionAuthMock.Object, companyAuthMock.Object);

            User user = new User();
            Company company = new Company();
            _context.Users.Add(user);
            _context.Companies.Add(company);
            _context.SaveChanges();

            DateTime start, end;

            // Act
            start = DateTime.Now;
            process.Execute(new CreatePositionParams
            {
                CompanyId = company.Id,
                Title = "title",
                HasApplied = true,
                Notes = "Notes",
                LinkedInId = "ABC123",
                RequestingUserId = user.Id
            });
            end = DateTime.Now;

            // Verify
            var result = _context.Positions.Single().History.SingleOrDefault();
            Assert.IsNotNull(result, "No history record was created");
            Assert.AreEqual("title", result.Title, "History record's title was incorrect");
            Assert.AreEqual(true, result.HasApplied, "History record's applied value was incorrect");
            Assert.AreEqual("Notes", result.Notes, "History record's notes value was incorrect");
            Assert.AreEqual("ABC123", result.LinkedInId, "History record's linkedin id was incorrect");

            Assert.AreEqual(MJLConstants.HistoryInsert, result.HistoryAction, "History action was incorrect");
            Assert.AreEqual(user.Id, result.AuthoringUserId, "History record's authoring user id was incorrect");
            Assert.IsTrue(result.DateModified >= start && result.DateModified <= end, "History's date was incorrect");
        }
        public void Can_Get_Members_With_Statistics_For_Organization()
        {
            // Setup
            var org = new Organization();
            var user1 = new User
            {
                Organization = org,
                FullName = "name 1",
                Email = "email 1",
                LastVisitedJobSearch = new JobSearch
                {
                    Metrics = new JobSearchMetrics
                    {
                        NumApplyTasksCompleted = 1,
                        NumApplyTasksCreated = 2,
                        NumCompaniesCreated = 3,
                        NumContactsCreated = 4,
                        NumInPersonInterviewTasksCreated = 5,
                        NumPhoneInterviewTasksCreated = 6
                    }
                }
            };

            var user2 = new User
            {
                Organization = org,
                FullName = "name 2",
                Email = "email 2",
                LastVisitedJobSearch = new JobSearch
                {
                    Metrics = new JobSearchMetrics
                    {
                        NumApplyTasksCompleted = 7,
                        NumApplyTasksCreated = 8,
                        NumCompaniesCreated = 9,
                        NumContactsCreated = 10,
                        NumInPersonInterviewTasksCreated = 11,
                        NumPhoneInterviewTasksCreated = 12
                    }
                }
            };

            _context.Users.Add(user1);
            _context.Users.Add(user2);
            _context.SaveChanges();

            var authMock = new Mock<IProcess<OrganizationAdminAuthorizationParams, AuthorizationResultViewModel>>();
            authMock.Setup(x => x.Execute(It.IsAny<OrganizationAdminAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true });

            IProcess<OrganizationMemberStatisticsParams, OrganizationMemberStatisticsViewModel> process = new OrganizationMetricQueryProcesses(_context, authMock.Object);

            // Act
            var result = process.Execute(new OrganizationMemberStatisticsParams { OrganizationId = org.Id });

            // Verify
            Assert.IsNotNull(result, "Process returned a null result");
            Assert.IsNotNull(result.MemberStats, "Resulting member list was null");
            Assert.AreEqual(2, result.MemberStats.Count, "Member list had an incorrect number of elements");
            Assert.IsTrue(result.MemberStats.Any(x => x.Id == user1.Id), "Member list did not contain the first user");
            Assert.IsTrue(result.MemberStats.Any(x => x.Id == user2.Id), "Member list did not contain the second user");
            Assert.AreEqual(org.Id, result.OrganizationId, "Organization Id was incorrect");

            var firstUser = result.MemberStats.Where(x => x.Id == user1.Id).Single();
            var metrics1 = user1.LastVisitedJobSearch.Metrics;
            Assert.AreEqual(user1.FullName, firstUser.FullName, "First user's full name was incorrect");
            Assert.AreEqual(user1.Email, firstUser.Email, "First user's email was incorrect");
            Assert.AreEqual(metrics1.NumApplyTasksCompleted, firstUser.Metrics.NumApplyTasksCompleted, "First user's number of apply tasks completed was incorrect");
            Assert.AreEqual(metrics1.NumApplyTasksCreated, firstUser.Metrics.NumApplyTasksCreated, "First user's number of apply tasks created was incorrect");
            Assert.AreEqual(metrics1.NumCompaniesCreated, firstUser.Metrics.NumCompaniesCreated, "First user's number of companies was incorrect");
            Assert.AreEqual(metrics1.NumContactsCreated, firstUser.Metrics.NumContactsCreated, "First user's number of contacts was incorrect");
            Assert.AreEqual(metrics1.NumInPersonInterviewTasksCreated, firstUser.Metrics.NumInPersonInterviewTasksCreated, "First user's number in person interview tasks was incorrect");
            Assert.AreEqual(metrics1.NumPhoneInterviewTasksCreated, firstUser.Metrics.NumPhoneInterviewTasksCreated, "First user's number of phone interview tasks was incorrect");

            var secondUser = result.MemberStats.Where(x => x.Id == user2.Id).Single();
            var metrics2 = user2.LastVisitedJobSearch.Metrics;
            Assert.AreEqual(user2.FullName, secondUser.FullName, "First user's full name was incorrect");
            Assert.AreEqual(user2.Email, secondUser.Email, "First user's email was incorrect");
            Assert.AreEqual(metrics2.NumApplyTasksCompleted, secondUser.Metrics.NumApplyTasksCompleted, "First user's number of apply tasks completed was incorrect");
            Assert.AreEqual(metrics2.NumApplyTasksCreated, secondUser.Metrics.NumApplyTasksCreated, "First user's number of apply tasks created was incorrect");
            Assert.AreEqual(metrics2.NumCompaniesCreated, secondUser.Metrics.NumCompaniesCreated, "First user's number of companies was incorrect");
            Assert.AreEqual(metrics2.NumContactsCreated, secondUser.Metrics.NumContactsCreated, "First user's number of contacts was incorrect");
            Assert.AreEqual(metrics2.NumInPersonInterviewTasksCreated, secondUser.Metrics.NumInPersonInterviewTasksCreated, "First user's number in person interview tasks was incorrect");
            Assert.AreEqual(metrics2.NumPhoneInterviewTasksCreated, secondUser.Metrics.NumPhoneInterviewTasksCreated, "First user's number of phone interview tasks was incorrect");
        }
        public void Throws_EntityNotFoundException_When_User_Not_Found()
        {
            // Setup
            var encryptionMock = new Mock<EncryptionUtils>();
            encryptionMock.Setup(x => x.EncryptStringToBytes_AES(It.IsAny<string>(), It.IsAny<byte[]>(), It.IsAny<byte[]>())).Returns(new byte[] { Convert.ToByte(true) });

            var user = new User { JigsawAccountDetails = new JigsawAccountDetails { Username = "******", EncryptedPassword = "******" } };
            _context.Users.Add(user);
            _context.SaveChanges();

            int id = user.Id + 101;
            _process = new JigsawAuthProcesses(_context, encryptionMock.Object);

            // Act
            try
            {
                _process.Execute(new SaveJigsawUserCredentialsParams { RequestingUserId = id });
                Assert.Fail("No exception was thrown");
            }

            // Verify
            catch (MJLEntityNotFoundException ex)
            {
                Assert.AreEqual(typeof(User), ex.EntityType, "Exception's entity type value was incorrect");
                Assert.AreEqual(id.ToString(), ex.IdValue, "Exception's id value was incorrect");
            }
        }
        public void Does_Not_Retrieve_Members_Of_Different_Organization()
        {
            // Setup 
            var org1 = new Organization();
            var org2 = new Organization();
            var user = new User { Organization = org2 };

            _context.Users.Add(user);
            _context.Organizations.Add(org1);
            _context.SaveChanges();

            var authMock = new Mock<IProcess<OrganizationAdminAuthorizationParams, AuthorizationResultViewModel>>();
            authMock.Setup(x => x.Execute(It.IsAny<OrganizationAdminAuthorizationParams>())).Returns(new AuthorizationResultViewModel { UserAuthorized = true });

            IProcess<OrganizationMemberStatisticsParams, OrganizationMemberStatisticsViewModel> process = new OrganizationMetricQueryProcesses(_context, authMock.Object);

            // Act
            var result = process.Execute(new OrganizationMemberStatisticsParams { OrganizationId = org1.Id });

            // Verify
            Assert.IsNotNull(result, "Process returned a null result");
            Assert.IsNotNull(result.MemberStats, "Process retured a null member list");
            Assert.AreEqual(0, result.MemberStats.Count, "Member list had an incorrect number of elements");
        }
 public MockMembershipService(User user)
 {
     _user = user;
 }