8000 Fix test warnings · wtf3505-git/libgit2sharp@e3d2565 · GitHub
[go: up one dir, main page]

Skip to content

Commit e3d2565

Browse files
committed
Fix test warnings
1 parent 587d2ed commit e3d2565

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+266
-268
lines changed

LibGit2Sharp.Tests/BlameFixture.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class BlameFixture : BaseFixture
99
{
1010
private static void AssertCorrectHeadBlame(BlameHunkCollection blame)
1111
{
12-
Assert.Equal(1, blame.Count());
12+
Assert.Single(blame);
1313
Assert.Equal(0, blame[0].FinalStartLineNumber);
1414
Assert.Equal("schacon@gmail.com", blame[0].FinalSignature.Email);
1515
Assert.Equal("4a202b3", blame[0].FinalCommit.Id.ToString(7));
@@ -39,7 +39,7 @@ public void CanBlameFromADifferentCommit()
3939
Assert.Throws<NotFoundException>(() => repo.Blame("ancestor-only.txt"));
4040

4141
var blame = repo.Blame("ancestor-only.txt", new BlameOptions { StartingAt = "9107b30" });
42-
Assert.Equal(1, blame.Count());
42+
Assert.Single(blame);
4343
}
4444
}
4545

@@ -79,7 +79,7 @@ public void CanStopBlame()
7979
// 9fd738e8 (Scott Chacon 2010-05-24 10:19:19 -0700 1) my new file
8080
// (be3563a comes after 9fd738e8)
8181
var blame = repo.Blame("new.txt", new BlameOptions {StoppingAt = "be3563a"});
82-
Assert.True(blame[0].FinalCommit.Sha.StartsWith("be3563a"));
82+
Assert.StartsWith("be3563a", blame[0].FinalCommit.Sha);
8383
}
8484
}
8585
}

LibGit2Sharp.Tests/BlobFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public void CanTellIfTheBlobContentLooksLikeBinary()
216216
using (var repo = new Repository(path))
217217
{
218218
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
219-
Assert.Equal(false, blob.IsBinary);
219+
Assert.False(blob.IsBinary);
220220
}
221221
}
222222

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void CanCreateAnUnbornBranch()
7474
Commit c = repo.Commit("New initial root commit", Constants.Signature, Constants.Signature);
7575

7676
// Ensure this commit has no parent
77-
Assert.Equal(0, c.Parents.Count());
77+
Assert.Empty(c.Parents);
7878

7979
// The branch now exists...
8080
Branch orphan = repo.Branches["orphan"];
@@ -262,7 +262,7 @@ public void CreatingABranchTriggersTheCreationOfADirectReference()
262262

263263
Reference reference = repo.Refs[newBranch.CanonicalName];
264264
Assert.NotNull(reference);
265-
Assert.IsType(typeof(DirectReference), reference);
265+
Assert.IsType<DirectReference>(reference);
266266
}
267267
}
268268

@@ -563,7 +563,7 @@ public void CanGetInformationFromUnbornBranch()
563563
var head = repo.Head;
564564

565565
Assert.Equal("refs/heads/master", head.CanonicalName);
566-
Assert.Equal(0, head.Commits.Count());
566+
Assert.Empty(head.Commits);
567567
Assert.True(head.IsCurrentRepositoryHead);
568568
Assert.False(head.IsRemote);
569569
Assert.Equal("master", head.FriendlyName);
@@ -1123,7 +1123,7 @@ public void TrackedBranchExistsFromDefaultConfigInEmptyClone()
11231123
using (var repo = new Repository(clonedRepoPath))
11241124
{
11251125
Assert.Empty(Directory.GetFiles(scd2.RootedDirectoryPath));
1126-
Assert.Equal(repo.Head.FriendlyName, "master");
1126+
Assert.Equal("master", repo.Head.FriendlyName);
11271127

11281128
Assert.Null(repo.Head.Tip);
11291129
Assert.NotNull(repo.Head.TrackedBranch);

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -526,13 +526,13 @@ public void CheckoutRetainsUntrackedChanges()
526526
string fullPathFileB = Touch(repo.Info.WorkingDirectory, "b.txt", alternateFileContent);
527527

528528
// Verify that there is an untracked entry.
529-
Assert.Equal(1, repo.RetrieveStatus().Untracked.Count());
529+
Assert.Single(repo.RetrieveStatus().Untracked);
530530
Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(fullPathFileB));
531531

