예제 #1
0
        public void test_initialize()
        {
            Mock <IHelper> mockHelper = new Mock <IHelper>();

            mockHelper.Setup(p => p.GetDBContext(It.IsAny <int>()))
            .Returns <int>(workspaceID =>
            {
                if (workspaceID == 0)
                {
                    throw new ArgumentException();
                }
                return(new DBContext(new kCura.Data.RowDataGateway.Context(c_SQLServerName, string.Format("EDDS{0}", workspaceID == -1 ? string.Empty : workspaceID.ToString()), c_SQLUser, c_SQLPassword)));;
            });
            mockHelper.Setup(p => p.GetServicesManager())
            .Returns(() =>
            {
                Mock <IServicesMgr> svcMgr = new Mock <IServicesMgr>();
                svcMgr.Setup(p => p.CreateProxy <IRSAPIClient>(It.IsAny <ExecutionIdentity>()))
                .Returns <ExecutionIdentity>(eid =>
                {
                    var rc = new RSAPIClient(new Uri(c_ServerURL), new UsernamePasswordCredentials(c_RelativityUser, c_RelativityPassword));
                    rc.Login();
                    return(rc);
                });
                return(svcMgr.Object);
            });
            NSerio.Relativity.RepositoryHelper.ConfigureRepository(mockHelper.Object);
        }
        /// <summary>
        /// Gets the RSAPIClient with IntegratedAuth
        /// </summary>
        /// <param name="workspaceId"></param>
        /// <returns></returns>
        private IRSAPIClient GetRsapiIntegrated(int workspaceId = -1)
        {
            var          creds = new kCura.Relativity.Client.IntegratedAuthCredentials();
            IRSAPIClient proxy = new RSAPIClient(
                ServicesUri,
                creds);

            proxy.APIOptions.WorkspaceID = workspaceId;
            proxy.Login();
            return(proxy);
        }
        /// <summary>
        /// Returns the RSAPIClient with the given workspace
        /// </summary>
        /// <param name="workspaceId"></param>
        /// <returns></returns>
        public IRSAPIClient GetRsapiClient(int workspaceId = -1)
        {
            switch (_authType)
            {
            case Constants.Enums.AuthType.Integrated:
                return(GetRsapiIntegrated(workspaceId));

            case Constants.Enums.AuthType.UsernamePassword:
                IRSAPIClient proxy = new RSAPIClient(
                    ServicesUri,
                    new kCura.Relativity.Client.UsernamePasswordCredentials(_user, _password));
                //proxy.APIOptions.WorkspaceID = DefaultWorkspaceId;
                proxy.APIOptions.WorkspaceID = workspaceId;
                proxy.Login();
                return(proxy);

            default:
                return(GetRsapiIntegrated(workspaceId));
            }
        }