コード例 #1
0
        public async Task SetPropertiesAsync_UpdateProperties()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ExtendedObjectVersion>(Method.POST, "/REST/objects/1/2/latest/properties");

            // Create the object to send in the body.
            var body = new[]
            {
                new PropertyValue()
                {
                    PropertyDef = 0,
                    TypedValue  = new TypedValue()
                    {
                        DataType = MFDataType.Text,
                        Value    = "hello world"
                    }
                }
            };

            runner.SetExpectedRequestBody(body);

            // Execute.
            await runner.MFWSClient.ObjectPropertyOperations.SetPropertiesAsync(1, 2, body, false);

            // Verify.
            runner.Verify();
        }
        public async Task DemoteObjectsAsync()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <List <ExtendedObjectVersion> >(Method.PUT, "/REST/objects/demotemultiobjects");

            // Create the expected body.
            var body = new[]
            {
                new ObjID()
                {
                    Type = 0,
                    ID   = 123
                },
                new ObjID()
                {
                    Type = 0,
                    ID   = 456
                }
            };

            // Set the expected body.
            runner.SetExpectedRequestBody(body);

            // Execute.
            await runner.MFWSClient.ExternalObjectOperations.DemoteObjectsAsync(objectsToDemote : body);

            // Verify.
            runner.Verify();
        }
コード例 #3
0
        public async Task RenameObjectAsync_Unmanaged()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ObjectVersion>(Method.PUT, $"/REST/objects/0/uhello%3Aworld/uagain/title");

            // Set the expected body.
            var newObjectName = new PrimitiveType <string>()
            {
                Value = "renamed object"
            };

            runner.SetExpectedRequestBody(newObjectName);

            // Execute.
            await runner.MFWSClient.ObjectOperations.RenameObjectAsync(new ObjVer()
            {
                Type = 0,
                ExternalRepositoryName            = "hello",
                ExternalRepositoryObjectID        = "world",
                ExternalRepositoryObjectVersionID = "again"
            }, newObjectName.Value);

            // Verify.
            runner.Verify();
        }
        public async Task AddValueListItemValueListIDPopulatedAsync()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ValueListItem>(Method.POST, "/REST/valuelists/23/items");

            // Set the expected body.
            var newVLitem = new ValueListItem
            {
                ValueListID = 23,
                Name        = "new valuelistItem name"
            };

            runner.SetExpectedRequestBody(newVLitem);

            // Execute.
            await runner.MFWSClient.ValueListItemOperations.AddValueListItemAsync
            (
                23,
                new ValueListItem
            {
                Name = "new valuelistItem name"
            }
            );

            // Verify.
            runner.Verify();
        }
コード例 #5
0
        public void ExecuteExtensionMethod_OutputDeserialisation()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <MySerialisableObject>(Method.POST, "/REST/vault/extensionmethod/HelloWorld.aspx");

            // Set the request body.
            var inputValue = new MySerialisableObject
            {
                a = "b",
                x = 7
            };

            runner.SetExpectedRequestBody(inputValue.ToSerializedString());

            // Set the response body.
            var outputValue = new MySerialisableObject
            {
                a = "c",
                x = 123
            };

            runner.ResponseData = outputValue;

            // Execute
            var output = runner.MFWSClient
                         .ExtensionMethodOperations
                         .ExecuteVaultExtensionMethod <MySerialisableObject, MySerialisableObject>("HelloWorld", input: inputValue);

            // Verify.
            runner.Verify();

            // Response must be correct.
            Assert.AreEqual(outputValue, output);
        }
コード例 #6
0
        public async Task ExecuteExtensionMethodAsync_InputSerialisation()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner(Method.POST, "/REST/vault/extensionmethod/HelloWorld.aspx");

            // Set the request body.
            var inputValue = new MySerialisableObject
            {
                a = "b",
                x = 7
            };

            runner.SetExpectedRequestBody(inputValue.ToSerializedString());

            // Set the response body.
            const string outputValue = "Return value";

            runner.ResponseData = outputValue;

            // Execute
            var output = await runner.MFWSClient.ExtensionMethodOperations.ExecuteVaultExtensionMethodAsync("HelloWorld", input : inputValue);

            // Verify.
            runner.Verify();

            // Response body must be correct.
            Assert.AreEqual(outputValue, output);
        }
        public void AddValueListItem()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ValueListItem>(Method.POST, "/REST/valuelists/1/items");

            // Set the expected body.
            var newVLitem = new ValueListItem
            {
                ValueListID = 1,
                Name        = "new valuelistItem name"
            };

            runner.SetExpectedRequestBody(newVLitem);


            // Execute.
            runner.MFWSClient.ValueListItemOperations.AddValueListItem
            (
                1,
                newVLitem
            );

            // Verify.
            runner.Verify();
        }