532532
Commands.Checkout(repo, otherBranchName);
533533

534534
// Verify untracked entry still exists.
535-
Assert.Equal(1, repo.RetrieveStatus().Untracked.Count());
535+
Assert.Single(repo.RetrieveStatus().Untracked);
536536
Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(fullPathFileB));
537537
}
538538
}
@@ -550,13 +550,13 @@ public void ForceCheckoutRetainsUntrackedChanges()
550550
string fullPathFileB = Touch(repo.Info.WorkingDirectory, "b.txt", alternateFileContent);
551551

552552
// Verify that there is an untracked entry.
553-
Assert.Equal(1, repo.RetrieveStatus().Untracked.Count());
553+
Assert.Single(repo.RetrieveStatus().Untracked);
554554
Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(fullPathFileB));
555555

556556
Commands.Checkout(repo, otherBranchName, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
557557

558558
// Verify untracked entry still exists.
559-
Assert.Equal(1, repo.RetrieveStatus().Untracked.Count());
559+
Assert.Single(repo.RetrieveStatus().Untracked);
560560
Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(fullPathFileB));
561561
}
562562
}
@@ -574,13 +574,13 @@ public void CheckoutRetainsUnstagedChanges()
574574
string fullPathFileA = Touch(repo.Info.WorkingDirectory, originalFilePath, alternateFileContent);
575575

576576
// Verify that there is a modified entry.
577-
Assert.Equal(1, repo.RetrieveStatus().Modified.Count());
577+
Assert.Single(repo.RetrieveStatus().Modified);
578578
Assert.Equal(FileStatus.ModifiedInWorkdir, repo.RetrieveStatus(fullPathFileA));
579579

580580
Commands.Checkout(repo, otherBranchName);
581581

582582
// Verify modified entry still exists.
583-
Assert.Equal(1, repo.RetrieveStatus().Modified.Count());
583+
Assert.Single(repo.RetrieveStatus().Modified);
584584
Assert.Equal(FileStatus.ModifiedInWorkdir, repo.RetrieveStatus(fullPathFileA));
585585
}
586586
}
@@ -599,13 +599,13 @@ public void CheckoutRetainsStagedChanges()
599599
Commands.Stage(repo, fullPathFileA);
600600

601601
// Verify that there is a staged entry.
602-
Assert.Equal(1, repo.RetrieveStatus().Staged.Count());
602+
Assert.Single(repo.RetrieveStatus().Staged);
603603
Assert.Equal(FileStatus.ModifiedInIndex, repo.RetrieveStatus(fullPathFileA));
604604

605605
Commands.Checkout(repo, otherBranchName);
606606

607607
// Verify staged entry still exists.
608-
Assert.Equal(1, repo.RetrieveStatus().Staged.Count());
608+
Assert.Single(repo.RetrieveStatus().Staged);
609609
Assert.Equal(FileStatus.ModifiedInIndex, repo.RetrieveStatus(fullPathFileA));
610610
}
611611
}
@@ -625,7 +625,7 @@ public void CheckoutRetainsIgnoredChanges()
625625
"bin/some_ignored_file.txt",
626626
"hello from this ignored file.");
627627

628-
Assert.Equal(1, repo.RetrieveStatus(new StatusOptions { IncludeIgnored = true }).Ignored.Count());
628+
Assert.Single(repo.RetrieveStatus(new StatusOptions { IncludeIgnored = true }).Ignored);
629629

630630
Assert.Equal(FileStatus.Ignored, repo.RetrieveStatus(ignoredFilePath));
631631

@@ -652,7 +652,7 @@ public void ForceCheckoutRetainsIgnoredChanges()
652652
"bin/some_ignored_file.txt",
653653
"hello from this ignored file.");
654654

