Ejemplo n.º 1
0
        private IRsapiProvider GetChoiceRsapiProvider(int?singleChoiceId, int[] multipleChoiceIds)
        {
            var providerMock = new Mock <IRsapiProvider>(MockBehavior.Strict);

            // setup the RDO Read

            var multipleGuid = typeof(GravityLevelOne)
                               .GetProperty(nameof(GravityLevelOne.MultipleChoiceFieldChoices))
                               .GetCustomAttribute <RelativityObjectFieldAttribute>()
                               .FieldGuid;

            var singleGuid = typeof(GravityLevelOne)
                             .GetProperty(nameof(GravityLevelOne.SingleChoice))
                             .GetCustomAttribute <RelativityObjectFieldAttribute>()
                             .FieldGuid;

            var rdo = TestObjectHelper.GetStubRDO <GravityLevelOne>(RootArtifactID);

            rdo[singleGuid].ValueAsSingleChoice     = singleChoiceId == null ? null : new Choice(singleChoiceId.Value);
            rdo[multipleGuid].ValueAsMultipleChoice = multipleChoiceIds?.Select(x => new Choice(x)).ToList() ?? new List <Choice>();

            providerMock.Setup(x => x.ReadSingle(RootArtifactID)).Returns(rdo);

            // setup the child object query
            providerMock.Setup(x => x.Query(It.IsAny <Query <RDO> >())).Returns(new[] { new RDO[0].ToSuccessResultSet <QueryResultSet <RDO> >() });

            // setup the choice query

            // results in ArtifactIDs 1, 2, 3
            var singleChoiceGuids = ChoiceCacheTests.GetOrderedGuids <SingleChoiceFieldChoices>();

            providerMock.Setup(ChoiceCacheTests.SetupExpr(singleChoiceGuids)).Returns(ChoiceCacheTests.GetResults(singleChoiceGuids, 1));
            // results in ArtifactIDs 11, 12, 13
            var multiChoiceGuids = ChoiceCacheTests.GetOrderedGuids <MultipleChoiceFieldChoices>();

            providerMock.Setup(ChoiceCacheTests.SetupExpr(multiChoiceGuids)).Returns(ChoiceCacheTests.GetResults(multiChoiceGuids, 11));

            return(providerMock.Object);
        }
Ejemplo n.º 2
0
        public void Execute_TestFixtureSetup()
        {
            try
            {
                //Start of test and setup
                Console.WriteLine("Test START.....");
                Console.WriteLine("Enter Test Fixture Setup.....");
                var helper = new TestHelper();

                //Setup for testing
                Console.WriteLine("Creating Test Helper Services Manager based on App.Config file settings.");
                _servicesManager = helper.GetServicesManager();
                Console.WriteLine("Services Manager Created.");

                Console.WriteLine("Creating workspace.....");
                if (!_debug)
                {
                    _workspaceId =
                        CreateWorkspace.CreateWorkspaceAsync(_workspaceName,
                                                             ConfigurationHelper.TEST_WORKSPACE_TEMPLATE_NAME, _servicesManager, ConfigurationHelper.ADMIN_USERNAME,
                                                             ConfigurationHelper.DEFAULT_PASSWORD).Result;
                    Console.WriteLine($"Workspace created [WorkspaceArtifactId= {_workspaceId}].....");
                }
                else
                {
                    //must point _workspaceId = valid workspace with application already installed
                    _workspaceId = _debugWorkspaceId;
                    Console.WriteLine($"Using existing workspace [WorkspaceArtifactId= {_workspaceId}].....");
                }


                Console.WriteLine("Creating RSAPI and Service Factory.....");
                try
                {
                    _eddsDbContext = helper.GetDBContext(-1);
                    _dbContext     = helper.GetDBContext(_workspaceId);

                    //create client
                    _client = _servicesManager.GetProxy <IRSAPIClient>(ConfigurationHelper.ADMIN_USERNAME, ConfigurationHelper.DEFAULT_PASSWORD);

                    LogStart("Application Import");
                    if (!_debug)
                    {
                        //Import Application
                        Relativity.Test.Helpers.Application.ApplicationHelpers.ImportApplication(_client, _workspaceId, true, _applicationFilePath, _applicationName);
                        LogEnd("Application Import");
                    }
                    else
                    {
                        Console.WriteLine($"Using existing application");
                    }



                    _client.APIOptions.WorkspaceID = _workspaceId;
                }
                catch (Exception ex)
                {
                    throw new Exception("Error encountered while creating new RSAPI Client and/or Service Proxy.", ex);
                }
                finally
                {
                    Console.WriteLine("Created RSAPI and Service Factory.....");
                }

                Console.WriteLine("Creating TestObject Helper.");
                //1 retry setting because I want to know if it fails quickly while debugging, may bump up for production
                _testObjectHelper = new TestObjectHelper(_servicesManager, _workspaceId, 1);
                Console.WriteLine("TestObject Helper Created.");
            }
            catch (Exception ex)
            {
                throw new Exception("Error encountered in Test Setup.", ex);
            }
            finally
            {
                Console.WriteLine("Exit Test Fixture Setup.....");
            }
        }