Skip to content

Commit

Permalink
Release/v2.1.0 (#15)
Browse files Browse the repository at this point in the history
- Fixed #13
- Implemented #14
- Bumped a version to 2.1.0
  • Loading branch information
skazantsev authored Feb 21, 2018
1 parent 616353e commit 3e4e6bf
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 71 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ using (var webDavClient = new WebDavClient(clientParams))
}
```

**Custom headers:**
``` csharp
using (var webDavClient = new WebDavClient())
{
var propfindParams = new PropfindParameters
{
Headers = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("User-Agent", "Not a browser")
}
};
var result = await webDavClient.Propfind("http://mywebdav/1.txt", propfindParams);
}
```

**Synchronous API:**
``` csharp
// will block the current thread, so use it cautiously
Expand Down
24 changes: 12 additions & 12 deletions src/WebDav.Client.Tests/WebDavClientTests/GetFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ public class GetFileTests
public async void When_GetRawFileIsCalled_Should_ProxyCallToGetFile()
{
var client = Substitute.ForPartsOf<WebDavClient>().SetWebDavDispatcher(Dispatcher.Mock());
client.GetFile(Arg.Any<Uri>(), Arg.Any<bool>(), Arg.Any<CancellationToken>()).Returns(new WebDavStreamResponse(200));
client.GetFile(Arg.Any<Uri>(), Arg.Any<bool>(), Arg.Any<GetFileParameters>()).Returns(new WebDavStreamResponse(200));

await client.GetRawFile(new Uri("http://example.com/file"));
await client.GetRawFile("http://example.com/file");
await client.GetRawFile(new Uri("http://example.com/file"), new GetFileParameters());
await client.GetRawFile("http://example.com/file", new GetFileParameters());

await client.Received(4).GetFile(Arg.Is<Uri>(x => x.ToString() == "http://example.com/file"), false, CancellationToken.None);
await client.Received(4).GetFile(Arg.Is<Uri>(x => x.ToString() == "http://example.com/file"), false, Arg.Any<GetFileParameters>());
}

[Fact]
public async void When_GetProcessedFileIsCalled_Should_ProxyCallToGetFile()
{
var client = Substitute.ForPartsOf<WebDavClient>().SetWebDavDispatcher(Dispatcher.Mock());
client.GetFile(Arg.Any<Uri>(), Arg.Any<bool>(), Arg.Any<CancellationToken>()).Returns(new WebDavStreamResponse(200));
client.GetFile(Arg.Any<Uri>(), Arg.Any<bool>(), Arg.Any<GetFileParameters>()).Returns(new WebDavStreamResponse(200));

await client.GetProcessedFile(new Uri("http://example.com/file"));
await client.GetProcessedFile("http://example.com/file");
await client.GetProcessedFile(new Uri("http://example.com/file"), new GetFileParameters());
await client.GetProcessedFile("http://example.com/file", new GetFileParameters());

await client.Received(4).GetFile(Arg.Is<Uri>(x => x.ToString() == "http://example.com/file"), true, CancellationToken.None);
await client.Received(4).GetFile(Arg.Is<Uri>(x => x.ToString() == "http://example.com/file"), true, Arg.Any<GetFileParameters>());
}

[Fact]
public async void When_RequestIsSuccessfull_Should_ReturnStatusCode200()
{
var client = new WebDavClient().SetWebDavDispatcher(Dispatcher.Mock());
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);
var response1 = await client.GetFile(new Uri("http://example.com/file"), false, new GetFileParameters());
var response2 = await client.GetFile(new Uri("http://example.com/file"), true, new GetFileParameters());

Assert.Equal(200, response1.StatusCode);
Assert.Equal(200, response2.StatusCode);
Expand All @@ -52,8 +52,8 @@ public async void When_RequestIsSuccessfull_Should_ReturnStatusCode200()
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);
var response1 = await client.GetFile(new Uri("http://example.com/file"), false, new GetFileParameters());
var response2 = await client.GetFile(new Uri("http://example.com/file"), true, new GetFileParameters());

