public void UploadFiles_CorrectResource()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create a temporary file.
            var tempFile = new FileInfo(@"test.txt");

            if (false == tempFile.Exists)
            {
                tempFile.Create();
            }

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <List <UploadInfo> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <List <UploadInfo> > >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new[]
                {
                    new UploadInfo()
                    {
                        UploadID = 1
                    }
                }.ToList());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ObjectFileOperations.UploadFiles(tempFile);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <List <UploadInfo> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/files", resourceAddress);
        }
Пример #2
0
        public void SetProperty_CorrectBody()
        {
            /* Arrange */

            // The method.
            PropertyValue body = null;

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                body = r.DeserializeBody <PropertyValue>();
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <ExtendedObjectVersion> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new ExtendedObjectVersion());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ObjectPropertyOperations.SetProperty(1, 2, new PropertyValue()
            {
                PropertyDef = 0,
                TypedValue  = new TypedValue()
                {
                    DataType = MFDataType.Text,
                    Value    = "hello world"
                }
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Body must be correct.
            Assert.IsNotNull(body);
            Assert.AreEqual(0, body.PropertyDef);
            Assert.IsNotNull(body.TypedValue);
            Assert.AreEqual(MFDataType.Text, body.TypedValue.DataType);
            Assert.AreEqual("hello world", body.TypedValue.Value);
        }
Пример #3
0
        public void SetProperty_CorrectMethod()
        {
            /* Arrange */

            // The method.
            Method?methodUsed      = null;
            string methodParameter = null;

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                methodUsed      = r.Method;
                methodParameter = r.Parameters.GetMethodQuerystringParameter();
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <ExtendedObjectVersion> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new ExtendedObjectVersion());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ObjectPropertyOperations.SetProperty(1, 2, new PropertyValue()
            {
                PropertyDef = 0,
                TypedValue  = new TypedValue()
                {
                    DataType = MFDataType.Text,
                    Value    = "hello world"
                }
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Method must be correct.
            Assert.AreEqual(Method.POST, methodUsed);
            Assert.AreEqual(Method.PUT.ToString(), methodParameter);
        }
Пример #4
0
        public void GetObjectPropertyValues_CorrectResource()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <List <List <PropertyValue> > >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <List <List <PropertyValue> > > >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new[]
                {
                    new []
                    {
                        new PropertyValue()
                    }.ToList()
                }.ToList());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ObjectPropertyOperations.GetProperties(new ObjVer()
            {
                ID   = 2,
                Type = 1
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <List <List <PropertyValue> > >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/objects/properties;1/2/0", resourceAddress);
        }
Пример #5
0
        public async Task GetObjectPropertyValuesAsync_CorrectMethod()
        {
            /* Arrange */

            // The method.
            Method?methodUsed = null;

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <List <List <PropertyValue> > >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                methodUsed = r.Method;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <List <List <PropertyValue> > > >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new[]
                {
                    new []
                    {
                        new PropertyValue()
                    }.ToList()
                }.ToList());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            await mfwsClient.ObjectPropertyOperations.GetPropertiesAsync(new ObjVer()
            {
                ID   = 2,
                Type = 1
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <List <List <PropertyValue> > >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Method must be correct.
            Assert.AreEqual(Method.GET, methodUsed);
        }
Пример #6
0
        public void SetProperty_CorrectResource()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <ExtendedObjectVersion> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new ExtendedObjectVersion());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ObjectPropertyOperations.SetProperty(1, 2, new PropertyValue()
            {
                PropertyDef = 0,
                TypedValue  = new TypedValue()
                {
                    DataType = MFDataType.Text,
                    Value    = "hello world"
                }
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/objects/1/2/latest/properties/0", resourceAddress);
        }
        public async Task GetViewContentsAsync_CorrectResource_WithView()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <FolderContentItems>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <FolderContentItems> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new FolderContentItems());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            await mfwsClient.ViewOperations.GetFolderContentsAsync(new FolderContentItem()
            {
                FolderContentItemType = MFFolderContentItemType.ViewFolder,
                View = new View()
                {
                    ID   = 15,
                    Name = "Favourites"
                }
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <FolderContentItems>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/views/v15/items", resourceAddress);
        }
        public void GetViewContents_CorrectMethod()
        {
            /* Arrange */

            // The method.
            Method?methodUsed = null;

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <FolderContentItems>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                methodUsed = r.Method;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <FolderContentItems> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new FolderContentItems());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ViewOperations.GetFolderContents(new FolderContentItem()
            {
                FolderContentItemType = MFFolderContentItemType.ViewFolder,
                View = new View()
                {
                    ID   = 15,
                    Name = "Favourites"
                }
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <FolderContentItems>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Method must be correct.
            Assert.AreEqual(Method.GET, methodUsed);
        }
Пример #9
0
        public void AuthenticateUsingCredentials_CorrectBody_WithExpiration()
        {
            /* Arrange */

            // The vault guid.
            var vaultGuid = Guid.NewGuid();

            // The request body.
            var requestBody = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <PrimitiveType <string> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                requestBody = r.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody)?.Value?.ToString();
            })
            // 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));
            });

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.AuthenticateUsingCredentials(vaultGuid, "my username", "my password", new DateTime(2017, 01, 01));

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <PrimitiveType <string> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Body must be correct.
            Assert.AreEqual($"{{\"Username\":\"my username\",\"Password\":\"my password\",\"Domain\":null,\"WindowsUser\":false,\"ComputerName\":null,\"VaultGuid\":\"{vaultGuid.ToString("D")}\",\"Expiration\":\"2017-01-01T00:00:00Z\",\"ReadOnly\":false,\"URL\":null,\"Method\":null}}", requestBody);
        }
        public async Task ExecuteExtensionMethodAsync_CorrectResource_InputSerialisation()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse>();

                // Setup the return data.
                response.SetupGet(r => r.Content)
                .Returns("returnValue");

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            await mfwsClient.ExtensionMethodOperations.ExecuteVaultExtensionMethodAsync("HelloWorld", new
            {
                a = "b",
                x = 7
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/vault/extensionmethod/HelloWorld", resourceAddress);
        }
        public void ExecuteExtensionMethod_CorrectRequestBody_InputSerialisation()
        {
            /* Arrange */

            // The actual request body.
            var requestBody = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                requestBody = r.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody)?.Value?.ToString();
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse>();

                // Setup the return data.
                response.SetupGet(r => r.Content)
                .Returns("returnValue");

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ExtensionMethodOperations.ExecuteVaultExtensionMethod("HelloWorld", new
            {
                a = "b",
                x = 7
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Request body must be correct.
            Assert.AreEqual("{\"a\":\"b\",\"x\":7}", requestBody);
        }
        public async Task RemoveFileAsync_CorrectResource()
        {
            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <Method>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, Method m, CancellationToken t) =>
            {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <ExtendedObjectVersion> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new ExtendedObjectVersion());

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


            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            await mfwsClient.ObjectFileOperations.RemoveFileAsync(new ObjVer()
            {
                ID      = 1,
                Type    = 0,
                Version = 2
            }, new FileVer()
            {
                ID = 3
            });

            // Execute must be called once.
            mock.Verify(c => c.ExecuteAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <Method>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/objects/0/1/2/files/3", resourceAddress);
        }
        public void ExecuteExtensionMethod_CorrectMethod_InputSerialisation()
        {
            /* Arrange */

            // The method.
            Method?methodUsed = null;

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                methodUsed = r.Method;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse>();

                // Setup the return data.
                response.SetupGet(r => r.Content)
                .Returns("returnValue");

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ExtensionMethodOperations.ExecuteVaultExtensionMethod("HelloWorld", new
            {
                a = "b",
                x = 7
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Method must be correct.
            Assert.AreEqual(Method.POST, methodUsed);
        }
        public void DownloadFile_CorrectMethod()
        {
            /* Arrange */

            // The method.
            Method?methodUsed = null;

            // The return value.
            byte[] content = new byte[0];

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                methodUsed = r.Method;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse>();

                // Setup the return data.
                response.SetupGet(r => r.RawBytes)
                .Returns(content);

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ObjectFileOperations.DownloadFile(1, 2, 3, 4);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Method must be correct.
            Assert.AreEqual(Method.GET, methodUsed);
        }
Пример #15
0
        public void AuthenticateUsingCredentials_CorrectMethod()
        {
            /* Arrange */

            // The method.
            Method?methodUsed = null;

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <PrimitiveType <string> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                methodUsed = r.Method;
            })
            // 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));
            });

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.AuthenticateUsingCredentials(Guid.NewGuid(), "my username", "my password");

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <PrimitiveType <string> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Method must be correct.
            Assert.AreEqual(Method.POST, methodUsed);
        }
        public async Task DownloadFileAsync_CorrectResource()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // The return value.
            byte[] content = new byte[0];

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse>();

                // Setup the return data.
                response.SetupGet(r => r.RawBytes)
                .Returns(content);

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            await mfwsClient.ObjectFileOperations.DownloadFileAsync(1, 2, 3, 4);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/objects/1/2/4/files/3/content", resourceAddress);
        }
