From 1a9497b7184a2b37b9f9522441aa05d9d234d731 Mon Sep 17 00:00:00 2001 From: cristi-badila Date: Thu, 15 Jan 2015 14:06:43 +0200 Subject: [PATCH] adds support for PATCH method --- .../InterfaceStubGenerator.cs | 2 +- Refit-Tests/RequestBuilder.cs | 25 +++++++++++++++++++ Refit/Attributes.cs | 10 ++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/InterfaceStubGenerator/InterfaceStubGenerator.cs b/InterfaceStubGenerator/InterfaceStubGenerator.cs index 543981933..f43650910 100644 --- a/InterfaceStubGenerator/InterfaceStubGenerator.cs +++ b/InterfaceStubGenerator/InterfaceStubGenerator.cs @@ -58,7 +58,7 @@ public List FindInterfacesToGenerate(SyntaxTree tree } static readonly HashSet httpMethodAttributeNames = new HashSet( - new[] {"Get", "Head", "Post", "Put", "Delete"} + new[] {"Get", "Head", "Post", "Put", "Delete", "Patch"} .SelectMany(x => new[] {"{0}", "{0}Attribute"}.Select(f => string.Format(f, x)))); public bool HasRefitHttpMethodAttribute(MethodDeclarationSyntax method) diff --git a/Refit-Tests/RequestBuilder.cs b/Refit-Tests/RequestBuilder.cs index 57daa5c21..75b891a6a 100644 --- a/Refit-Tests/RequestBuilder.cs +++ b/Refit-Tests/RequestBuilder.cs @@ -55,6 +55,9 @@ public interface IRestMethodInfoTests [Post("/foo/{id}")] string AsyncOnlyBuddy(int id); + + [Patch("/foo/{id}")] + IObservable PatchSomething(int id, [Body] string someAttribute); } [TestFixture] @@ -234,6 +237,15 @@ public void SyncMethodsShouldThrow() Assert.IsFalse(shouldDie); } + + [Test] + public void UsingThePatchAttributeSetsTheCorrectMethod() + { + var input = typeof(IRestMethodInfoTests); + var fixture = new RestMethodInfo(input, input.GetMethods().First(x => x.Name == "PatchSomething")); + + Assert.AreEqual("Patch", fixture.HttpMethod.Method); + } } [Headers("User-Agent: RefitTestClient", "Api-Version: 1")] @@ -292,6 +304,9 @@ public interface IDummyHttpApi [Post("/foo/bar/{id}")] Task PostAValueType(int id, [Body] Guid? content); + + [Patch("/foo/bar/{id}")] + IObservable PatchSomething(int id, [Body] string someAttribute); } public class SomeRequestData @@ -615,5 +630,15 @@ public async Task ICanPostAValueTypeIfIWantYoureNotTheBossOfMe() Assert.AreEqual(expected, content); } + + [Test] + public async Task SupportPATCHMethod() + { + var fixture = new RequestBuilderImplementation(typeof(IDummyHttpApi)); + var factory = fixture.BuildRequestFactoryForMethod("PatchSomething"); + var output = factory(new object[] { "testData" }); + + Assert.AreEqual("Patch", output.Method.Method); + } } } diff --git a/Refit/Attributes.cs b/Refit/Attributes.cs index 1d8539afb..bad7cec5d 100644 --- a/Refit/Attributes.cs +++ b/Refit/Attributes.cs @@ -58,6 +58,16 @@ public override HttpMethod Method { get { return HttpMethod.Delete; } } } + + [AttributeUsage(AttributeTargets.Method)] + public class PatchAttribute : HttpMethodAttribute + { + public PatchAttribute(string path) : base(path) { } + + public override HttpMethod Method { + get { return new HttpMethod("PATCH"); } + } + } [AttributeUsage(AttributeTargets.Method)] public class HeadAttribute : HttpMethodAttribute