コード例 #8
0
        public async Task AuthenticateUsingCredentialsAsync()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <PrimitiveType <string> >(Method.POST, "/REST/server/authenticationtokens");

            // When the execute method is called, return a dummy authentication token.
            runner.RestClientMock
            .Setup(c => c.ExecuteTaskAsync <PrimitiveType <string> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <PrimitiveType <string> > >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new PrimitiveType <string>()
                {
                    Value = "hello world"
                });

                //Return the mock object.
                return(Task.FromResult(response.Object));
            });

            // Create the object to send in the body.
            var body = new Authentication
            {
                VaultGuid  = Guid.NewGuid(),
                Username   = "******",
                Password   = "******",
                Expiration = new DateTime(2017, 01, 01, 0, 0, 0, DateTimeKind.Utc)
            };

            // We should post a collection of objvers (but only with this one in it).
            runner.SetExpectedRequestBody(body);

            // Execute.
            await runner.MFWSClient.AuthenticateUsingCredentialsAsync(body.VaultGuid.Value, body.Username, body.Password);

            // Verify.
            runner.Verify();

            // Authentication header must exist.
            var authenticationHeader = runner.MFWSClient
                                       .DefaultParameters
                                       .FirstOrDefault(h => h.Type == ParameterType.HttpHeader && h.Name == "X-Authentication");

            Assert.IsNotNull(authenticationHeader);
            Assert.AreEqual("hello world", authenticationHeader.Value);
        }
コード例 #9
0
        public void ExecuteExtensionMethod_CorrectRequestBody()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner(Method.POST, "/REST/vault/extensionmethod/HelloWorld.aspx");

            // Set the request body.
            const string inputValue = "this is my test input value";

            runner.SetExpectedRequestBody(inputValue);

            // Execute.
            runner.MFWSClient.ExtensionMethodOperations.ExecuteVaultExtensionMethod("HelloWorld", input: inputValue);

            // Verify.
            runner.Verify();
        }
コード例 #10
0
        public void GetMetadataStructureIDsByAliases()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <VaultStructureAliasResponse>(Method.POST, "/REST/structure/metadatastructure/itemidbyalias.aspx");

            // Set up the expected body.
            var body = new VaultStructureAliasRequest();

            runner.SetExpectedRequestBody(body);

            // Execute.
            runner.MFWSClient.GetMetadataStructureIDsByAliases(body);

            // Verify.
            runner.Verify();
        }
コード例 #11
0
        public void DeleteObject()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ObjectVersion>(Method.PUT, $"/REST/objects/0/1/deleted");

            // Set the expected request body.
            runner.SetExpectedRequestBody(new PrimitiveType <bool>()
            {
                Value = true
            });

            // Execute.
            runner.MFWSClient.ObjectOperations.DeleteObject(0, 1);

            // Verify.
            runner.Verify();
        }
コード例 #12
0
        public void GetPropertyDefIDsByAliases()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <Dictionary <string, int> >(Method.POST, "/REST/structure/properties/itemidbyalias.aspx");

            // Set up the expected body.
            var body = new JsonArray {
                "hello", "world", "third option"
            };

            runner.SetExpectedRequestBody(body);

            // Execute.
            runner.MFWSClient.PropertyDefOperations.GetPropertyDefIDsByAliases(aliases: new string[] { "hello", "world", "third option" });

            // Verify.
            runner.Verify();
        }
コード例 #13
0
        public async Task GetPropertyDefIDByAliasAsync()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <Dictionary <string, int> >(Method.POST, "/REST/structure/properties/itemidbyalias.aspx");

            // Set up the expected body.
            var body = new JsonArray {
                "hello world"
            };

            runner.SetExpectedRequestBody(body);

            // Execute.
            await runner.MFWSClient.PropertyDefOperations.GetPropertyDefIDByAliasAsync("hello world");

            // Verify.
            runner.Verify();
        }