Пример #17
0
        public async Task AuthenticateUsingCredentialsAsync_CorrectResource()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <PrimitiveType <string> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // 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));
            });

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            await mfwsClient.AuthenticateUsingCredentialsAsync(Guid.NewGuid(), "my username", "my password");

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <PrimitiveType <string> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/server/authenticationtokens", resourceAddress);
        }
Пример #18
0
        public void AuthenticateUsingCredentials_AuthenticationHeaderSet()
        {
            /* Arrange */

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .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));
            });

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.AuthenticateUsingCredentials(Guid.NewGuid(), "my username", "my password");

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <PrimitiveType <string> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

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

            Assert.IsNotNull(authenticationHeader);
            Assert.AreEqual("hello world", authenticationHeader.Value);
        }
        public async Task ExecuteExtensionMethodAsync_CorrectOutput_InputSerialisation()
        {
            /* Arrange */

            // The input value.
            var outputValue = "Return value";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse>();

                // Setup the return data.
                response.SetupGet(r => r.Content)
                .Returns(outputValue);

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            var output = await mfwsClient.ExtensionMethodOperations.ExecuteVaultExtensionMethodAsync("HelloWorld", new
            {
                a = "b",
                x = 7
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Request body must be correct.
            Assert.AreEqual(outputValue, output);
        }
Пример #20
0
        public void GetOnlineVaults_CorrectResource()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <List <Vault> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <List <Vault> > >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new List <Vault>());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.GetOnlineVaults();

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <List <Vault> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/server/vaults?online=true", resourceAddress);
        }
