Esempio n. 1
0
        public async Task Docs_ContentManagement_ListFields_Add()
        {
            // ALIGN
            await EnsureContentAsync("/Root/Content/IT/Document_Library", "DocumentLibrary");

            try
            {
                // ACTION for doc
                var body   = @"models=[{
                    ""__ContentType"": ""IntegerFieldSetting"",
                    ""Name"": ""MyField1"",
                    ""DisplayName"": ""My Field 1"",
                    ""Compulsory"": true,
                    ""MinValue"": 10}]";
                var result = await RESTCaller.GetResponseStringAsync(
                    "/Root/Content/IT/Document_Library", null, HttpMethod.Post, body);

                Console.WriteLine(result);

                // ASSERT
                Assert.Inconclusive();
            }
            finally
            {
                await Content.DeleteAsync("/Root/Content/IT/Document_Library", true, CancellationToken.None);
            }
        }
        /// <summary>
        /// Checks whether a user has the provided permissions on the provided content.
        /// </summary>
        /// <param name="contentId">Id of a content.</param>
        /// <param name="permissions">Permission names to check.</param>
        /// <param name="user">The user who's permissions need to be checked. If it is not provided, the server checks the current user.</param>
        /// <param name="server">Target server.</param>
        public static async Task <bool> HasPermissionAsync(int contentId, string[] permissions, string user = null, ServerContext server = null)
        {
            if (permissions == null || permissions.Length == 0)
            {
                throw new InvalidOperationException("Please provide at least one permission entry.");
            }

            var requestData = new ODataRequest(server)
            {
                ContentId   = contentId,
                ActionName  = "HasPermission",
                Permissions = permissions,
                User        = user
            };

            var result = await RESTCaller.GetResponseStringAsync(requestData.GetUri(), server).ConfigureAwait(false);

            bool hasPermission;

            if (bool.TryParse(result, out hasPermission))
            {
                return(hasPermission);
            }

            return(false);
        }
Esempio n. 3
0
        public async Task Docs_Collaboration_Versioning_TakeLockOver()
        {
            Assert.Inconclusive();
            //UNDONE:---- ERROR: The server returned an error (HttpStatus: InternalServerError): User not found by the parameter: 12345
            // ALIGN
            // ReSharper disable once InconsistentNaming
            await using var Console = new StringWriter();
            await EnsureContentAsync("/Root/Content/IT/Document_Library", "DocumentLibrary");
            await EnsureContentAsync("/Root/Content/IT/Document_Library/Calgary", "Folder");
            await EnsureContentAsync("/Root/Content/IT/Document_Library/Calgary/BusinessPlan.docx", "File");

            try
            {
                // ACTION for doc
                var body   = @"models=[{""user"": ""12345""}]";
                var result = await RESTCaller.GetResponseStringAsync(
                    "/Root/Content/IT/Document_Library/Calgary/BusinessPlan.docx", "TakeLockOver", HttpMethod.Post, body);

                Console.WriteLine(result);

                // ASSERT
                var message = Console.GetStringBuilder().ToString();
                Assert.Inconclusive();
            }
            finally
            {
                var c = await Content.LoadAsync("/Root/Content/IT/Document_Library/Calgary/BusinessPlan.docx");

                if (c != null)
                {
                    await c.DeleteAsync(true);
                }
            }
        }
Esempio n. 4
0
        // GetContentAsync GetResponseStringAsync GetResponseJsonAsync
        public async Task Docs_BasicConcepts_Select()
        {
            // ACTION for doc
            dynamic content = await RESTCaller.GetContentAsync(new ODataRequest
            {
                Path   = "/Root/Content/IT",
                Select = new[] { "DisplayName", "Description" }
            });

            // ASSERT-1
            var responseString = await RESTCaller.GetResponseStringAsync(new ODataRequest
            {
                Path   = "/Root/Content/IT",
                Select = new[] { "DisplayName", "Description" }
            });

            Assert.AreEqual("{\"d\":{\"DisplayName\":\"IT\",\"Description\":null}}", responseString.RemoveWhitespaces());

            // ASSERT-2
            var responseJson = await RESTCaller.GetResponseJsonAsync(new ODataRequest
            {
                Path   = "/Root/Content/IT",
                Select = new[] { "DisplayName", "Description" }
            });

            var displayName = responseJson.d.DisplayName.ToString();
            var description = responseJson.d.Description.ToString();

            Assert.AreEqual(displayName, content.DisplayName.ToString());
            Assert.AreEqual(description, content.Description.ToString());
        }