コード例 #14
0
        public async Task GetObjectClassIDsByAliasesAsync()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <Dictionary <string, int> >(Method.POST, "/REST/structure/classes/itemidbyalias.aspx");

            // Set up the expected body.
            var body = new JsonArray {
                "hello", "world", "third option"
            };

            runner.SetExpectedRequestBody(body);

            // Execute.
            await runner.MFWSClient.ClassOperations.GetObjectClassIDsByAliasesAsync(aliases : new string[] { "hello", "world", "third option" });

            // Verify.
            runner.Verify();
        }
コード例 #15
0
        public void GetObjectClassIDByAlias()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <Dictionary <string, int> >(Method.POST, "/REST/structure/classes/itemidbyalias.aspx");

            // Set up the expected body.
            var body = new JsonArray {
                "hello world"
            };

            runner.SetExpectedRequestBody(body);

            // Execute.
            runner.MFWSClient.ClassOperations.GetObjectClassIDByAlias("hello world");

            // Verify.
            runner.Verify();
        }
コード例 #16
0
        public void SetWorkflowState()
        {
            var runner = new RestApiTestRunner <ExtendedObjectVersion>(Method.PUT, $"/REST/objects/0/1/2/workflowstate");

            runner.SetExpectedRequestBody(new ObjectWorkflowState()
            {
                StateID = 2
            });
            // Execute.
            runner.MFWSClient.ObjectPropertyOperations.SetWorkflowState(new ObjVer()
            {
                Type    = 0,
                ID      = 1,
                Version = 2
            }, 2);

            // Verify.
            runner.Verify();
        }
コード例 #17
0
        public async Task RenameFileAsync_WithVersionData()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ObjectVersion>(Method.PUT, "/REST/objects/1/2/4/files/3/5/title");

            // Create the object to send in the body.
            var body = new PrimitiveType <string>()
            {
                Value = "renamed.pdf"
            };

            // Set the expected request body.
            runner.SetExpectedRequestBody(body);

            // Execute.
            await runner.MFWSClient.ObjectFileOperations.RenameFileAsync(1, 2, 3, "renamed.pdf", 4, 5);

            // Verify.
            runner.Verify();
        }
コード例 #18
0
        public void AddToFavorites()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ExtendedObjectVersion>(Method.POST, $"/REST/favorites");

            // Set the expected body.
            var objId = new ObjID()
            {
                Type = 0,
                ID   = 1
            };

            runner.SetExpectedRequestBody(objId);

            // Execute.
            runner.MFWSClient.ObjectOperations.AddToFavorites(objId);

            // Verify.
            runner.Verify();
        }
コード例 #19
0
        public void RenameFileWithVersionData()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ObjectVersion>(Method.PUT, "/REST/objects/4/5/7/files/6/8/title");

            // Create the object to send in the body.
            var body = new PrimitiveType <string>()
            {
                Value = "renamed.pdf"
            };

            // Set the expected request body.
            runner.SetExpectedRequestBody(body);

            // Execute.
            runner.MFWSClient.ObjectFileOperations.RenameFile(4, 5, 6, "renamed.pdf", 7, 8);

            // Verify.
            runner.Verify();
        }
コード例 #20
0
        public void SetCheckoutStatus_CheckedOutToMe()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ObjectVersion>(Method.PUT, $"/REST/objects/0/1/latest/checkedout");

            // Set the expected body.
            runner.SetExpectedRequestBody(new PrimitiveType <MFCheckOutStatus>()
            {
                Value = MFCheckOutStatus.CheckedOutToMe
            });

            // Execute.
            runner.MFWSClient.ObjectOperations.SetCheckoutStatus(new ObjID()
            {
                Type = 0,
                ID   = 1
            }, MFCheckOutStatus.CheckedOutToMe);

            // Verify.
            runner.Verify();
        }
コード例 #21
0
        public async Task GetPropertiesOfMultipleObjectsAsync_ExceptionForNoVersion()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <List <List <PropertyValue> > >(Method.POST, "/REST/objects/properties.aspx");

            // Create the object to send in the body.
            var body = new ObjVer()
            {
                ID   = 2,
                Type = 1
            };

            // We should post a collection of objvers (but only with this one in it).
            runner.SetExpectedRequestBody(new[] { body });

            // Execute.
            await runner.MFWSClient.ObjectPropertyOperations.GetPropertiesOfMultipleObjectsAsync(body);

            // Verify.
            runner.Verify();
        }
