Skip to content

Commit

Permalink
Modernize code
Browse files Browse the repository at this point in the history
  • Loading branch information
Oren Novotny committed Jun 19, 2017
1 parent 59bf5a7 commit 8770888
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 104 deletions.
1 change: 1 addition & 0 deletions Directory.build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
<Description>The automatic type-safe REST library for Xamarin and .NET</Description>
<NoWarn>$(NoWarn);1701;1702;CS1591</NoWarn>
<NoPackageAnalysis>true</NoPackageAnalysis>
</PropertyGroup>

<ItemGroup Condition="'$(IsTestProject)' != 'true' and '$(NCrunch)' == '' and '$(SourceLinkEnabled)' != 'false'">
Expand Down
20 changes: 12 additions & 8 deletions Refit.Tests/RestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

namespace Refit.Tests
{
#pragma warning disable IDE1006 // Naming Styles
public class RootObject
{
public string _id { get; set; }
public string _rev { get; set; }
public string name { get; set; }
public string name { get; set; }
}
#pragma warning restore IDE1006 // Naming Styles

[Headers("User-Agent: Refit Integration Tests")]
public interface INpmJs
Expand Down Expand Up @@ -96,7 +98,7 @@ public async Task HitTheGitHubUserApi()
var result = await fixture.GetUser("octocat");

Assert.Equal("octocat", result.Login);
Assert.False(String.IsNullOrEmpty(result.AvatarUrl));
Assert.False(string.IsNullOrEmpty(result.AvatarUrl));

mockHttp.VerifyNoOutstandingExpectation();
}
Expand All @@ -119,7 +121,7 @@ public async Task HitWithCamelCaseParameter()
var result = await fixture.GetUserCamelCase("octocat");

Assert.Equal("octocat", result.Login);
Assert.False(String.IsNullOrEmpty(result.AvatarUrl));
Assert.False(string.IsNullOrEmpty(result.AvatarUrl));

mockHttp.VerifyNoOutstandingExpectation();
}
Expand Down Expand Up @@ -191,7 +193,7 @@ public async Task HitTheGitHubUserApiAsObservable()
.Timeout(TimeSpan.FromSeconds(10));

Assert.Equal("octocat", result.Login);
Assert.False(String.IsNullOrEmpty(result.AvatarUrl));
Assert.False(string.IsNullOrEmpty(result.AvatarUrl));

mockHttp.VerifyNoOutstandingExpectation();
}
Expand Down Expand Up @@ -219,16 +221,18 @@ public async Task HitTheGitHubUserApiAsObservableAndSubscribeAfterTheFact()
await obs;
var result2 = await obs;
Assert.Equal("octocat", result2.Login);
Assert.False(String.IsNullOrEmpty(result2.AvatarUrl));
Assert.False(string.IsNullOrEmpty(result2.AvatarUrl));
}

[Fact]
public async Task TwoSubscriptionsResultInTwoRequests()
{
var input = new TestHttpMessageHandler();
var input = new TestHttpMessageHandler
{

// we need to use a factory here to ensure each request gets its own httpcontent instance
input.ContentFactory = () => new StringContent("test");
// we need to use a factory here to ensure each request gets its own httpcontent instance
ContentFactory = () => new StringContent("test")
};

var client = new HttpClient(input) { BaseAddress = new Uri("http://foo") };
var fixture = RestService.For<IGitHubApi>(client);
Expand Down
27 changes: 5 additions & 22 deletions Refit/MultipartItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ public abstract class MultipartItem
{
public MultipartItem(string fileName, string contentType)
{
if (fileName == null)
{
throw new ArgumentNullException("fileName");
}

this.FileName = fileName;
this.ContentType = contentType;
FileName = fileName ?? throw new ArgumentNullException("fileName");
ContentType = contentType;
}

public string FileName { get; private set; }
Expand All @@ -43,11 +38,7 @@ public class StreamPart : MultipartItem
public StreamPart(Stream value, string fileName, string contentType = null) :
base(fileName, contentType)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
Value = value;
Value = value ?? throw new ArgumentNullException("value");
}

public Stream Value { get; private set; }
Expand All @@ -63,11 +54,7 @@ public class ByteArrayPart : MultipartItem
public ByteArrayPart(byte[] value, string fileName, string contentType = null) :
base(fileName, contentType)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
Value = value;
Value = value ?? throw new ArgumentNullException("value");
}

public byte[] Value { get; private set; }
Expand All @@ -83,11 +70,7 @@ public class FileInfoPart : MultipartItem
public FileInfoPart(FileInfo value, string fileName, string contentType = null) :
base(fileName, contentType)
{
if (value == null)
{
throw new ArgumentNullException("value");
}
Value = value;
Value = value ?? throw new ArgumentNullException("value");
}

public FileInfo Value { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion Refit/RefitSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DefaultUrlParameterFormatter : IUrlParameterFormatter
{
public virtual string Format(object parameterValue, ParameterInfo parameterInfo)
{
return parameterValue != null ? parameterValue.ToString() : null;
return parameterValue?.ToString();
}
}
}
Loading

0 comments on commit 8770888

Please sign in to comment.