Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion InterfaceStubGenerator/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public List<InterfaceDeclarationSyntax> FindInterfacesToGenerate(SyntaxTree tree
}

static readonly HashSet<string> httpMethodAttributeNames = new HashSet<string>(
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)
Expand Down
25 changes: 25 additions & 0 deletions Refit-Tests/RequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public interface IRestMethodInfoTests

[Post("/foo/{id}")]
string AsyncOnlyBuddy(int id);

[Patch("/foo/{id}")]
IObservable<string> PatchSomething(int id, [Body] string someAttribute);
}

[TestFixture]
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -292,6 +304,9 @@ public interface IDummyHttpApi

[Post("/foo/bar/{id}")]
Task<bool> PostAValueType(int id, [Body] Guid? content);

[Patch("/foo/bar/{id}")]
IObservable<string> PatchSomething(int id, [Body] string someAttribute);
}

public class SomeRequestData
Expand Down Expand Up @@ -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);
}
}
}
10 changes: 10 additions & 0 deletions Refit/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down