コード例 #22
0
        public void SetCheckoutStatus_External_Latest()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ObjectVersion>(Method.PUT, $"/REST/objects/0/urepository%2Bname%3Amy%2Bobject/latest/checkedout");

            // Set the expected body.
            runner.SetExpectedRequestBody(new PrimitiveType <MFCheckOutStatus>()
            {
                Value = MFCheckOutStatus.CheckedOutToMe
            });

            // Execute.
            runner.MFWSClient.ObjectOperations.SetCheckoutStatus(new ObjVer()
            {
                Type = 0,
                ExternalRepositoryName     = "repository name",
                ExternalRepositoryObjectID = "my object"
            }, MFCheckOutStatus.CheckedOutToMe);

            // Verify.
            runner.Verify();
        }
コード例 #23
0
        public async Task GetAutomaticMetadataForTemporaryFilesAsync()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <List <PropertyValueSuggestion> >(Method.POST, "/REST/objects/automaticmetadata.aspx");

            // Set up the expected body.
            var body = new AutomaticMetadataRequestInfo()
            {
                UploadIds = new List <int>()
                {
                    123, 456
                }
            };

            runner.SetExpectedRequestBody(body);

            // Execute.
            await runner.MFWSClient.AutomaticMetadataOperations.GetAutomaticMetadataForTemporaryFilesAsync(temporaryFileIds : body.UploadIds.ToArray());

            // Verify.
            runner.Verify();
        }
コード例 #24
0
        public async Task RenameObjectAsync()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <ObjectVersion>(Method.PUT, $"/REST/objects/1/2/latest/title");

            // Set the expected body.
            var newObjectName = new PrimitiveType <string>()
            {
                Value = "renamed object"
            };

            runner.SetExpectedRequestBody(newObjectName);

            // Execute.
            await runner.MFWSClient.ObjectOperations.RenameObjectAsync(new ObjID()
            {
                Type = 1,
                ID   = 2
            }, newObjectName.Value);

            // Verify.
            runner.Verify();
        }
コード例 #25
0
        public async Task LogInWithExtensionAuthenticationAsync()
        {
            // Set the target ID.
            var targetID = "hello world";

            // Create our test runner.
            var runner = new RestApiTestRunner <RepositoryAuthenticationStatus>(Method.POST, $"/REST/repositories/{HttpUtility.UrlEncode(targetID)}/session.aspx");

            // Create the body.
            var authentication = new RepositoryAuthentication()
            {
                ConfigurationName = "hello"
            };

            // Set the expected body.
            runner.SetExpectedRequestBody(authentication);

            // Execute.
            await runner.MFWSClient.ExtensionAuthenticationOperations.LogInWithExtensionAuthenticationAsync(targetID, authentication);

            // Verify.
            runner.Verify();
        }
コード例 #26
0
        public async Task AuthenticateUsingCredentialsAsync()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <PrimitiveType <string> >(Method.POST, "/REST/server/authenticationtokens");

            // When the execute method is called, return a dummy authentication token.
            runner.ResponseData = new PrimitiveType <string>()
            {
                Value = "hello world"
            };

            // Create the object to send in the body.
            var body = new Authentication
            {
                VaultGuid  = Guid.NewGuid(),
                Username   = "******",
                Password   = "******",
                SessionID  = "mySessionId",
                Expiration = new DateTime(2017, 01, 01, 0, 0, 0, DateTimeKind.Utc)
            };

            runner.SetExpectedRequestBody(body);

            // Execute.
            await runner.MFWSClient.AuthenticateUsingCredentialsAsync(body.VaultGuid.Value, body.Username, body.Password, body.Expiration.Value, body.SessionID);

            // Verify.
            runner.Verify();

            // Authentication header must exist.
            var authenticationHeader = runner.MFWSClient
                                       .DefaultParameters
                                       .FirstOrDefault(h => h.Type == ParameterType.HttpHeader && h.Name == "X-Authentication");

            Assert.IsNotNull(authenticationHeader);
            Assert.AreEqual("hello world", authenticationHeader.Value);
        }
コード例 #27
0
        public async Task ExecuteExtensionMethodAsync_CorrectOutput()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner(Method.POST, "/REST/vault/extensionmethod/HelloWorld.aspx");

            // Set the request body.
            const string inputValue = "this is my test input value";

            runner.SetExpectedRequestBody(inputValue);

            // Set the response body.
            const string outputValue = "Return value";

            runner.ResponseData = outputValue;

            // Execute.
            var output = await runner.MFWSClient.ExtensionMethodOperations.ExecuteVaultExtensionMethodAsync("HelloWorld", input : inputValue);

            // Verify.
            runner.Verify();

            // Response body must be correct.
            Assert.AreEqual(outputValue, output);
        }