Assert.Equal(500, response1.StatusCode);
Assert.Equal(500, response2.StatusCode);
Expand All @@ -67,8 +67,8 @@ public async void When_GetFile_Should_SendGetRequest()
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 client.GetFile(requestUri, false, new GetFileParameters());
await client.GetFile(requestUri, true, new GetFileParameters());
await dispatcher.Received(2)
.Send(requestUri, HttpMethod.Get, Arg.Is<RequestParameters>(x => x.Content == null), CancellationToken.None);
}
Expand All @@ -81,7 +81,7 @@ public async void When_IsCalledWithTranslateOff_Should_SendTranslateHeaderEquals
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, false, new GetFileParameters());
await dispatcher.Received(1)
.Send(requestUri, HttpMethod.Get, Arg.Is(Predicates.CompareHeader("Translate", "f")), CancellationToken.None);
}
Expand All @@ -94,7 +94,7 @@ public async void When_IsCalledWithTranslateOn_Should_SendTranslateHeaderEqualsT
var client = new WebDavClient().SetWebDavDispatcher(dispatcher);

await dispatcher.DidNotReceiveWithAnyArgs().Send(requestUri, Arg.Any<HttpMethod>(), new RequestParameters(), CancellationToken.None);
await client.GetFile(requestUri, true, CancellationToken.None);
await client.GetFile(requestUri, true, new GetFileParameters());
await dispatcher.Received(1)
.Send(requestUri, HttpMethod.Get, Arg.Is(Predicates.CompareHeader("Translate", "t")), CancellationToken.None);
}
Expand Down
9 changes: 8 additions & 1 deletion src/WebDav.Client/ApiParams/CopyParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.Collections.Generic;
using System.Threading;

namespace WebDav
{
Expand All @@ -13,6 +14,7 @@ public class CopyParameters
public CopyParameters()
{
Overwrite = true;
Headers = new List<KeyValuePair<string, string>>();
CancellationToken = CancellationToken.None;
}

Expand All @@ -36,6 +38,11 @@ public CopyParameters()
/// </value>
public bool Overwrite { get; set; }

/// <summary>
/// Gets or sets the collection of http request headers.
/// </summary>
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; set; }

/// <summary>
/// Gets or sets the cancellation token.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/WebDav.Client/ApiParams/DeleteParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.Collections.Generic;
using System.Threading;

namespace WebDav
{
Expand All @@ -12,6 +13,7 @@ public class DeleteParameters
/// </summary>
public DeleteParameters()
{
Headers = new List<KeyValuePair<string, string>>();
CancellationToken = CancellationToken.None;
}

Expand All @@ -20,6 +22,11 @@ public DeleteParameters()
/// </summary>
public string LockToken { get; set; }

/// <summary>
/// Gets or sets the collection of http request headers.
/// </summary>
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; set; }

/// <summary>
/// Gets or sets the cancellation token.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/WebDav.Client/ApiParams/GetFileParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.Collections.Generic;
using System.Threading;

namespace WebDav
{
Expand All @@ -12,9 +13,15 @@ public class GetFileParameters
/// </summary>
public GetFileParameters()
{
Headers = new List<KeyValuePair<string, string>>();
CancellationToken = CancellationToken.None;
}

/// <summary>
/// Gets or sets the collection of http request headers.
/// </summary>
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; set; }

/// <summary>
/// Gets or sets the cancellation token.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/WebDav.Client/ApiParams/LockParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading;

namespace WebDav
Expand All @@ -13,6 +14,7 @@ public class LockParameters
/// </summary>
public LockParameters()
{
Headers = new List<KeyValuePair<string, string>>();
CancellationToken = CancellationToken.None;
}

Expand All @@ -37,6 +39,11 @@ public LockParameters()
/// </summary>
public LockOwner Owner { get; set; }

/// <summary>
/// Gets or sets the collection of http request headers.
/// </summary>
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; set; }

/// <summary>
/// Gets or sets the cancellation token.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/WebDav.Client/ApiParams/MkColParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.Collections.Generic;
using System.Threading;