Esempio n. 5
0
        public async Task Docs_ContentManagement_Move_Single()
        {
            // ALIGN
            await EnsureContentAsync("/Root/Content/IT/Document_Library", "DocumentLibrary");
            await EnsureContentAsync("/Root/Content/IT/Document_Library/Munich", "Folder");
            await EnsureContentAsync("/Root/Content/IT/Document_Library/Chicago", "Folder");
            await EnsureContentAsync("/Root/Content/IT/Document_Library/Chicago/100Pages.pdf", "File");

            try
            {
                // ACTION for doc
                var body   = @"models=[{""targetPath"": ""/Root/Content/IT/Document_Library/Munich"",
                ""paths"": [""/Root/Content/IT/Document_Library/Chicago/100Pages.pdf""]}]";
                var result = await RESTCaller.GetResponseStringAsync(
                    "/Root", "MoveBatch", HttpMethod.Post, body);

                Console.WriteLine(result);

                // ASSERT
                Assert.Inconclusive();
            }
            finally
            {
                var c = await Content.LoadAsync("/Root/Content/IT/Document_Library/Munich");

                if (c != null)
                {
                    await c.DeleteAsync(true);
                }
            }
        }
Esempio n. 6
0
        public async Task Docs_Collaboration_Versioning_RestoreOldVersion()
        {
            // ALIGN
            // ReSharper disable once InconsistentNaming
            await using var Console = new StringWriter();
            await EnsureContentAsync("/Root/Content/IT/Document_Library", "DocumentLibrary");
            await EnsureContentAsync("/Root/Content/IT/Document_Library/Calgary", "Folder");
            await EnsureContentAsync("/Root/Content/IT/Document_Library/Calgary/BusinessPlan.docx", "File");

            try
            {
                // ACTION for doc
                var body   = @"models=[{""version"": ""V1.0.A""}]";
                var result = await RESTCaller.GetResponseStringAsync(
                    "/Root/Content/IT/Document_Library/Calgary/BusinessPlan.docx", "RestoreVersion", HttpMethod.Post, body);

                Console.WriteLine(result);

                // ASSERT
                var message = Console.GetStringBuilder().ToString();
                Assert.Inconclusive();
            }
            finally
            {
                var c = await Content.LoadAsync("/Root/Content/IT/Document_Library/Calgary/BusinessPlan.docx");

                if (c != null)
                {
                    await c.DeleteAsync(true);
                }
            }
        }
