Exemplo n.º 1
0
        public void CreateOrUpdateAccountGroupAccountInvitationTest()
        {
            string      email    = GetNewEmailAddress();
            AccountTest _account = new AccountTest();

            WebAccountService.TransitAccount t_user = _account.GetTransitInstance();
            t_user.Id = _account.EndPoint.CreateAccount(string.Empty, email, t_user);
            Assert.AreNotEqual(0, t_user.Id);
            Console.WriteLine("Created account: {0}", t_user.Id);
            // only members can create invitations
            WebGroupService.TransitAccountGroupAccountInvitation t_instance = GetTransitInstance();
            t_instance.AccountId   = t_user.Id;
            t_instance.RequesterId = _user.id;
            try
            {
                // make sure the user is not a member of the group
                Assert.IsNull(EndPoint.GetAccountGroupAccountByAccountGroupId(
                                  GetAdminTicket(), _user.id, _group_id));
                // create the account group invitation
                EndPoint.CreateOrUpdateAccountGroupAccountInvitation(_user.ticket, t_instance);
                Assert.IsTrue(false, "Expected Access Denied exception.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}", ex.Message);
                Assert.AreEqual("System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> SnCore.Services.ManagedAccount+AccessDeniedException: Access denied",
                                ex.Message.Split("\n".ToCharArray(), 2)[0],
                                string.Format("Unexpected exception: {0}", ex.Message));
            }
            // the user joins the group
            WebGroupService.TransitAccountGroupAccount t_accountinstance = new WebGroupService.TransitAccountGroupAccount();
            t_accountinstance.AccountGroupId  = _group_id;
            t_accountinstance.AccountId       = _user.id;
            t_accountinstance.IsAdministrator = false;
            t_accountinstance.Id = EndPoint.CreateOrUpdateAccountGroupAccount(GetAdminTicket(), t_accountinstance);
            // make sure the invitation can be now sent
            t_instance.Id = EndPoint.CreateOrUpdateAccountGroupAccountInvitation(_user.ticket, t_instance);
            Assert.AreNotEqual(0, t_instance.Id);

            // TODO: make sure another user can't see invitation
        }
Exemplo n.º 2
0
        public void AcceptAccountGroupAccountInvitationTest()
        {
            // login user
            string      email    = GetNewEmailAddress();
            AccountTest _account = new AccountTest();

            WebAccountService.TransitAccount t_user = _account.GetTransitInstance();
            t_user.Id = _account.EndPoint.CreateAccount(string.Empty, email, t_user);
            Assert.AreNotEqual(0, t_user.Id);
            Console.WriteLine("Created account: {0}", t_user.Id);
            string userticket = _account.Login(email, t_user.Password);

            // join user to group
            WebGroupService.TransitAccountGroupAccount t_account = new WebGroupService.TransitAccountGroupAccount();
            t_account.AccountGroupId  = _group_id;
            t_account.AccountId       = t_user.Id;
            t_account.IsAdministrator = false;
            t_account.Id = EndPoint.CreateOrUpdateAccountGroupAccount(userticket, t_account);
            Assert.AreNotEqual(0, t_account.Id);
            Console.WriteLine("Joined user: {0}", t_account.Id);
            // update the group to private
            WebGroupService.TransitAccountGroup t_group = EndPoint.GetAccountGroupById(GetAdminTicket(), _group_id);
            t_group.IsPrivate = true;
            EndPoint.CreateOrUpdateAccountGroup(GetAdminTicket(), t_group);
            Console.WriteLine("Updated group to private: {0}", _group_id);
            // create an invitatoin for user
            WebGroupService.TransitAccountGroupAccountInvitation t_instance = new WebGroupService.TransitAccountGroupAccountInvitation();
            t_instance.AccountGroupId = _group_id;
            t_instance.AccountId      = _user.id;
            t_instance.RequesterId    = t_account.AccountId;
            t_instance.Message        = GetNewString();
            t_instance.Id             = EndPoint.CreateOrUpdateAccountGroupAccountInvitation(GetAdminTicket(), t_instance);
            Console.WriteLine("Created invitation: {0}", t_instance.Id);
            // make sure the user isn't member of the group
            Assert.IsNull(EndPoint.GetAccountGroupAccountByAccountGroupId(GetAdminTicket(), _user.id, _group_id));
            // get the pending group membership requests
            WebGroupService.TransitAccountGroupAccountRequest[] requests1 = EndPoint.GetAccountGroupAccountRequests(
                GetAdminTicket(), _group_id, null);
            Console.WriteLine("Pending requests: {0}", requests1.Length);
            // accept invitation
            EndPoint.AcceptAccountGroupAccountInvitation(_user.ticket, t_instance.Id, GetNewString());
            // this has created a new request on the group, it should be +1
            WebGroupService.TransitAccountGroupAccountRequest[] requests2 = EndPoint.GetAccountGroupAccountRequests(
                GetAdminTicket(), _group_id, null);
            Console.WriteLine("Pending requests: {0}", requests2.Length);
            Assert.AreEqual(requests1.Length + 1, requests2.Length);
            // make sure there's an AccountId in the requests for the user
            WebGroupService.TransitAccountGroupAccountRequest request = null;
            Assert.IsTrue(new TransitServiceCollection <WebGroupService.TransitAccountGroupAccountRequest>(requests2).ContainsId(
                              _user.id, "AccountId", out request));
            Assert.IsNotNull(request);
            Console.WriteLine("New request: {0}", request.Id);
            // accept the request by admin
            EndPoint.AcceptAccountGroupAccountRequest(GetAdminTicket(), request.Id, GetNewString());
            // make sure the invitation was deleted
            Assert.IsNull(EndPoint.GetAccountGroupAccountInvitationById(_user.ticket, t_instance.Id));
            // make sure the request cannot be found any more
            WebGroupService.TransitAccountGroupAccountRequest[] requests3 = EndPoint.GetAccountGroupAccountRequests(
                GetAdminTicket(), _group_id, null);
            Console.WriteLine("Pending requests: {0}", requests3.Length);
            Assert.AreEqual(requests1.Length, requests3.Length);
            // make sure the user is member of the group
            WebGroupService.TransitAccountGroupAccount t_groupaccount = EndPoint.GetAccountGroupAccountByAccountGroupId(
                GetAdminTicket(), _user.id, _group_id);
            Assert.IsNotNull(t_groupaccount);
            Console.WriteLine("Account: {0}", t_groupaccount.Id);
            Assert.AreEqual(t_groupaccount.AccountId, _user.id);
            _account.Delete(GetAdminTicket(), t_user.Id);
        }