namespace WebDav
{
Expand All @@ -12,6 +13,7 @@ public class MkColParameters
/// </summary>
public MkColParameters()
{
Headers = new List<KeyValuePair<string, string>>();
CancellationToken = CancellationToken.None;
}

Expand All @@ -20,6 +22,11 @@ public MkColParameters()
/// </summary>
public string LockToken { get; set; }

/// <summary>
/// Gets or sets the collection of http request headers.
/// </summary>
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; set; }

/// <summary>
/// Gets or sets the cancellation token.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/WebDav.Client/ApiParams/MoveParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.Collections.Generic;
using System.Threading;

namespace WebDav
{
Expand All @@ -13,6 +14,7 @@ public class MoveParameters
public MoveParameters()
{
Overwrite = true;
Headers = new List<KeyValuePair<string, string>>();
CancellationToken = CancellationToken.None;
}

Expand All @@ -35,6 +37,11 @@ public MoveParameters()
/// </value>
public bool Overwrite { get; set; }

/// <summary>
/// Gets or sets the collection of http request headers.
/// </summary>
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; set; }

/// <summary>
/// Gets or sets the cancellation token.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/WebDav.Client/ApiParams/PropfindParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public PropfindParameters()
{
CustomProperties = new List<XName>();
Namespaces = new List<NamespaceAttr>();
Headers = new List<KeyValuePair<string, string>>();
CancellationToken = CancellationToken.None;
}

Expand All @@ -35,6 +36,11 @@ public PropfindParameters()
/// </summary>
public ApplyTo.Propfind? ApplyTo { get; set; }

/// <summary>
/// Gets or sets the collection of http request headers.
/// </summary>
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; set; }

/// <summary>
/// Gets or sets the cancellation token.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/WebDav.Client/ApiParams/ProppatchParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public ProppatchParameters()
PropertiesToSet = new Dictionary<XName, string>();
PropertiesToRemove = new List<XName>();
Namespaces = new List<NamespaceAttr>();
Headers = new List<KeyValuePair<string, string>>();
CancellationToken = CancellationToken.None;
}

Expand All @@ -35,6 +36,11 @@ public ProppatchParameters()
/// </summary>
public IReadOnlyCollection<NamespaceAttr> Namespaces { get; set; }

/// <summary>
/// Gets or sets the collection of http request headers.
/// </summary>
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; set; }

/// <summary>
/// Gets or sets the cancellation token.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/WebDav.Client/ApiParams/PutFileParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.Collections.Generic;
using System.Threading;

namespace WebDav
{
Expand All @@ -13,6 +14,7 @@ public class PutFileParameters
public PutFileParameters()
{
ContentType = "application/octet-stream";
Headers = new List<KeyValuePair<string, string>>();
CancellationToken = CancellationToken.None;
}

Expand All @@ -27,6 +29,11 @@ public PutFileParameters()
/// </summary>
public string LockToken { get; set; }

/// <summary>
/// Gets or sets the collection of http request headers.
/// </summary>
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; set; }

/// <summary>
/// Gets or sets the cancellation token.
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/WebDav.Client/ApiParams/UnlockParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System.Collections.Generic;
using System.Threading;

namespace WebDav
{
Expand All @@ -16,6 +17,7 @@ public UnlockParameters(string lockToken)
Guard.NotNull(lockToken, "lockToken");

LockToken = lockToken;
Headers = new List<KeyValuePair<string, string>>();
CancellationToken = CancellationToken.None;
}

Expand All @@ -24,6 +26,11 @@ public UnlockParameters(string lockToken)
/// </summary>
public string LockToken { get; }

/// <summary>
/// Gets or sets the collection of http request headers.
/// </summary>
public IReadOnlyCollection<KeyValuePair<string, string>> Headers { get; set; }

/// <summary>
/// Gets or sets the cancellation token.
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions src/WebDav.Client/Domain/WebDavHeaders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace WebDav.Client.Domain
{
internal static class WebDavHeaders
{
public static readonly string Depth = "Depth";

public static readonly string Destination = "Destination";

public static readonly string If = "If";

public static readonly string LockToken = "Lock-Token";

public static readonly string Overwrite = "Overwrite";

public static readonly string Timeout = "Timeout";

public static readonly string Translate = "Translate";
}
}
Loading

0 comments on commit 3e4e6bf

Please sign in to comment.