protected override void InternalValidate()
 {
     TaskLogger.LogEnter();
     try
     {
         base.InternalValidate();
         if (!base.HasErrors)
         {
             this.ServerObject = TestLiveIdAuthenticationTask.EnsureSingleObject <Server>(() => this.Server.GetObjects <Server>(null, this.SystemConfigurationSession));
             if (this.ServerObject == null)
             {
                 throw new CasHealthMailboxServerNotFoundException(this.Server.ToString());
             }
             if (this.MailboxCredential == null)
             {
                 this.GetTestMailbox();
             }
         }
     }
     catch (LocalizedException exception)
     {
         this.WriteError(exception, ErrorCategory.OperationStopped, this, true);
     }
     finally
     {
         TaskLogger.LogExit();
     }
 }
        internal static NetworkCredential GetDefaultTestAccount(TestLiveIdAuthenticationTask.ClientAccessContext context, LiveIdAuthenticationUserTypeEnum userType)
        {
            SmtpAddress?defaultTestUser = null;

            if (!TestConnectivityCredentialsManager.IsExchangeMultiTenant())
            {
                throw new InvalidOperationException();
            }
            if (userType <= LiveIdAuthenticationUserTypeEnum.ManagedBusiness)
            {
                if (userType != LiveIdAuthenticationUserTypeEnum.ManagedConsumer)
                {
                    if (userType == LiveIdAuthenticationUserTypeEnum.ManagedBusiness)
                    {
                        defaultTestUser = TestConnectivityCredentialsManager.GetMultiTenantAutomatedTaskUser(context.Instance, context.ConfigurationSession, context.Site, DatacenterUserType.BPOS);
                    }
                }
                else
                {
                    defaultTestUser = TestConnectivityCredentialsManager.GetMultiTenantAutomatedTaskUser(context.Instance, context.ConfigurationSession, context.Site, DatacenterUserType.EDU);
                }
            }
            else if (userType == LiveIdAuthenticationUserTypeEnum.FederatedConsumer || userType == LiveIdAuthenticationUserTypeEnum.FederatedBusiness)
            {
                throw new MailboxNotFoundException(new MailboxIdParameter(), null);
            }
            if (defaultTestUser == null)
            {
                throw new MailboxNotFoundException(new MailboxIdParameter(), null);
            }
            MailboxIdParameter localMailboxId = new MailboxIdParameter(string.Format("{0}", defaultTestUser.Value.Local));
            ADUser             aduser         = TestLiveIdAuthenticationTask.EnsureSingleObject <ADUser>(() => localMailboxId.GetObjects <ADUser>(null, TestLiveIdAuthenticationTask.GetRecipientSession(defaultTestUser.GetValueOrDefault().Domain)));

            if (aduser == null)
            {
                throw new MailboxNotFoundException(new MailboxIdParameter(defaultTestUser.ToString()), null);
            }
            ExchangePrincipal exchangePrincipal = ExchangePrincipal.FromADUser(aduser.OrganizationId.ToADSessionSettings(), aduser);

            if (exchangePrincipal == null)
            {
                throw new MailboxNotFoundException(new MailboxIdParameter(defaultTestUser.ToString()), null);
            }
            NetworkCredential  networkCredential  = new NetworkCredential(defaultTestUser.Value.ToString(), string.Empty, context.WindowsDomain);
            NetworkCredential  networkCredential2 = TestLiveIdAuthenticationTask.MakeCasCredential(networkCredential);
            LocalizedException ex = TestConnectivityCredentialsManager.LoadAutomatedTestCasConnectivityInfo(exchangePrincipal, networkCredential2);

            if (ex != null)
            {
                throw ex;
            }
            networkCredential.Domain   = defaultTestUser.Value.Domain;
            networkCredential.Password = networkCredential2.Password;
            return(networkCredential);
        }
        private void GetTestMailbox()
        {
            ADSite localSite = this.SystemConfigurationSession.GetLocalSite();

            base.WriteVerbose(Strings.RunCmdletOnSite(localSite.ToString()));
            string domain = this.ServerObject.Domain;

            base.WriteVerbose(Strings.RunCmdletOnDomain(domain));
            NetworkCredential defaultTestAccount = TestLiveIdAuthenticationTask.GetDefaultTestAccount(new TestLiveIdAuthenticationTask.ClientAccessContext
            {
                Instance             = this,
                MonitoringContext    = this.MonitoringContext,
                ConfigurationSession = this.SystemConfigurationSession,
                WindowsDomain        = domain,
                Site = localSite
            }, this.UserType);

            base.WriteVerbose(Strings.RunCmdletOnUser(defaultTestAccount.UserName));
            this.MailboxCredential = TestLiveIdAuthenticationTask.MakePSCredential(defaultTestAccount);
        }