655-
Assert.Equal(1, repo.RetrieveStatus(new StatusOptions { IncludeIgnored = true }).Ignored.Count());
655+
Assert.Single(repo.RetrieveStatus(new StatusOptions { IncludeIgnored = true }).Ignored);
656656

657657
Assert.Equal(FileStatus.Ignored, repo.RetrieveStatus(ignoredFilePath));
658658

@@ -958,7 +958,7 @@ public void CanCheckoutPath(string originalBranch, string checkoutFrom, string p
958958
repo.CheckoutPaths(checkoutFrom, new[] { path });
959959

960960
Assert.Equal(expectedStatus, repo.RetrieveStatus(path));
961-
Assert.Equal(1, repo.RetrieveStatus().Count());
961+
Assert.Single(repo.RetrieveStatus());
962962
}
963963
}
964964

@@ -995,8 +995,7 @@ public void CannotCheckoutPathsWithEmptyOrNullPathArgument()
995995
Assert.False(repo.RetrieveStatus().IsDirty);
996996

997997
// Passing null 'paths' parameter should throw
998-
Assert.Throws(typeof(ArgumentNullException),
999-
() => repo.CheckoutPaths("i-do-numbers", null));
998+
Assert.Throws<ArgumentNullException>(() => repo.CheckoutPaths("i-do-numbers", null));
1000999

10011000
// Passing empty list should do nothing
10021001
repo.CheckoutPaths("i-do-numbers", Enumerable.Empty<string>());

LibGit2Sharp.Tests/CherryPickFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void CherryPickWithConflictDoesNotCommit()
6666
Assert.Equal(CherryPickStatus.Conflicts, cherryPickResult.Status);
6767

6868
Assert.Null(cherryPickResult.Commit);
69-
Assert.Equal(1, repo.Index.Conflicts.Count());
69+
Assert.Single(repo.Index.Conflicts);
7070

7171
var conflict = repo.Index.Conflicts.First();
7272
var changes = repo.Diff.Compare(repo.Lookup<Blob>(conflict.Theirs.Id), repo.Lookup<Blob>(conflict.Ours.Id));
@@ -139,7 +139,7 @@ public void CanCherryPickCommit()
139139
var result = repo.ObjectDatabase.CherryPickCommit(commitToMerge, ours, 0, null);
140140

141141
Assert.Equal(MergeTreeStatus.Succeeded, result.Status);
142-
Assert.Equal(0, result.Conflicts.Count());
142+
Assert.Empty(result.Conflicts);
143143
}
144144
}
145145

LibGit2Sharp.Tests/CleanFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public void CanCleanWorkingDirectory()
1414
{
1515
// Verify that there are the expected number of entries and untracked files
1616
Assert.Equal(6, repo.RetrieveStatus().Count());
17-
Assert.Equal(1, repo.RetrieveStatus().Untracked.Count());
17+
Assert.Single(repo.RetrieveStatus().Untracked);
1818

1919
repo.RemoveUntrackedFiles();
2020

2121
// Verify that there are the expected number of entries and 0 untracked files
2222
Assert.Equal(5, repo.RetrieveStatus().Count());
23-
Assert.Equal(0, repo.RetrieveStatus().Untracked.Count());
23+
Assert.Empty(repo.RetrieveStatus().Untracked);
2424
}
2525
}
2626

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public void CanClone(string url)
3333
Assert.False(repo.Info.IsBare);
3434

3535
Assert.True(File.Exists(Path.Combine(scd.RootedDirectoryPath, "master.txt")));
36-
Assert.Equal(repo.Head.FriendlyName, "master");
37-
Assert.Equal(repo.Head.Tip.Id.ToString(), "49322bb17d3acc9146f98c97d078513228bbf3c0");
36+
Assert.Equal("master", repo.Head.FriendlyName);
37+
Assert.Equal("49322bb17d3acc9146f98c97d078513228bbf3c0", repo.Head.Tip.Id.ToString());
3838
}
3939
}
4040

@@ -74,7 +74,7 @@ private void AssertLocalClone(string url, string path = null, bool isCloningAnEm
7474
Assert.Equal(isCloningAnEmptyRepository ? 0 : 1, clonedRepo.Branches.Count(b => !b.IsRemote));
7575

7676
Assert.Equal(originalRepo.Tags.Count(), clonedRepo.Tags.Count());
77-
Assert.Equal(1, clonedRepo.Network.Remotes.Count());
77+
Assert.Single(clonedRepo.Network.Remotes);
7878
}
7979
}
8080

