public void TestTryToAddPeopleWhenUserAlreadyExists1()
        {
            #region Arrange
            //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null));
            new FakeUsers(3, UserRepository);
            new FakeWorkgroupPermissions(0, WorkgroupPermissionRepository);
            var failCount = 0;
            var dupCount  = 0;
            var notAdded  = new List <KeyValuePair <string, string> >();
            new FakeRoles(3, RepositoryFactory.RoleRepository);
            new FakeWorkgroups(3, WorkgroupRepository);
            #endregion Arrange

            #region Act
            var result = WorkgroupService.TryToAddPeople(1, RepositoryFactory.RoleRepository.Queryable.Single(a => a.Id == "2"), new Workgroup(), 0, "2", ref failCount, ref dupCount, notAdded);
            #endregion Act

            #region Assert
            Assert.AreEqual(1, result);
            Assert.AreEqual(0, failCount);
            Assert.AreEqual(0, dupCount);
            Assert.AreEqual(0, notAdded.Count());
            EmailPreferencesRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <EmailPreferences> .Is.Anything));
            WorkgroupPermissionRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <WorkgroupPermission> .Is.Anything));
            var args = (WorkgroupPermission)WorkgroupPermissionRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <WorkgroupPermission> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("2", args.Role.Id);
            Assert.AreEqual("2", args.User.Id);
            Assert.AreEqual(1, args.Workgroup.Id);
            UserIdentity.AssertWasCalled(a => a.RemoveUserRoleFromCache(Resources.Role_CacheId, "2"));
            #endregion Assert
        }
        public void TestTryToAddPeopleWhenUserIsFoundWithLdap1()
        {
            #region Arrange
            //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null));
            new FakeUsers(3, UserRepository);
            new FakeWorkgroupPermissions(0, WorkgroupPermissionRepository);
            var failCount = 0;
            var dupCount  = 0;
            var notAdded  = new List <KeyValuePair <string, string> >();
            new FakeRoles(3, RepositoryFactory.RoleRepository);
            new FakeWorkgroups(3, WorkgroupRepository);
            var directoryUser = new DirectoryUser();
            directoryUser.LoginId      = "3";
            directoryUser.EmailAddress = "*****@*****.**";
            directoryUser.FirstName    = "F3";
            directoryUser.LastName     = "Last3";
            SearchService.Expect(a => a.FindUser("LDAP")).Return(directoryUser);
            #endregion Arrange

            #region Act
            var result = WorkgroupService.TryToAddPeople(1, RepositoryFactory.RoleRepository.Queryable.Single(a => a.Id == "2"), new Workgroup(), 0, "LDAP", ref failCount, ref dupCount, notAdded);
            #endregion Act

            #region Assert
            Assert.AreEqual(1, result);
            Assert.AreEqual(0, failCount);
            Assert.AreEqual(0, dupCount);
            Assert.AreEqual(0, notAdded.Count());
            UserRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            EmailPreferencesRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <EmailPreferences> .Is.Anything));
            WorkgroupPermissionRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <WorkgroupPermission> .Is.Anything));
            var args = (WorkgroupPermission)WorkgroupPermissionRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <WorkgroupPermission> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("2", args.Role.Id);
            Assert.AreEqual("3", args.User.Id);
            Assert.AreEqual(1, args.Workgroup.Id);
            #endregion Assert
        }