Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 004b7c5

Browse files
authored
Merge pull request #1478 from github/cleanup/LogManager-CA1004
Fix a bunch of warnings in release build
2 parents 3576f31 + fe3e119 commit 004b7c5

File tree

10 files changed

+32
-33
lines changed

10 files changed

+32
-33
lines changed

src/GitHub.App/Api/ApiClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ public IObservable<PullRequest> GetPullRequestsForRepository(string owner, strin
242242
Guard.ArgumentNotEmptyString(name, nameof(name));
243243

244244
return gitHubClient.PullRequest.GetAllForRepository(owner, name,
245-
new PullRequestRequest {
245+
new PullRequestRequest
246+
{
246247
State = ItemStateFilter.All,
247248
SortProperty = PullRequestSort.Updated,
248249
SortDirection = SortDirection.Descending
@@ -268,7 +269,7 @@ public IObservable<Branch> GetBranches(string owner, string repo)
268269
Guard.ArgumentNotEmptyString(owner, nameof(owner));
269270
Guard.ArgumentNotEmptyString(repo, nameof(repo));
270271

271-
#pragma warning disable CS0618
272+
#pragma warning disable 618
272273
// GetAllBranches is obsolete, but don't want to introduce the change to fix the
273274
// warning in the PR, so disabling for now.
274275
return gitHubClient.Repository.GetAllBranches(owner, repo);

src/GitHub.Logging/Logging/LogManager.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Diagnostics.CodeAnalysis;
34
using GitHub.Info;
45
using Serilog;
56
using Serilog.Core;
@@ -33,10 +34,8 @@ static Logger CreateLogger()
3334

3435
static Lazy<Logger> Logger { get; } = new Lazy<Logger>(CreateLogger);
3536

36-
//Violates CA1004 - Generic methods should provide type parameter
37-
#pragma warning disable CA1004
37+
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
3838
public static ILogger ForContext<T>() => ForContext(typeof(T));
39-
#pragma warning restore CA1004
4039

4140
public static ILogger ForContext(Type type) => Logger.Value.ForContext(type).ForContext("ShortSourceContext", type.Name);
4241
}

test/GitHub.InlineReviews.UnitTests/TestDoubles/FakeDiffService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public string AddFile(string path, string contents)
3939
var directory = Path.GetDirectoryName(fullPath);
4040
Directory.CreateDirectory(directory);
4141
File.WriteAllText(fullPath, contents);
42+
#pragma warning disable 618 // Type or member is obsolete
4243
repository.Stage(path);
44+
#pragma warning restore 618 // Type or member is obsolete
4345
repository.Commit("Added " + path, signature, signature);
4446
return repository.Head.Tip.Sha;
4547
}
@@ -106,7 +108,9 @@ static IRepository CreateRepository()
106108
var signature = new Signature("user", "user@user", DateTimeOffset.Now);
107109

108110
File.WriteAllText(Path.Combine(tempPath, ".gitattributes"), "* text=auto");
111+
#pragma warning disable 618 // Type or member is obsolete
109112
result.Stage("*");
113+
#pragma warning restore 618 // Type or member is obsolete
110114
result.Commit("Initial commit", signature, signature);
111115

112116
return result;

test/UnitTests/GitHub.Api/LoginManagerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public async Task ErasesLoginWhenNonOctokitExceptionThrown()
250250
var keychain = Substitute.For<IKeychain>();
251251
var tfa = new Lazy<ITwoFactorChallengeHandler>(() => Substitute.For<ITwoFactorChallengeHandler>());
252252
var oauthListener = Substitute.For<IOAuthCallbackListener>();
253-
253+
254254
var target = new LoginManager(keychain, tfa, oauthListener, "id", "secret", scopes);
255255
Assert.ThrowsAsync<InvalidOperationException>(async () => await target.Login(host, client, "foo", "bar"));
256256

@@ -283,7 +283,7 @@ public async Task ErasesLoginWhenNonOctokitExceptionThrownIn2FA()
283283
}
284284

285285
[Test]
286-
public async Task InvalidResponseScopesCauseException()
286+
public void InvalidResponseScopesCauseException()
287287
{
288288
var client = CreateClient(responseScopes: new[] { "user", "repo" });
289289
client.Authorization.GetOrCreateApplicationAuthentication("id", "secret", Arg.Any<NewAuthorization>())

test/UnitTests/GitHub.App/Caches/ImageCacheTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async Task WhenLoadingFromCacheFailsInvalidatesCacheEntry()
5555
Assert.That(retrieved, Is.Null);
5656
Assert.ThrowsAsync<KeyNotFoundException>(async () => await cache.Get("https://fake/"));
5757
}
58-
58+
5959
[Test]
6060
public async Task DownloadsImageWhenMissingAndCachesIt()
6161
{
@@ -76,7 +76,7 @@ public async Task DownloadsImageWhenMissingAndCachesIt()
7676
}
7777

7878
[Test]
79-
public async Task ThrowsKeyNotFoundExceptionWhenItemNotInCacheAndImageFetchThrowsException()
79+
public void ThrowsKeyNotFoundExceptionWhenItemNotInCacheAndImageFetchThrowsException()
8080
{
8181
var imageUri = new Uri("https://example.com/poop.gif");
8282
var cacheFactory = Substitute.For<IBlobCacheFactory>();
@@ -91,7 +91,7 @@ public async Task ThrowsKeyNotFoundExceptionWhenItemNotInCacheAndImageFetchThrow
9191
}
9292

9393
[Test]
94-
public async Task ThrowsKeyNotFoundExceptionWhenItemNotInCacheAndImageFetchReturnsEmpty()
94+
public void ThrowsKeyNotFoundExceptionWhenItemNotInCacheAndImageFetchReturnsEmpty()
9595
{
9696
var imageUri = new Uri("https://example.com/poop.gif");
9797
var cache = new InMemoryBlobCache();

test/UnitTests/GitHub.App/Models/AccountModelTests.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,13 @@ public static bool BitmapSourcesAreEqual(BitmapSource image1, BitmapSource image
119119

120120
public static byte[] BitmapSourceToBytes(BitmapSource image)
121121
{
122-
byte[] data = new byte[] { };
123-
if (image != null)
122+
var encoder = new BmpBitmapEncoder();
123+
encoder.Frames.Add(BitmapFrame.Create(image));
124+
using (MemoryStream ms = new MemoryStream())
124125
{
125-
try
126-
{
127-
var encoder = new BmpBitmapEncoder();
128-
encoder.Frames.Add(BitmapFrame.Create(image));
129-
using (MemoryStream ms = new MemoryStream())
130-
{
131-
encoder.Save(ms);
132-
data = ms.ToArray();
133-
}
134-
return data;
135-
}
136-
catch (Exception ex)
137-
{
138-
}
126+
encoder.Save(ms);
127+
return ms.ToArray();
139128
}
140-
141-
return data;
142129
}
143130
}
144131
}

test/UnitTests/GitHub.App/Services/GitClientTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ public async Task LocalBaseHeadAndMergeBase_DontFetch()
250250

251251
var mergeBaseSha = await gitClient.GetPullRequestMergeBase(repo, targetCloneUrl, baseSha, headSha, baseRef, pullNumber);
252252

253+
#pragma warning disable 618 // Type or member is obsolete
253254
repo.Network.DidNotReceiveWithAnyArgs().Fetch(null as Remote, null, null as FetchOptions);
255+
#pragma warning restore 618 // Type or member is obsolete
254256
Assert.That(expectMergeBaseSha, Is.EqualTo(mergeBaseSha));
255257
}
256258