@@ -263,7 +263,7 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT
263263
Assert.True(valid);
264264
var x509 = ((CertificateX509)cert).Certificate;
265265
// we get a string with the different fields instead of a structure, so...
266-
Assert.True(x509.Subject.Contains("CN=github.com,"));
266+
Assert.Contains("CN=github.com,", x509.Subject);
267267
checksHappy = true;
268268
return false;
269269
}

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void CanEnumerateCommitsInDetachedHeadState()
7070
ObjectId parentOfHead = repo.Head.Tip.Parents.First().Id;
7171

7272
repo.Refs.Add("HEAD", parentOfHead.Sha, true);
73-
Assert.Equal(true, repo.Info.IsHeadDetached);
73+
Assert.True(repo.Info.IsHeadDetached);
7474

7575
Assert.Equal(6, repo.Commits.Count());
7676
}
@@ -156,7 +156,7 @@ public void CanEnumerateCommitsWithReverseTimeSorting()
156156
}))
157157
{
158158
Assert.NotNull(commit);
159-
Assert.True(commit.Sha.StartsWith(reversedShas[count]));
159+
Assert.StartsWith(reversedShas[count], commit.Sha);
160160
count++;
161161
}
162162
}
@@ -204,7 +204,7 @@ public void CanGetParentsCount()
204204
string path = SandboxBareTestRepo();
205205
using (var repo = new Repository(path))
206206
{
207-
Assert.Equal(1, repo.Commits.First().Parents.Count());
207+
Assert.Single(repo.Commits.First().Parents);
208208
}
209209
}
210210

@@ -222,7 +222,7 @@ public void CanEnumerateCommitsWithTimeSorting()
222222
}))
223223
{
224224
Assert.NotNull(commit);
225-
Assert.True(commit.Sha.StartsWith(expectedShas[count]));
225+
Assert.StartsWith(expectedShas[count], commit.Sha);
226226
count++;
227227
}
228228
}
@@ -484,7 +484,7 @@ public void CanReadCommitData()
484484

485485
Assert.Equal("181037049a54a1eb5fab404658a3a250b44335d7", commit.Tree.Sha);
486486

487-
Assert.Equal(0, commit.Parents.Count());
487+
Assert.Empty(commit.Parents);
488488
}
489489
}
490490

@@ -590,8 +590,8 @@ public void CommitParentsAreMergeHeads()
590590
Assert.Equal(CurrentOperation.None, repo.Info.CurrentOperation);
591591

592592
Assert.Equal(2, newMergedCommit.Parents.Count());
593-
Assert.Equal(newMergedCommit.Parents.First().Sha, "c47800c7266a2be04c571c04d5a6614691ea99bd");
594-
Assert.Equal(newMergedCommit.Parents.Skip(1).First().Sha, "9fd738e8f7967c078dceed8190330fc8648ee56a");
593+
Assert.Equal("c47800c7266a2be04c571c04d5a6614691ea99bd", newMergedCommit.Parents.First().Sha);
594+
Assert.Equal("9fd738e8f7967c078dceed8190330fc8648ee56a", newMergedCommit.Parents.Skip(1).First().Sha);
595595

596596
// Assert reflog entry is created
597597
var reflogEntry = repo.Refs.Log(repo.Refs.Head).First();
@@ -670,11 +670,11 @@ public void CanCommitALittleBit()
670670
AssertBlobContent(repo.Head[relativeFilepath], "nulltoken\n");
671671
AssertBlobContent(commit[relativeFilepath], "nulltoken\n");
672672

673-
Assert.Equal(0, commit.Parents.Count());
673+
Assert.Empty(commit.Parents);
674674
Assert.False(repo.Info.IsHeadUnborn);
675675

676676
// Assert a reflog entry is created on HEAD
677-
Assert.Equal(1, repo.Refs.Log("HEAD").Count());
677+
Assert.Single(repo.Refs.Log("HEAD"));
678678
var reflogEntry = repo.Refs.Log("HEAD").First();
679679

