public void AddApiTest_FileNotFound()
        {
            var testFile = TestFiles.NotExist;
            var options  = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        SearchCriteria = new SearchCriteriaWithoutValue
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Creator",
                                    Category = "Person"
                                }
                            }
                        },
                        Value = "New Value",
                        Type  = "String"
                    }
                }
            };

            var request = new AddRequest(options);

            var ex = Assert.Throws <ApiException>(() => { MetadataApi.Add(request); });

            Assert.AreEqual($"Can't find file located at '{testFile.FullName}'.", ex.Message);
        }
        public void AddApiTest_PropertyName()
        {
            var testFile = TestFiles.Doc;
            var now      = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss");

            var options = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        Value          = now,
                        Type           = "DateTime",
                        SearchCriteria = new SearchCriteria
                        {
                            NameOptions = new NameOptions
                            {
                                Value = "print"
                            }
                        },
                    }
                }
            };

            var request = new AddRequest(options);

            var result = MetadataApi.Add(request);

            Assert.IsNotNull(result);
            Assert.IsNotEmpty(result.Path);
            Assert.IsNotEmpty(result.Url);
            Assert.Greater(result.AddedCount, 0);
        }
        public void AddApiTest_UnsupportedFormat()
        {
            var testFile = TestFiles.Json;
            var options  = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        SearchCriteria = new SearchCriteriaWithoutValue
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Creator",
                                    Category = "Person"
                                }
                            }
                        },
                        Value = "New Value",
                        Type  = "String"
                    }
                }
            };

            var request = new AddRequest(options);

            var ex = Assert.Throws <ApiException>(() => { MetadataApi.Add(request); });

            Assert.AreEqual($"The specified file '{testFile.FullName}' has type which is not currently supported.", ex.Message);
        }
        public void AddApiTest_ValueFormatException()
        {
            var testFile = TestFiles.Jpg;
            var options  = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        SearchCriteria = new SearchCriteriaWithoutValue
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Printed",
                                    Category = "Time"
                                }
                            }
                        },
                        Value = "New Value",
                        Type  = "DateTime"
                    }
                }
            };

            var request = new AddRequest(options);
            var ex      = Assert.Throws <ApiException>(() => { MetadataApi.Add(request); });

            Assert.AreEqual(ex.Message, "Request parameters missing or have incorrect format");
        }
        public void AddApiTestWrongValueTypeForTag()
        {
            var testFile = TestFiles.Docx;
            var options  = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        SearchCriteria = new SearchCriteriaWithoutValue
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Printed",
                                    Category = "Time"
                                }
                            }
                        },
                        Value = "New Value",
                        Type  = "String"
                    }
                }
            };

            var request = new AddRequest(options);

            var ex = Assert.Throws <ApiException>(() => { MetadataApi.Add(request); });

            Assert.AreEqual($"There are no changes in metadata.", ex.Message);
        }
        public void AddApiTest()
        {
            var now      = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss");
            var testFile = TestFiles.Docx;
            var options  = new AddOptions
            {
                FileInfo   = testFile.ToFileInfo(),
                Properties = new List <AddProperty>
                {
                    new AddProperty
                    {
                        SearchCriteria = new SearchCriteriaWithoutValue
                        {
                            TagOptions = new TagOptions
                            {
                                ExactTag = new Tag
                                {
                                    Name     = "Printed",
                                    Category = "Time"
                                }
                            }
                        },
                        Value = now,
                        Type  = "DateTime"
                    }
                }
            };

            var request = new AddRequest(options);

            var result = MetadataApi.Add(request);

            Assert.IsNotNull(result);
            Assert.Greater(result.AddedCount, 0);
        }
        public static void Run()
        {
            var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
            var apiInstance   = new MetadataApi(configuration);

            try
            {
                var fileInfo = new FileInfo
                {
                    FilePath    = "documents/input.docx",
                    StorageName = Common.MyStorage
                };

                var now     = DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss");
                var options = new AddOptions
                {
                    FileInfo   = fileInfo,
                    Properties = new List <AddProperty>
                    {
                        new AddProperty
                        {
                            Value          = now,
                            Type           = "DateTime",
                            SearchCriteria = new SearchCriteria
                            {
                                NameOptions = new NameOptions
                                {
                                    Value        = "^.*print.*",
                                    MatchOptions = new MatchOptions
                                    {
                                        IsRegex = true
                                    }
                                }
                            },
                        }
                    }
                };

                var request = new AddRequest(options);

                var response = apiInstance.Add(request);
                Console.WriteLine($"Count of changes: {response.AddedCount}");
                Console.WriteLine("Resultant file path: " + response.Path);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while calling MetadataApi: " + e.Message);
            }
        }