@@ -274,7 +276,9 @@ public async Task WhenToFetch(string baseSha, string headSha, string mergeBaseSh
274276
}
275277
catch (NotFoundException) { /* We're interested in calls to Fetch even if it throws */ }
276278

279+
#pragma warning disable 618 // Type or member is obsolete
277280
repo.Network.Received(receivedFetch).Fetch(Arg.Any<Remote>(), Arg.Any<string[]>(), Arg.Any<FetchOptions>());
281+
#pragma warning restore 618 // Type or member is obsolete
278282
}
279283

280284
[TestCase("baseSha", null, "mergeBaseSha", "baseRef", 777, "refs/pull/777/head")]
@@ -295,7 +299,9 @@ public async Task WhatToFetch(string baseSha, string headSha, string mergeBaseSh
295299
}
296300
catch (NotFoundException) { /* We're interested in calls to Fetch even if it throws */ }
297301

302+
#pragma warning disable 618 // Type or member is obsolete
298303
repo.Network.Received(1).Fetch(Arg.Any<Remote>(), Arg.Is<IEnumerable<string>>(x => x.Contains(expectRefSpec)), Arg.Any<FetchOptions>());
304+
#pragma warning restore 618 // Type or member is obsolete
299305
}
300306

301307
static IRepository MockRepo(string baseSha, string headSha, string mergeBaseSha)