コード例 #28
0
        public void GetAutomaticMetadataForObject()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <List <PropertyValueSuggestion> >(Method.POST, "/REST/objects/automaticmetadata.aspx");

            // Set up the expected body.
            var body = new AutomaticMetadataRequestInfo()
            {
                ObjVer = new ObjVer()
                {
                    Type    = 0,
                    ID      = 43,
                    Version = 0
                }
            };

            runner.SetExpectedRequestBody(body);

            // Execute.
            runner.MFWSClient.AutomaticMetadataOperations.GetAutomaticMetadataForObject(body.ObjVer);

            // Verify.
            runner.Verify();
        }
        public async Task PromoteObjectsAsync()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <List <ExtendedObjectVersion> >(Method.PUT, "/REST/objects/setmultipleobjproperties");

            // Create the expected body.
            var body = new ObjectsUpdateInfo()
            {
                MultipleObjectInfo = new[]
                {
                    new ObjectVersionUpdateInformation()
                    {
                        ObjVer = new ObjVer()
                        {
                            ExternalRepositoryName            = "hello world",
                            ExternalRepositoryObjectID        = "my object id",
                            ExternalRepositoryObjectVersionID = "version",
                            Type = 0
                        },
                        Properties = new List <PropertyValue>
                        {
                            new PropertyValue()
                            {
                                PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass,
                                TypedValue  = new TypedValue()
                                {
                                    Lookup = new Lookup()
                                    {
                                        Item = (int)MFBuiltInDocumentClass.MFBuiltInDocumentClassOtherDocument
                                    }
                                }
                            }
                        }
                    },
                    new ObjectVersionUpdateInformation()
                    {
                        ObjVer = new ObjVer()
                        {
                            ExternalRepositoryName            = "hello world",
                            ExternalRepositoryObjectID        = "my object id 2",
                            ExternalRepositoryObjectVersionID = "version 2",
                            Type = 0
                        },
                        Properties = new List <PropertyValue>
                        {
                            new PropertyValue()
                            {
                                PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass,
                                TypedValue  = new TypedValue()
                                {
                                    Lookup = new Lookup()
                                    {
                                        Item = (int)MFBuiltInDocumentClass.MFBuiltInDocumentClassOtherDocument
                                    }
                                }
                            }
                        }
                    }
                }.ToList()
            };

            // Set the expected body.
            runner.SetExpectedRequestBody(body);

            // Execute.
            await runner.MFWSClient.ExternalObjectOperations.PromoteObjectsAsync(
                objectVersionUpdateInformation : body.MultipleObjectInfo.ToArray());

            // Verify.
            runner.Verify();
        }
コード例 #30
0
        public void SetPropertiesOfMultipleObjects()
        {
            // Create our test runner.
            var runner = new RestApiTestRunner <List <ExtendedObjectVersion> >(Method.PUT, "/REST/objects/setmultipleobjproperties");

            // Create the expected body.
            var body = new ObjectsUpdateInfo()
            {
                MultipleObjectInfo = new[]
                {
                    new ObjectVersionUpdateInformation()
                    {
                        ObjVer = new ObjVer()
                        {
                            Type    = 0,
                            ID      = 1,
                            Version = 2
                        },
                        Properties = new List <PropertyValue>
                        {
                            new PropertyValue()
                            {
                                PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass,
                                TypedValue  = new TypedValue()
                                {
                                    Lookup = new Lookup()
                                    {
                                        Item = (int)MFBuiltInDocumentClass.MFBuiltInDocumentClassOtherDocument
                                    }
                                }
                            }
                        }
                    },
                    new ObjectVersionUpdateInformation()
                    {
                        ObjVer = new ObjVer()
                        {
                            Type    = 0,
                            ID      = 2,
                            Version = 1
                        },
                        Properties = new List <PropertyValue>
                        {
                            new PropertyValue()
                            {
                                PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass,
                                TypedValue  = new TypedValue()
                                {
                                    Lookup = new Lookup()
                                    {
                                        Item = (int)MFBuiltInDocumentClass.MFBuiltInDocumentClassOtherDocument
                                    }
                                }
                            }
                        }
                    }
                }.ToList()
            };

            // Set the expected body.
            runner.SetExpectedRequestBody(body);

            // Execute.
            runner.MFWSClient.ExternalObjectOperations.PromoteObjects(
                objectVersionUpdateInformation: body.MultipleObjectInfo.ToArray());

            // Verify.
            runner.Verify();
        }