Esempio n. 7
0
        public async Task Docs_BasicConcepts_GetSchema()
        {
            // ACTION for doc
            string schema = await RESTCaller.GetResponseStringAsync("/Root", "GetSchema");

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 8
0
 /// <summary>
 /// Removes permission break on the provided content.
 /// </summary>
 /// <param name="contentId">Id of a content.</param>
 /// <param name="server">Target server.</param>
 public static async Task UnbreakInheritanceAsync(int contentId, ServerContext server = null)
 {
     await RESTCaller.GetResponseStringAsync(contentId, SETPERMISSIONS, HttpMethod.Post, JsonHelper.Serialize(new
     {
         inheritance = "unbreak"
     }),
                                             server);
 }
Esempio n. 9
0
        // ============================================================================== Static methods

        private static async Task <SyncConfiguration> LoadConfiguration()
        {
            try
            {
                dynamic settingsContent = Content.LoadAsync(SettingsPath).Result;
                if (settingsContent == null)
                {
                    return(null);
                }

                string binaryUrl = _siteUrl.TrimEnd('/') + settingsContent.Binary.__mediaresource.media_src +
                                   "&includepasswords=true";

                var settingsText = await RESTCaller.GetResponseStringAsync(new Uri(binaryUrl));

                var config = JsonHelper.Deserialize <SyncConfiguration>(settingsText);

                // decrypt passwords and inject them back to the configuration
                foreach (var server in config.Servers.Where(server => server.LogonCredentials != null && !string.IsNullOrEmpty(server.LogonCredentials.Password)))
                {
                    var request = new ODataRequest
                    {
                        ActionName          = "Decrypt",
                        Path                = "Root",
                        IsCollectionRequest = false,
                        SiteUrl             = _siteUrl
                    };

                    try
                    {
                        server.LogonCredentials.Password = await RESTCaller.GetResponseStringAsync(
                            request.GetUri(),
                            ClientContext.Current.Servers[0],
                            HttpMethod.Post,
                            JsonHelper.Serialize(new { text = server.LogonCredentials.Password }));
                    }
                    catch (ClientException cex)
                    {
                        AdLog.LogError("Error during password decryption. " + Common.FormatClientException(cex));
                    }
                    catch (Exception ex)
                    {
                        AdLog.LogException(ex);
                    }
                }

                // preload all AD-related content types from the server
                ADRelatedContentTypes = await LoadADRelatedContentTypes();

                return(config);
            }
            catch (Exception ex)
            {
                AdLog.LogException(ex);
            }

            return(null);
        }
Esempio n. 10
0
        public async Task Docs_Permissions_Main_GetPermissions_CurrentUser()
        {
            //UNDONE:- Feature request: Content.GetPermissionAsync
            // ACTION for doc
            var result = await RESTCaller.GetResponseStringAsync("/Root/Content/IT", "GetPermissions");

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 11
0
        public async Task Docs_BasicConcepts_GetSingleProperty()
        {
            var response =
                // ACTION for doc
                //UNDONE:- Feature request: Content.GetPropertyAsync: await Content.GetPropertyAsync("/Root/IMS", "DisplayName");
                await RESTCaller.GetResponseStringAsync("/Root/Content/IT", "DisplayName");

            // ASSERT
            Assert.AreEqual("{\"d\":{\"DisplayName\":\"IT\"}}", response.RemoveWhitespaces());
        }
Esempio n. 12
0
        public async Task Docs_BasicConcepts_GetSinglePropertyValue()
        {
            var url = ClientContext.Current.Server.Url;

            var response =
                // ACTION for doc
                //UNDONE:- Feature request: Content.GetPropertyValueAsync: await Content.GetPropertyValueAsync("/Root/IMS", "DisplayName");
                await RESTCaller.GetResponseStringAsync(new Uri(url + "/OData.svc/Root/Content/('IT')/DisplayName/$value"));

            // ASSERT
            Assert.AreEqual("IT", response.RemoveWhitespaces());
        }
Esempio n. 13
0
        public async Task Docs_BasicConcepts_GlobalMetadata()
        {
            var url = ClientContext.Current.Server.Url;

            var response =
                // ACTION for doc
                await RESTCaller.GetResponseStringAsync(
                    new Uri(url + "/OData.svc/$metadata"));

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 14
0
        public async Task Docs_Preview_Main_RegeneratePreviews()
        {
            Assert.Inconclusive();
            //UNDONE: this test has not run yet
            // ACTION for doc
            await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT/Document_Library/Calgary/BusinessPlan.docx", "RegeneratePreviews",
                HttpMethod.Post);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 15
0
        /// <summary>
        /// Sets the provided permissions on the provided content.
        /// </summary>
        /// <param name="contentId">Id of a content.</param>
        /// <param name="permissions">Permission settings to be sent to the server.</param>
        /// <param name="server">Target server.</param>
        public static async Task SetPermissionsAsync(int contentId, SetPermissionRequest[] permissions, ServerContext server = null)
        {
            if (permissions == null || permissions.Length == 0)
            {
                throw new InvalidOperationException("Please provide at least one permission entry.");
            }

            await RESTCaller.GetResponseStringAsync(contentId, SETPERMISSIONS, HttpMethod.Post, JsonHelper.Serialize(new
            {
                r = permissions
            }),
                                                    server);
        }
Esempio n. 16
0
        public async Task Docs_Sharing_Main_GetSharing()
        {
            Assert.Inconclusive();
            //UNDONE: this test has not run yet
            // ACTION for doc
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT", "GetSharing");

            //Console.WriteLine(result);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 17
0
        public async Task Docs_Preview_Main_GetPageCount()
        {
            Assert.Inconclusive();
            //UNDONE: this test has not run yet
            // ACTION for doc
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT/Document_Library/Calgary/BusinessPlan.docx", "GetPageCount", HttpMethod.Post);

            //Console.WriteLine(result);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 18
0
        public async Task Docs_UsersAndGroups_GroupMembership_Remove()
        {
            Assert.Inconclusive();
            //UNDONE:---- ERROR: Content not found
            // ACTION for doc
            var body   = @"models=[{""contentIds"": [ 1157 ]}]";
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/IMS/Public/developers", "RemoveMembers", HttpMethod.Post, body);

            Console.WriteLine(result);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 19
0
        public async Task Docs_Sharing_Main_Remove()
        {
            Assert.Inconclusive();
            //UNDONE: this test has not run yet
            // ACTION for doc
            var body   = @"models=[{""id"": ""1b9abb5f-ed49-48c8-8edd-2c7e634bd77b""}]";
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT", "RemoveSharing", HttpMethod.Post, body);

            //Console.WriteLine(result);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 20
0
        public async Task Docs_Permissions_Main_GetPermissions_Specific()
        {
            //UNDONE:- Feature request: Content.GetPermissionAsync(identity)
            // ACTION for doc
            var req = new ODataRequest
            {
                Path       = "/Root/Content/IT",
                ActionName = "GetPermissions",
                Parameters = { { "identity", "/Root/IMS/Public/Editors" } }
            };
            var result = await RESTCaller.GetResponseStringAsync(req);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 21
0
        public async Task Docs_BasicConcepts_LocalMetadata()
        {
            // ALIGN
            await EnsureContentAsync("/Root/Content/IT/Document_Library", "DocumentLibrary");

            var url = ClientContext.Current.Server.Url;

            var response =
                // ACTION for doc
                await RESTCaller.GetResponseStringAsync(
                    new Uri(url + "/OData.svc/Root/Content/IT/Document_Library/$metadata"));

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 22
0
        public async Task Docs_Collaboration_SavedQueries_SavePublic()
        {
            // ACTION for doc
            var body   = @"models=[{
                ""query"": ""+TypeIs:File +InTree:/Root/Content/IT"",
                ""displayName"": ""Public query"",
                ""queryType"": ""Public""}]";
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT/Document_Library", "SaveQuery", HttpMethod.Post, body);

            Console.WriteLine(result);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 23
0
        public async Task Docs_ContentManagement_AllowedChildTypes_Check()
        {
            // ReSharper disable once InconsistentNaming
            await using var Console = new StringWriter();

            // ACTION for doc
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT", "CheckAllowedChildTypesOfFolders");

            Console.WriteLine(result);

            // ASSERT
            var message = Console.GetStringBuilder().ToString();

            Assert.Inconclusive();
        }
Esempio n. 24
0
        public async Task Docs_ContentManagement_Copy_Single()
        {
            // ALIGN
            await EnsureContentAsync("/Root/Content/IT/Document_Library", "DocumentLibrary");

            // ACTION for doc
            var body   = @"models=[{""targetPath"": ""/Root/Content/IT/Document_Library/Munich"",
            ""paths"": [""/Root/Content/IT/Document_Library/Chicago/100Pages.pdf""]}]";
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root", "CopyBatch", HttpMethod.Post, body);

            Console.WriteLine(result);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 25
0
        public async Task Docs_Preview_Main_CheckPreviews()
        {
            Assert.Inconclusive();
            //UNDONE: this test has not run yet
            // ACTION for doc
            var body   = @"models=[{
                ""generateMissing"": false}]";
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT/Document_Library/Calgary/BusinessPlan.docx", "CheckPreviews",
                HttpMethod.Post, body);

            //Console.WriteLine(result);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 26
0
        public async Task Docs_Preview_Main_RemoveComment()
        {
            Assert.Inconclusive();
            //UNDONE: this test has not run yet
            // ACTION for doc
            var body   = @"models=[{
                ""id"": ""839ba802-d587-4153-b4e8-ccd4c593e1f4""}]";
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT/Document_Library/Calgary/BusinessPlan.docx", "DeletePreviewComment",
                HttpMethod.Post, body);

            //Console.WriteLine(result);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 27
0
        public async Task Docs_ContentManagement_Trash_Options()
        {
            // ReSharper disable once InconsistentNaming
            await using var Console = new StringWriter();

            // ACTION for doc
            var body   = @"models=[{""SizeQuota"": 20, ""BagCapacity"": 100, ""MinRetentionTime"": 14}]";
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Trash", null, HttpMethod.Patch, body);

            Console.WriteLine(result);

            // ASSERT
            var message = Console.GetStringBuilder().ToString();

            Assert.Inconclusive();
        }
Esempio n. 28
0
        public async Task Docs_Collaboration_SavedQueries_SavePrivate()
        {
            Assert.Inconclusive();
            //UNDONE:---- ERROR: The server returned an error (HttpStatus: InternalServerError): User profile could not be created.
            // ACTION for doc
            var body   = @"models=[{
                ""query"": ""+TypeIs:File +InTree:/Root/Content/IT"",
                ""displayName"": ""My query"",
                ""queryType"": ""Private""}]";
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT/Document_Library", "SaveQuery", HttpMethod.Post, body);

            Console.WriteLine(result);

            // ASSERT
            Assert.Inconclusive();
        }
Esempio n. 29
0
        public async Task Docs_ContentManagement_Trash_Disable()
        {
            // ReSharper disable once InconsistentNaming
            await using var Console = new StringWriter();

            // ACTION for doc
            var body   = @"models=[{""TrashDisabled"": true}]";
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT", null, HttpMethod.Patch, body);

            Console.WriteLine(result);

            // ASSERT
            var message = Console.GetStringBuilder().ToString();

            Assert.Inconclusive();
        }
Esempio n. 30
0
        public async Task Docs_Sharing_Main_Levels()
        {
            Assert.Inconclusive();
            //UNDONE: this test has not run yet
            // ACTION for doc
            var body   = @"models=[{
                ""token"": ""*****@*****.**"",
                ""level"": ""Edit"",
                ""mode"": ""Private"",
                ""sendNotification"": true}]";
            var result = await RESTCaller.GetResponseStringAsync(
                "/Root/Content/IT", "Share", HttpMethod.Post, body);

            //Console.WriteLine(result);

            // ASSERT
            Assert.Inconclusive();
        }