Пример #21
0
        public async Task GetPropertyDefAsync_CorrectResource()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <PropertyDef>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <PropertyDef> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new PropertyDef());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            await mfwsClient.PropertyDefOperations.GetPropertyDefAsync(123);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <PropertyDef>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/structure/properties/123", resourceAddress);
        }
Пример #22
0
        public void RemoveProperty_CorrectMethod()
        {
            /* Arrange */

            // The method.
            Method?methodUsed = null;

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                methodUsed = r.Method;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <ExtendedObjectVersion> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new ExtendedObjectVersion());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ObjectPropertyOperations.RemoveProperty(1, 2, 0);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Method must be correct.
            Assert.AreEqual(Method.DELETE, methodUsed);
        }
        public void GetValueListItems_CorrectResource_WithNameFilter()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <Results <ValueListItem> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <Results <ValueListItem> > >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new Results <ValueListItem>());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ValueListItemOperations.GetValueListItems(1, "hello");

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <Results <ValueListItem> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/valuelists/1/items?filter=hello", resourceAddress);
        }
        public async Task GetObjectClassAsync_CorrectMethod_WithTemplates()
        {
            /* Arrange */

            // The method.
            Method?methodUsed = null;

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <ExtendedObjectClass>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                methodUsed = r.Method;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <ExtendedObjectClass> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new ExtendedObjectClass());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            await mfwsClient.ClassOperations.GetObjectClassAsync(classId : 0, includeTemplates : true);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <ExtendedObjectClass>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Method must be correct.
            Assert.AreEqual(Method.GET, methodUsed);
        }
        public void GetObjectClass_CorrectResource_WithTemplates()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <ExtendedObjectClass>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <ExtendedObjectClass> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new ExtendedObjectClass());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ClassOperations.GetObjectClass(classId: 0, includeTemplates: true);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <ExtendedObjectClass>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/structure/classes/0?include=templates", resourceAddress);
        }
Пример #26
0
        public void AuthenticateUsingSingleSignOn_CorrectResource()
        {
            /* Arrange */

            // The vault Guid to request.
            var guid = Guid.NewGuid();

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(Task.FromResult(new Mock <IRestResponse>().Object));

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.AuthenticateUsingSingleSignOn(guid);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual($"/WebServiceSSO.aspx?popup=1&vault={guid:D}", resourceAddress);
        }
Пример #27
0
        public void AuthenticateUsingSingleSignOn_CorrectMethod()
        {
            /* Arrange */

            // The vault Guid to request.
            var guid = Guid.NewGuid();

            // The method.
            Method?methodUsed = null;

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                methodUsed = r.Method;
            })
            // Return a mock response.
            .Returns(Task.FromResult(new Mock <IRestResponse>().Object));

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.AuthenticateUsingSingleSignOn(guid);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Method must be correct.
            Assert.AreEqual(Method.GET, methodUsed);
        }
