public async void EnviarNextCloud(List <IFormFile> files, string Url, string Path, string Folder) { foreach (var formFile in files) { if (formFile.Length > 0) { using var ms = new MemoryStream(); await formFile.CopyToAsync(ms); ms.Seek(0, SeekOrigin.Begin); var clientParams = new WebDavClientParams { BaseAddress = new Uri(Url), Credentials = new NetworkCredential(ConfigurationManager.AppSetting["NextCloud:User"], ConfigurationManager.AppSetting["NextCloud:Password"]) }; var client = new WebDavClient(clientParams); await client.Mkcol(Folder + "/"); await client.Mkcol(Folder + "/" + Path + "/"); clientParams.BaseAddress = new Uri(clientParams.BaseAddress + Folder + "/" + Path + "/"); client = new WebDavClient(clientParams); await client.PutFile(formFile.FileName, ms); // upload a resource } } }
public bool GenerateClient(UpdateServerConfig config) { bool success; try { // Create client params var clientparams = new WebDavClientParams() { BaseAddress = new Uri(config.ServerAdress), Credentials = new NetworkCredential(config.Username, config.Password), UseProxy = false }; // Create client client = new WebDavClient(clientparams); // Remember config Config = config; success = true; } catch (Exception) { success = false; Config = null; client = null; } return(success); }
public override SyncInfo Initialize(DatabaseInfo info) { if (info == null) { throw new ArgumentNullException("info"); } var details = info.Details; var parts = details.Url.Split('\n'); _client = new WebDavClient( parts[1], parts[2]); _info = new SyncInfo { Path = parts[0], Modified = details.Modified, HasLocalChanges = details.HasLocalChanges, }; info.OpenDatabaseFile(x => { using (var buffer = new MemoryStream()) { BufferEx.CopyStream(x, buffer); _info.Database = buffer.ToArray(); } }); return(_info); }
public async void When_RequestIsSuccessfull_Should_ReturnStatusCode200() { var stream = new MemoryStream(Encoding.UTF8.GetBytes("<content/>")); var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.Mock()); var response1 = await client.PutFile("http://example.com/file", stream); var response2 = await client.PutFile(new Uri("http://example.com/file"), stream); var response3 = await client.PutFile("http://example.com/file", stream, "text/xml"); var response4 = await client.PutFile(new Uri("http://example.com/file"), stream, "text/xml"); var response5 = await client.PutFile("http://example.com/file", stream, new PutFileParameters()); var response6 = await client.PutFile(new Uri("http://example.com/file"), stream, new PutFileParameters()); var response7 = await client.PutFile("http://example.com/file", new StreamContent(stream), new PutFileParameters()); var response8 = await client.PutFile(new Uri("http://example.com/file"), new StreamContent(stream), new PutFileParameters()); Assert.Equal(200, response1.StatusCode); Assert.Equal(200, response2.StatusCode); Assert.Equal(200, response3.StatusCode); Assert.Equal(200, response4.StatusCode); Assert.Equal(200, response5.StatusCode); Assert.Equal(200, response6.StatusCode); Assert.Equal(200, response7.StatusCode); Assert.Equal(200, response8.StatusCode); }
public PhotoPageViewModel() { EnterFullScreenCommand = new DelegateCommand(EnterFullScreen); LeaveFullScreenCommand = new DelegateCommand(LeaveFullscreen); ShowControls = true; _client = new WebDavClient(new Uri(Configuration.ServerUrl), Configuration.Credential); }
public async Task <ActionResult> ObterFicheiroNextCloud(string Url) { var clientParams = new WebDavClientParams { BaseAddress = new Uri(Url), Credentials = new NetworkCredential(ConfigurationManager.AppSetting["NextCloud:User"], ConfigurationManager.AppSetting["NextCloud:Password"]) }; var client = new WebDavClient(clientParams); using (var response = await client.GetRawFile(Url)) using (var reader = new StreamReader(response.Stream)) { var bytes = default(byte[]); using (var memstream = new MemoryStream()) { reader.BaseStream.CopyTo(memstream); bytes = memstream.ToArray(); } new FileExtensionContentTypeProvider().TryGetContentType(Url.Split('/').Last(), out string contentType); var cd = new System.Net.Mime.ContentDisposition { FileName = Url.Split('/').Last(), Inline = false, CreationDate = DateTime.Now, }; Response.Headers.Add("Content-Disposition", cd.ToString()); return(File(bytes, contentType)); } }
public async void When_RequestIsFailed_Should_ReturnStatusCode500() { var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.MockFaulted()); var response = await client.Proppatch("http://example", new ProppatchParameters()); Assert.Equal(500, response.StatusCode); }
public async void When_RequestIsFailed_Should_ReturnStatusCode500() { var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.MockFaulted()); var response = await client.Unlock("http://example.com/file", "lock-token"); Assert.Equal(500, response.StatusCode); }
public async void When_SetProperties_Should_IncludeThemInSetTag() { const string expectedContent = @"<?xml version=""1.0"" encoding=""utf-8""?> <D:propertyupdate xmlns:D=""DAV:""> <D:set> <D:prop> <prop1>value1</prop1> </D:prop> <D:prop> <prop2>value2</prop2> </D:prop> </D:set> </D:propertyupdate>"; var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); var propertiesToSet = new Dictionary <XName, string> { { "prop1", "value1" }, { "prop2", "value2" } }; await client.Proppatch("http://example.com", new ProppatchParameters { PropertiesToSet = propertiesToSet }); await dispatcher.Received(1) .Send(Arg.Any <Uri>(), WebDavMethod.Proppatch, Arg.Is(Predicates.CompareRequestContent(expectedContent)), CancellationToken.None); }
public async void When_RequestIsFailed_Should_ReturnStatusCode500() { var stream = new MemoryStream(Encoding.UTF8.GetBytes("<content/>")); var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.MockFaulted()); var response = await client.PutFile("http://example.com/file", stream); Assert.Equal(500, response.StatusCode); }
public async void When_RemovePropertiesWithNamespaces_Should_IncludeXmlnsTagAndUsePrefixes() { const string expectedContent = @"<?xml version=""1.0"" encoding=""utf-8""?> <D:propertyupdate xmlns:D=""DAV:"" xmlns:X=""http://x.example.com/"" xmlns=""http://y.example.com/""> <D:remove> <D:prop> <X:prop1 /> </D:prop> <D:prop> <prop2 /> </D:prop> </D:remove> </D:propertyupdate>"; var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); var propertiesToRemove = new XName[] { "{http://x.example.com/}prop1", "{http://y.example.com/}prop2" }; var ns = new[] { new NamespaceAttr("X", "http://x.example.com/"), new NamespaceAttr("http://y.example.com/") }; await client.Proppatch("http://example.com", new ProppatchParameters { PropertiesToRemove = propertiesToRemove, Namespaces = ns }); await dispatcher.Received(1) .Send(Arg.Any <Uri>(), WebDavMethod.Proppatch, Arg.Is(Predicates.CompareRequestContent(expectedContent)), CancellationToken.None); }
private async Task <bool> UploadFile(WebDavClient client, string filePath, string uploadName) { var sFile = new FileStream(filePath, FileMode.Open, FileAccess.Read); var result = await client.PutFile(uploadName, sFile); sFile.Close(); return(result.IsSuccessful); }
public async void When_IsAppliedToResourceAndAncestors_Should_SendDepthHeaderEqualsInfinity() { var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Lock("http://example.com", new LockParameters { ApplyTo = ApplyTo.Lock.ResourceAndAncestors }); await dispatcher.Received(1) .Send(Arg.Any<Uri>(), WebDavMethod.Lock, Arg.Is(Predicates.CompareHeader("Depth", "infinity")), CancellationToken.None); }
public async void When_IsAppliedToResourceAndChildren_Should_SendDepthHeaderEqualsOne() { var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Propfind("http://example.com", new PropfindParameters { ApplyTo = ApplyTo.Propfind.ResourceAndChildren }); await dispatcher.Received(1) .Send(Arg.Any<Uri>(), WebDavMethod.Propfind, Arg.Is(Predicates.CompareHeader("Depth", "1")), CancellationToken.None); }
public async Task DeleteItemAsync(List <DavItem> items) { var client = new WebDavClient(new Uri(Configuration.ServerUrl, UriKind.RelativeOrAbsolute), Configuration.Credential); foreach (var item in items) { await client.Delete(new Uri(item.EntityId, UriKind.RelativeOrAbsolute)); } }
public YandexDiscFile(string filename, string location, WebDavClient webDav) { filename = filename.Replace("\\", "/").Trim('/') + ".db3"; Location = Path.Combine(location, filename) .Replace("\\", "/") .Trim('/'); Uri = new Uri($"{webDav.BaseAddress}{Location}"); }
public async void When_RequestIsFailed_Should_ReturnStatusCode500() { var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.MockFaulted()); var response1 = await client.GetFile(new Uri("http://example.com/file"), false, CancellationToken.None); var response2 = await client.GetFile(new Uri("http://example.com/file"), true, CancellationToken.None); Assert.Equal(500, response1.StatusCode); Assert.Equal(500, response2.StatusCode); }
public async void When_RequestIsSuccessfull_Should_ReturnStatusCode200() { var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.Mock()); var response1 = await client.Proppatch("http://example.com", new ProppatchParameters()); var response2 = await client.Proppatch(new Uri("http://example.com"), new ProppatchParameters()); Assert.Equal(200, response1.StatusCode); Assert.Equal(200, response2.StatusCode); }
public async void When_IsCalledWithCancellationToken_Should_SendRequestWithIt() { var cts = new CancellationTokenSource(); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Unlock("http://example.com/file", new UnlockParameters("lock-token") { CancellationToken = cts.Token }); await dispatcher.Received(1) .Send(Arg.Any<Uri>(), WebDavMethod.Unlock, Arg.Is<RequestParameters>(x => x.Content == null), cts.Token); }
public async void When_IsAppliedToResourceOnly_Should_SendDepthHeaderEqualsZero() { var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Lock("http://example.com", new LockParameters { ApplyTo = ApplyTo.Lock.ResourceOnly }); await dispatcher.Received(1) .Send(Arg.Any <Uri>(), WebDavMethod.Lock, Arg.Is(Predicates.CompareHeader("Depth", "0")), CancellationToken.None); }
public async Task CreateFolder(DavItem parentFolder, string folderName) { folderName = Uri.EscapeDataString(folderName); folderName = folderName.Replace("%28", "("); folderName = folderName.Replace("%29", ")"); var uri = new Uri(parentFolder.EntityId.TrimEnd('/') + "/" + folderName, UriKind.RelativeOrAbsolute); var client = new WebDavClient(new Uri(Configuration.ServerUrl, UriKind.RelativeOrAbsolute), Configuration.Credential); await client.CreateFolder(uri); }
public JianguoClient(string username, string password) { UserName = username; Password = password; _WebDevClient = new WebDavClient(new WebDavClientParams() { BaseAddress = new Uri(_BaseAddress), Credentials = new System.Net.NetworkCredential(username, password) }); }
public async void When_IsCalledWithCancellationToken_Should_SendRequestWithIt() { var cts = new CancellationTokenSource(); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Proppatch("http://example.com", new ProppatchParameters { CancellationToken = cts.Token }); await dispatcher.Received(1) .Send(Arg.Any<Uri>(), WebDavMethod.Proppatch, Arg.Is<RequestParameters>(x => !x.Headers.Any()), cts.Token); }
public async void When_IsAppliedToResourceAndChildren_Should_SendDepthHeaderEqualsOne() { var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Propfind("http://example.com", new PropfindParameters { ApplyTo = ApplyTo.Propfind.ResourceAndChildren }); await dispatcher.Received(1) .Send(Arg.Any <Uri>(), WebDavMethod.Propfind, Arg.Is(Predicates.CompareHeader("Depth", "1")), CancellationToken.None); }
private void InitPars() { var pars = NavigationContext.QueryString; _client = new WebDavClient( pars["user"], pars["pass"]); _path = pars["path"]; _folder = pars["folder"]; }
public async void When_IsCalledWithTimeout_Should_SendTimeoutHeaderInSeconds() { var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Lock("http://example.com", new LockParameters { Timeout = TimeSpan.FromMinutes(2) }); await dispatcher.Received(1) .Send(Arg.Any <Uri>(), WebDavMethod.Lock, Arg.Is(Predicates.CompareHeader("Timeout", "Second-120")), CancellationToken.None); }
public async void When_IsCalledWithCancellationToken_Should_SendRequestWithIt() { var cts = new CancellationTokenSource(); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Propfind("http://example.com", new PropfindParameters { CancellationToken = cts.Token }); await dispatcher.Received(1) .Send(Arg.Any <Uri>(), WebDavMethod.Propfind, Arg.Is(Predicates.CompareHeader("Depth", "1")), cts.Token); }
public async void When_IsCalledWithDefaultParameters_Should_SendDepthHeaderEqualsInfinity() { var sourceUri = new Uri("http://example.com/old"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(sourceUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.Copy(sourceUri, new Uri("http://example.com/new")); await dispatcher.Received(1) .Send(sourceUri, WebDavMethod.Copy, Arg.Is(Predicates.CompareHeader("Depth", "infinity")), CancellationToken.None); }
public async void When_IsCalledWithDefaultArguments_Should_SendUnlockRequest() { var requestUri = new Uri("http://example.com/file"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.Unlock(requestUri, "lock-token"); await dispatcher.Received(1) .Send(requestUri, WebDavMethod.Unlock, Arg.Is<RequestParameters>(x => x.Content == null), CancellationToken.None); }
public async void When_IsCalled_Should_SendLockRequest() { var requestUri = new Uri("http://example.com/new"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.Lock(requestUri); await dispatcher.Received(1) .Send(requestUri, WebDavMethod.Lock, Arg.Any<RequestParameters>(), CancellationToken.None); }
public async void When_IsCalledWithOverwriteOff_Should_SendOverwriteHeaderEqualsF() { var sourceUri = new Uri("http://example.com/old"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(sourceUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.Move(sourceUri, new Uri("http://example.com/new"), new MoveParameters { Overwrite = false }); await dispatcher.Received(1) .Send(sourceUri, WebDavMethod.Move, Arg.Is(Predicates.CompareHeader("Overwrite", "F")), CancellationToken.None); }
public async void When_IsCalled_Should_SendMoveRequest() { var sourceUri = new Uri("http://example.com/old"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(sourceUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.Move(sourceUri, new Uri("http://example.com/new")); await dispatcher.Received(1) .Send(sourceUri, WebDavMethod.Move, Arg.Is(CheckMoveRequestParameters()), CancellationToken.None); }
public async void When_IsCalledWithCancellationToken_Should_SendRequestWithIt() { var stream = new MemoryStream(Encoding.UTF8.GetBytes("<content/>")); var cts = new CancellationTokenSource(); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.PutFile("http://example.com/file", stream, new PutFileParameters { CancellationToken = cts.Token }); await dispatcher.Received(1) .Send(Arg.Any<Uri>(), HttpMethod.Put, Arg.Is(Predicates.CompareRequestContent("<content/>")), cts.Token); }
public async void When_IsCalledWithTranslateOff_Should_SendTranslateHeaderEqualsF() { var requestUri = new Uri("http://example.com/file"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.GetFile(requestUri, false, CancellationToken.None); await dispatcher.Received(1) .Send(requestUri, HttpMethod.Get, Arg.Is(Predicates.CompareHeader("Translate", "f")), CancellationToken.None); }
public async void When_IsCalledWithLockToken_Should_SetIfHeader() { var requestUri = new Uri("http://example.com/new"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.Mkcol(requestUri, new MkColParameters { LockToken = "urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4" }); await dispatcher.Received(1) .Send(requestUri, WebDavMethod.Mkcol, Arg.Is(Predicates.CompareHeader("If", "(<urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4>)")), CancellationToken.None); }
public MyWebDavClient(IConnectionSettings connectionSettings) { _connectionSettings = connectionSettings; _client = new WebDavClient(new WebDavClientParams { Credentials = new NetworkCredential(_connectionSettings.UserName, _connectionSettings.GetPassword()), UseDefaultCredentials = false, Timeout = TimeSpan.FromMinutes(5) }); }
public async void When_IsCalledWithDefaultArguments_Should_SendDeleteRequest() { var requestUri = new Uri("http://example.com/file"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Delete(requestUri); await dispatcher.Received(1) .Send(requestUri, HttpMethod.Delete, Arg.Is <RequestParameters>(x => !x.Headers.Any() && x.Content == null), CancellationToken.None); }
public async void When_IsCalledWithCancellationToken_Should_SendRequestWithIt() { var cts = new CancellationTokenSource(); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Mkcol("http://example.com/new", new MkColParameters { CancellationToken = cts.Token }); await dispatcher.Received(1) .Send(Arg.Any <Uri>(), WebDavMethod.Mkcol, Arg.Is <RequestParameters>(x => !x.Headers.Any() && x.Content == null), cts.Token); }
public async void When_IsCalledWithDefaultArguments_Should_SendProppatchRequest() { var requestUri = new Uri("http://example.com"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.Proppatch(requestUri, new ProppatchParameters()); await dispatcher.Received(1) .Send(requestUri, WebDavMethod.Proppatch, Arg.Is<RequestParameters>(x => !x.Headers.Any()), CancellationToken.None); }
public async void When_IsCalled_Should_SendLockRequest() { var requestUri = new Uri("http://example.com/new"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Lock(requestUri); await dispatcher.Received(1) .Send(requestUri, WebDavMethod.Lock, Arg.Any <RequestParameters>(), CancellationToken.None); }
public async void When_IsCalledWithDefaultArguments_Should_SendNoHeaders() { var requestUri = new Uri("http://example.com/new"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Lock(requestUri); await dispatcher.Received(1) .Send(requestUri, WebDavMethod.Lock, Arg.Is <RequestParameters>(x => !x.Headers.Any()), CancellationToken.None); }
public async void When_IsCalledWithCancellationToken_Should_SendRequestWithIt() { var cts = new CancellationTokenSource(); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Lock("http://example.com/new", new LockParameters { CancellationToken = cts.Token }); await dispatcher.Received(1) .Send(Arg.Any <Uri>(), WebDavMethod.Lock, Arg.Any <RequestParameters>(), cts.Token); }
public async void When_IsCalledWithLockToken_Should_SetIfHeader() { var requestUri = new Uri("http://example.com/file"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Delete(requestUri, new DeleteParameters { LockToken = "urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4" }); await dispatcher.Received(1) .Send(requestUri, HttpMethod.Delete, Arg.Is(Predicates.CompareHeader("If", "(<urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4>)")), CancellationToken.None); }
public async void When_IsCalledWithDefaultArguments_Should_SendPropfindRequest() { var requestUri = new Uri("http://example.com"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.Propfind(requestUri); await dispatcher.Received(1) .Send(requestUri, WebDavMethod.Propfind, Arg.Is(Predicates.CompareHeader("Depth", "1")), CancellationToken.None); }
public async void When_GetFile_Should_SendGetRequest() { var requestUri = new Uri("http://example.com/file"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.GetFile(requestUri, false, CancellationToken.None); await client.GetFile(requestUri, true, CancellationToken.None); await dispatcher.Received(2) .Send(requestUri, HttpMethod.Get, Arg.Is<RequestParameters>(x => x.Content == null), CancellationToken.None); }
public async void When_IsCalledWithDefaultArguments_Should_SendPropertyUpdateRequest() { const string expectedContent = @"<?xml version=""1.0"" encoding=""utf-8""?> <D:propertyupdate xmlns:D=""DAV:"" />"; var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Proppatch("http://example.com", new ProppatchParameters()); await dispatcher.Received(1) .Send(Arg.Any<Uri>(), WebDavMethod.Proppatch, Arg.Is(Predicates.CompareRequestContent(expectedContent)), CancellationToken.None); }
public async void When_RequestIsSuccessfull_Should_ParseResponse() { var dispatcher = Dispatcher.Mock("response", 207, "Multi-Status"); var proppatchResponseParser = Substitute.For<IResponseParser<ProppatchResponse>>(); var client = new WebDavClient() .SetWebDavDispatcher(dispatcher) .SetProppatchResponseParser(proppatchResponseParser); proppatchResponseParser.DidNotReceiveWithAnyArgs().Parse("", 0, ""); await client.Proppatch("http://example", new ProppatchParameters()); proppatchResponseParser.Received(1).Parse("response", 207, "Multi-Status"); }
public async void When_IsCalledWithLockToken_Should_SetIfHeader() { var stream = new MemoryStream(Encoding.UTF8.GetBytes("<content/>")); var requestUri = new Uri("http://example.com/file"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.PutFile(requestUri, stream, new PutFileParameters { LockToken = "urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4" }); await dispatcher.Received(1) .Send(requestUri, HttpMethod.Put, Arg.Is(Predicates.CompareHeader("If", "(<urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4>)")), CancellationToken.None); }
public async void When_IsCalled_Should_SendPutRequestWithContent() { var stream = new MemoryStream(Encoding.UTF8.GetBytes("<content/>")); var requestUri = new Uri("http://example.com/file"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.PutFile(requestUri, stream); await dispatcher.Received(1) .Send(requestUri, HttpMethod.Put, Arg.Is(Predicates.CompareRequestContent("<content/>")), CancellationToken.None); }
public async void When_RequestIsSuccessfull_Should_ReturnStatusCode200() { var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.Mock()); var response1 = await client.Move("http://example.com/old", "http://example.com/new"); var response2 = await client.Move(new Uri("http://example.com/old"), new Uri("http://example.com/new")); var response3 = await client.Move("http://example.com/old", "http://example.com/new", new MoveParameters()); var response4 = await client.Move(new Uri("http://example.com/old"), new Uri("http://example.com/new"), new MoveParameters()); Assert.Equal(200, response1.StatusCode); Assert.Equal(200, response2.StatusCode); Assert.Equal(200, response3.StatusCode); Assert.Equal(200, response4.StatusCode); }
public async void When_IsCalledWithLockToken_Should_SendLockTokenHeader() { var requestUri = new Uri("http://example.com/file"); var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None); await client.Unlock(requestUri, "urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4"); await client.Unlock(requestUri, new UnlockParameters("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6")); await dispatcher.Received(1) .Send(requestUri, WebDavMethod.Unlock, Arg.Is(Predicates.CompareHeader("Lock-Token", "<urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4>")), CancellationToken.None); await dispatcher.Received(1) .Send(requestUri, WebDavMethod.Unlock, Arg.Is(Predicates.CompareHeader("Lock-Token", "<urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6>")), CancellationToken.None); }
public async void When_RequestIsSuccessfull_Should_ReturnStatusCode200() { var stream = new MemoryStream(Encoding.UTF8.GetBytes("<content/>")); var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.Mock()); var response1 = await client.PutFile("http://example.com/file", stream); var response2 = await client.PutFile(new Uri("http://example.com/file"), stream); var response3 = await client.PutFile("http://example.com/file", stream, "text/xml"); var response4 = await client.PutFile(new Uri("http://example.com/file"), stream, "text/xml"); var response5 = await client.PutFile(new Uri("http://example.com/file"), stream, new PutFileParameters()); var response6 = await client.PutFile(new Uri("http://example.com/file"), stream, new PutFileParameters()); Assert.Equal(200, response1.StatusCode); Assert.Equal(200, response2.StatusCode); Assert.Equal(200, response3.StatusCode); Assert.Equal(200, response4.StatusCode); Assert.Equal(200, response5.StatusCode); Assert.Equal(200, response6.StatusCode); }
public async void When_SetProperties_Should_IncludeThemInSetTag() { const string expectedContent = @"<?xml version=""1.0"" encoding=""utf-8""?> <D:propertyupdate xmlns:D=""DAV:""> <D:set> <D:prop> <prop1>value1</prop1> </D:prop> <D:prop> <prop2>value2</prop2> </D:prop> </D:set> </D:propertyupdate>"; var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); var propertiesToSet = new Dictionary<XName, string> { {"prop1", "value1"}, {"prop2", "value2"} }; await client.Proppatch("http://example.com", new ProppatchParameters { PropertiesToSet = propertiesToSet }); await dispatcher.Received(1) .Send(Arg.Any<Uri>(), WebDavMethod.Proppatch, Arg.Is(Predicates.CompareRequestContent(expectedContent)), CancellationToken.None); }
public async void When_RemoveProperties_Should_IncludeThemInRemoveTag() { const string expectedContent = @"<?xml version=""1.0"" encoding=""utf-8""?> <D:propertyupdate xmlns:D=""DAV:""> <D:remove> <D:prop> <prop1 /> </D:prop> <D:prop> <prop2 /> </D:prop> </D:remove> </D:propertyupdate>"; var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Proppatch("http://example.com", new ProppatchParameters { PropertiesToRemove = new XName[] { "prop1", "prop2" } }); await dispatcher.Received(1) .Send(Arg.Any<Uri>(), WebDavMethod.Proppatch, Arg.Is(Predicates.CompareRequestContent(expectedContent)), CancellationToken.None); }
public async void When_RemovePropertiesWithNamespaces_Should_IncludeXmlnsTagAndUsePrefixes() { const string expectedContent = @"<?xml version=""1.0"" encoding=""utf-8""?> <D:propertyupdate xmlns:D=""DAV:"" xmlns:X=""http://x.example.com/"" xmlns=""http://y.example.com/""> <D:remove> <D:prop> <X:prop1 /> </D:prop> <D:prop> <prop2 /> </D:prop> </D:remove> </D:propertyupdate>"; var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); var propertiesToRemove = new XName[] { "{http://x.example.com/}prop1", "{http://y.example.com/}prop2" }; var ns = new[] { new NamespaceAttr("X", "http://x.example.com/"), new NamespaceAttr("http://y.example.com/") }; await client.Proppatch("http://example.com", new ProppatchParameters { PropertiesToRemove = propertiesToRemove, Namespaces = ns}); await dispatcher.Received(1) .Send(Arg.Any<Uri>(), WebDavMethod.Proppatch, Arg.Is(Predicates.CompareRequestContent(expectedContent)), CancellationToken.None); }
public async void When_IsCalledWithTimeout_Should_SendTimeoutHeaderInSeconds() { var dispatcher = Dispatcher.Mock(); var client = new WebDavClient().SetWebDavDispatcher(dispatcher); await client.Lock("http://example.com", new LockParameters { Timeout = TimeSpan.FromMinutes(2) }); await dispatcher.Received(1) .Send(Arg.Any<Uri>(), WebDavMethod.Lock, Arg.Is(Predicates.CompareHeader("Timeout", "Second-120")), CancellationToken.None); }