public void TestTryToAddPeopleWhenUserIsFoundWithLdap2()
        {
            #region Arrange
            //HttpContext.Current = new HttpContext(new HttpRequest(null, "http://test.org", null), new HttpResponse(null));
            //new FakeUsers(3, UserRepository);
            UserRepository.Expect(a => a.GetNullableById("LDAP")).Return(null).Repeat.Twice();
            UserRepository.Expect(a => a.GetNullableById("LDAP")).Return(CreateValidEntities.User(3)).Repeat.Once();

            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      = "LDAP";
            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.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            EmailPreferencesRepository.AssertWasCalled(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
        }
        public void TestTryToAddPeopleWhenUserIsNotFound1()
        {
            #region Arrange
            new FakeUsers(0, UserRepository);
            SearchService.Expect(a => a.FindUser(Arg <string> .Is.Anything)).Return(null);
            var failCount = 0;
            var dupCount  = 0;
            var notAdded  = new List <KeyValuePair <string, string> >();
            #endregion Arrange

            #region Act
            var result = WorkgroupService.TryToAddPeople(1, new Role(), new Workgroup(), 0, "test", ref failCount, ref dupCount, notAdded);
            #endregion Act

            #region Assert
            UserRepository.AssertWasCalled(a => a.GetNullableById("test"));
            SearchService.AssertWasCalled(a => a.FindUser("test"));
            Assert.AreEqual(1, failCount);
            Assert.AreEqual(0, dupCount);
            Assert.AreEqual(0, result);
            Assert.AreEqual(1, notAdded.Count());
            Assert.AreEqual("Not found", notAdded[0].Value);
            Assert.AreEqual("test", notAdded[0].Key);
            #endregion Assert
        }