Пример #28
0
        public void AuthenticateUsingSingleSignOn_SessionIdSet()
        {
            /* Arrange */

            // The vault Guid to request.
            var guid = Guid.NewGuid();

            // The ASP.NET session Id (dummy value).
            var sessionId = Guid.NewGuid().ToString();

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            mock.SetupAllProperties();
            mock.SetupGet(c => c.BaseUrl)
            .Returns(new Uri("http://example.org/"));

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            // Return a mock response.
            .Returns(() =>
            {
                var response = new Mock <IRestResponse>();
                response.SetupGet(r => r.Cookies)
                .Returns(new List <RestResponseCookie>()
                {
                    new RestResponseCookie()
                    {
                        Name   = "ASP.NET_SessionId",
                        Value  = sessionId,
                        Path   = "/",
                        Domain = "example.org"
                    }
                });
                return(Task.FromResult(response.Object));
            });

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.AuthenticateUsingSingleSignOn(guid);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Ensure cookie is in default cookie container.
            var requestSessionCookie = mfwsClient
                                       .CookieContainer
                                       .GetCookies(new Uri("http://example.org"))
                                       .Cast <Cookie>()
                                       .FirstOrDefault(c => c.Name == "ASP.NET_SessionId");

            Assert.IsNotNull(requestSessionCookie);
            Assert.AreEqual(requestSessionCookie.Value, sessionId);
        }
        public void GetViewContents_CorrectResource_WithView_TwoGroupings()
        {
            /* Arrange */

            // The actual requested address.
            var resourceAddress = "";

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <FolderContentItems>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                resourceAddress = r.Resource;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <FolderContentItems> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new FolderContentItems());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ViewOperations.GetFolderContents(new FolderContentItem()
            {
                FolderContentItemType = MFFolderContentItemType.ViewFolder,
                View = new View()
                {
                    ID   = 216,
                    Name = "By Technology"
                }
            }, new FolderContentItem()
            {
                FolderContentItemType = MFFolderContentItemType.PropertyFolder,
                PropertyFolder        = new TypedValue()
                {
                    DataType = MFDataType.Lookup,
                    Lookup   = new Lookup()
                    {
                        Item = 4
                    }
                }
            }, new FolderContentItem()
            {
                FolderContentItemType = MFFolderContentItemType.PropertyFolder,
                PropertyFolder        = new TypedValue()
                {
                    DataType = MFDataType.Lookup,
                    Lookup   = new Lookup()
                    {
                        Item = 19
                    }
                }
            });

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <FolderContentItems>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Resource must be correct.
            Assert.AreEqual("/REST/views/v216/L4/L19/items", resourceAddress);
        }
        public void AddFiles_CorrectMethod()
        {
            /* Arrange */

            // The method.
            Method?methodUsed = null;

            // Create a temporary file.
            var tempFile = new FileInfo(@"test.txt");

            if (false == tempFile.Exists)
            {
                tempFile.Create();
            }

            // Create our restsharp mock.
            var mock = new Mock <IRestClient>();

            // When the execute method is called, log the resource requested.
            mock
            .Setup(c => c.ExecuteTaskAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            .Callback((IRestRequest r, CancellationToken t) => {
                methodUsed = r.Method;
            })
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <ExtendedObjectVersion> >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new ExtendedObjectVersion());

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

            // We also need to handle the upload file call or our tests will except.
            mock
            .Setup(c => c.ExecuteTaskAsync <List <UploadInfo> >(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()))
            // Return a mock response.
            .Returns(() =>
            {
                // Create the mock response.
                var response = new Mock <IRestResponse <List <UploadInfo> > >();

                // Setup the return data.
                response.SetupGet(r => r.Data)
                .Returns(new[]
                {
                    new UploadInfo()
                    {
                        UploadID = 1
                    }
                }.ToList());

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

            /* Act */

            // Create our MFWSClient.
            var mfwsClient = MFWSClient.GetMFWSClient(mock);

            // Execute.
            mfwsClient.ObjectFileOperations.AddFiles(0, 1, 2, tempFile);

            /* Assert */

            // Execute must be called once.
            mock.Verify(c => c.ExecuteTaskAsync <ExtendedObjectVersion>(It.IsAny <IRestRequest>(), It.IsAny <CancellationToken>()), Times.Exactly(1));

            // Method must be correct.
            Assert.AreEqual(Method.POST, methodUsed);
        }