test/UnitTests/GitHub.App/Services/PullRequestServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ public async Task ExtractBase_MergeBaseAvailable_UseMergeBaseSha()
616616
}
617617

618618
[Test]
619-
public async Task MergeBaseNotAvailable_ThrowsNotFoundException()
619+
public void MergeBaseNotAvailable_ThrowsNotFoundException()
620620
{
621621
var baseFileContent = "baseFileContent";
622622
var headFileContent = "headFileContent";

test/UnitTests/GitHub.VisualStudio/Services/ConnectionManagerTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task ReturnsInvalidConnections()
4747
var result = await target.GetLoadedConnections();
4848

4949
Assert.That(2, Is.EqualTo(result.Count));
50-
Assert.That("https://github.com/",Is.EqualTo(result[0].HostAddress.WebUri.ToString()));
50+
Assert.That("https://github.com/", Is.EqualTo(result[0].HostAddress.WebUri.ToString()));
5151
Assert.That("https://invalid.com/", Is.EqualTo(result[1].HostAddress.WebUri.ToString()));
5252
Assert.That(result[0].ConnectionError, Is.Null);
5353
Assert.That(result[1].ConnectionError, Is.Not.Null);
@@ -121,7 +121,7 @@ public async Task AddsLoggedInConnectionToConnections()
121121
}
122122

123123
[Test]
124-
public async Task ThrowsWhenLoginFails()
124+
public void ThrowsWhenLoginFails()
125125
{
126126
var target = new ConnectionManager(
127127
CreateProgram(),
@@ -136,7 +136,7 @@ public async Task ThrowsWhenLoginFails()
136136
}
137137

138138
[Test]
139-
public async Task ThrowsWhenExistingConnectionExists()
139+
public void ThrowsWhenExistingConnectionExists()
140140
{
141141
var target = new ConnectionManager(
142142
CreateProgram(),
@@ -208,7 +208,7 @@ public async Task RemovesConnectionFromConnections()
208208
}
209209

210210
[Test]
211-
public async Task ThrowsIfConnectionDoesntExist()
211+
public void ThrowsIfConnectionDoesntExist()
212212
{
213213
var loginManager = CreateLoginManager();
214214
var target = new ConnectionManager(

test/UnitTests/TestDoubles/FakeCommitLog.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ public ICommitLog QueryBy(CommitFilter filter)
3232
throw new NotImplementedException();
3333
}
3434

35+
#pragma warning disable 618 // Type or member is obsolete
3536
public IEnumerable<LogEntry> QueryBy(string path, FollowFilter filter)
3637
{
3738
throw new NotImplementedException();
3839
}
40+
#pragma warning restore 618 // Type or member is obsolete
3941

4042
public IEnumerable<LogEntry> QueryBy(string path, CommitFilter filter)
4143
{

0 commit comments

Comments
 (0)