680680
Assert.Equal(identity.Name, reflogEntry.Committer.Name);
@@ -689,7 +689,7 @@ public void CanCommitALittleBit()
689689

690690
// Assert a reflog entry is created on HEAD target
691691
var targetCanonicalName = repo.Refs.Head.TargetIdentifier;
692-
Assert.Equal(1, repo.Refs.Log(targetCanonicalName).Count());
692+
Assert.Single(repo.Refs.Log(targetCanonicalName));
693693
Assert.Equal(commit.Id, repo.Refs.Log(targetCanonicalName).First().To);
694694

695695
File.WriteAllText(filePath, "nulltoken commits!\n");
@@ -701,7 +701,7 @@ public void CanCommitALittleBit()
701701
AssertBlobContent(repo.Head[relativeFilepath], "nulltoken commits!\n");
702702
AssertBlobContent(commit2[relativeFilepath], "nulltoken commits!\n");
703703

704-
Assert.Equal(1, commit2.Parents.Count());
704+
Assert.Single(commit2.Parents);
705705
Assert.Equal(commit.Id, commit2.Parents.First().Id);
706706

707707
// Assert the reflog is shifted
@@ -721,7 +721,7 @@ public void CanCommitALittleBit()
721721
AssertBlobContent(repo.Head[relativeFilepath], "davidfowl commits!\n");
722722
AssertBlobContent(commit3[relativeFilepath], "davidfowl commits!\n");
723723

724-
Assert.Equal(1, commit3.Parents.Count());
724+
Assert.Single(commit3.Parents);
725725
Assert.Equal(commit.Id, commit3.Parents.First().Id);
726726

727727
AssertBlobContent(firstCommitBranch[relativeFilepath], "nulltoken\n");
@@ -776,17 +776,17 @@ public void CanAmendARootCommit()
776776

777777
using (var repo = new Repository(repoPath))
778778
{
779-
Assert.Equal(1, repo.Head.Commits.Count());
779+
Assert.Single(repo.Head.Commits);
780780

781781
Commit originalCommit = repo.Head.Tip;
782-
Assert.Equal(0, originalCommit.Parents.Count());
782+
Assert.Empty(originalCommit.Parents);
783783

784784
CreateAndStageANewFile(repo);
785785

786786
Commit amendedCommit = repo.Commit("I'm rewriting the history!", Constants.Signature, Constants.Signature,
787787
new CommitOptions { AmendPreviousCommit = true });
788788

789-
Assert.Equal(1, repo.Head.Commits.Count());
789+
Assert.Single(repo.Head.Commits);
790790

791791
AssertCommitHasBeenAmended(repo, amendedCommit, originalCommit);
792792
}
@@ -918,7 +918,7 @@ public void CanCommitOnOrphanedBranch()
918918
Commands.Stage(repo, relativeFilepath);
919919

920920
repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
921-
Assert.Equal(1, repo.Head.Commits.Count());
921+
Assert.Single(repo.Head.Commits);
922922
}
923923
}
924924

@@ -1000,8 +1000,8 @@ public void CanCommitAnEmptyCommitWhenMerging()
10001000
Commit newMergedCommit = repo.Commit("Merge commit", Constants.Signature, Constants.Signature);
10011001

10021002
Assert.Equal(2, newMergedCommit.Parents.Count());
1003-
Assert.Equal(newMergedCommit.Parents.First().Sha, "32eab9cb1f450b5fe7ab663462b77d7f4b703344");
1004-
Assert.Equal(newMergedCommit.Parents.Skip(1).First().Sha, "f705abffe7015f2beacf2abe7a36583ebee3487e");
1003+
Assert.Equal("32eab9cb1f450b5fe7ab663462b77d7f4b703344", newMergedCommit.Parents.First().Sha);
1004+
Assert.Equal("f705abffe7015f2beacf2abe7a36583ebee3487e", newMergedCommit.Parents.Skip(1).First().Sha);
10051005
}
10061006
}
10071007

0 commit comments

Comments
 (0)
0