diff --git a/Directory.Build.props b/Directory.Build.props index c4e5543d3..fb2ca9ca9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,13 +1,10 @@ + true $(MSBuildThisFileDirectory)bin\$(MSBuildProjectName)\$(Configuration)\ $(MSBuildThisFileDirectory)obj\$(MSBuildProjectName)\ $(DefineConstants);$(ExtraDefine) - - - - diff --git a/Directory.Build.targets b/Directory.Build.targets index c1631f63d..080355c7d 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -2,13 +2,6 @@ true - $(TargetsForTfmSpecificContentInPackage);IncludePDBsInPackage - - - - - - diff --git a/LibGit2Sharp.Tests/BlameFixture.cs b/LibGit2Sharp.Tests/BlameFixture.cs index 9138646c3..da63dc124 100644 --- a/LibGit2Sharp.Tests/BlameFixture.cs +++ b/LibGit2Sharp.Tests/BlameFixture.cs @@ -9,7 +9,7 @@ public class BlameFixture : BaseFixture { private static void AssertCorrectHeadBlame(BlameHunkCollection blame) { - Assert.Equal(1, blame.Count()); + Assert.Single(blame); Assert.Equal(0, blame[0].FinalStartLineNumber); Assert.Equal("schacon@gmail.com", blame[0].FinalSignature.Email); Assert.Equal("4a202b3", blame[0].FinalCommit.Id.ToString(7)); @@ -39,7 +39,7 @@ public void CanBlameFromADifferentCommit() Assert.Throws(() => repo.Blame("ancestor-only.txt")); var blame = repo.Blame("ancestor-only.txt", new BlameOptions { StartingAt = "9107b30" }); - Assert.Equal(1, blame.Count()); + Assert.Single(blame); } } @@ -79,7 +79,7 @@ public void CanStopBlame() // 9fd738e8 (Scott Chacon 2010-05-24 10:19:19 -0700 1) my new file // (be3563a comes after 9fd738e8) var blame = repo.Blame("new.txt", new BlameOptions {StoppingAt = "be3563a"}); - Assert.True(blame[0].FinalCommit.Sha.StartsWith("be3563a")); + Assert.StartsWith("be3563a", blame[0].FinalCommit.Sha); } } } diff --git a/LibGit2Sharp.Tests/BlobFixture.cs b/LibGit2Sharp.Tests/BlobFixture.cs index 371e50c51..e6a5f3c57 100644 --- a/LibGit2Sharp.Tests/BlobFixture.cs +++ b/LibGit2Sharp.Tests/BlobFixture.cs @@ -216,7 +216,7 @@ public void CanTellIfTheBlobContentLooksLikeBinary() using (var repo = new Repository(path)) { var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6"); - Assert.Equal(false, blob.IsBinary); + Assert.False(blob.IsBinary); } } diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs index e06e81784..d8a47edfb 100644 --- a/LibGit2Sharp.Tests/BranchFixture.cs +++ b/LibGit2Sharp.Tests/BranchFixture.cs @@ -74,7 +74,7 @@ public void CanCreateAnUnbornBranch() Commit c = repo.Commit("New initial root commit", Constants.Signature, Constants.Signature); // Ensure this commit has no parent - Assert.Equal(0, c.Parents.Count()); + Assert.Empty(c.Parents); // The branch now exists... Branch orphan = repo.Branches["orphan"]; @@ -262,7 +262,7 @@ public void CreatingABranchTriggersTheCreationOfADirectReference() Reference reference = repo.Refs[newBranch.CanonicalName]; Assert.NotNull(reference); - Assert.IsType(typeof(DirectReference), reference); + Assert.IsType(reference); } } @@ -563,7 +563,7 @@ public void CanGetInformationFromUnbornBranch() var head = repo.Head; Assert.Equal("refs/heads/master", head.CanonicalName); - Assert.Equal(0, head.Commits.Count()); + Assert.Empty(head.Commits); Assert.True(head.IsCurrentRepositoryHead); Assert.False(head.IsRemote); Assert.Equal("master", head.FriendlyName); @@ -1123,7 +1123,7 @@ public void TrackedBranchExistsFromDefaultConfigInEmptyClone() using (var repo = new Repository(clonedRepoPath)) { Assert.Empty(Directory.GetFiles(scd2.RootedDirectoryPath)); - Assert.Equal(repo.Head.FriendlyName, "master"); + Assert.Equal("master", repo.Head.FriendlyName); Assert.Null(repo.Head.Tip); Assert.NotNull(repo.Head.TrackedBranch); diff --git a/LibGit2Sharp.Tests/CheckoutFixture.cs b/LibGit2Sharp.Tests/CheckoutFixture.cs index 8510b3d81..f0c2c36ed 100644 --- a/LibGit2Sharp.Tests/CheckoutFixture.cs +++ b/LibGit2Sharp.Tests/CheckoutFixture.cs @@ -526,13 +526,13 @@ public void CheckoutRetainsUntrackedChanges() string fullPathFileB = Touch(repo.Info.WorkingDirectory, "b.txt", alternateFileContent); // Verify that there is an untracked entry. - Assert.Equal(1, repo.RetrieveStatus().Untracked.Count()); + Assert.Single(repo.RetrieveStatus().Untracked); Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(fullPathFileB)); Commands.Checkout(repo, otherBranchName); // Verify untracked entry still exists. - Assert.Equal(1, repo.RetrieveStatus().Untracked.Count()); + Assert.Single(repo.RetrieveStatus().Untracked); Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(fullPathFileB)); } } @@ -550,13 +550,13 @@ public void ForceCheckoutRetainsUntrackedChanges() string fullPathFileB = Touch(repo.Info.WorkingDirectory, "b.txt", alternateFileContent); // Verify that there is an untracked entry. - Assert.Equal(1, repo.RetrieveStatus().Untracked.Count()); + Assert.Single(repo.RetrieveStatus().Untracked); Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(fullPathFileB)); Commands.Checkout(repo, otherBranchName, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force }); // Verify untracked entry still exists. - Assert.Equal(1, repo.RetrieveStatus().Untracked.Count()); + Assert.Single(repo.RetrieveStatus().Untracked); Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(fullPathFileB)); } } @@ -574,13 +574,13 @@ public void CheckoutRetainsUnstagedChanges() string fullPathFileA = Touch(repo.Info.WorkingDirectory, originalFilePath, alternateFileContent); // Verify that there is a modified entry. - Assert.Equal(1, repo.RetrieveStatus().Modified.Count()); + Assert.Single(repo.RetrieveStatus().Modified); Assert.Equal(FileStatus.ModifiedInWorkdir, repo.RetrieveStatus(fullPathFileA)); Commands.Checkout(repo, otherBranchName); // Verify modified entry still exists. - Assert.Equal(1, repo.RetrieveStatus().Modified.Count()); + Assert.Single(repo.RetrieveStatus().Modified); Assert.Equal(FileStatus.ModifiedInWorkdir, repo.RetrieveStatus(fullPathFileA)); } } @@ -599,13 +599,13 @@ public void CheckoutRetainsStagedChanges() Commands.Stage(repo, fullPathFileA); // Verify that there is a staged entry. - Assert.Equal(1, repo.RetrieveStatus().Staged.Count()); + Assert.Single(repo.RetrieveStatus().Staged); Assert.Equal(FileStatus.ModifiedInIndex, repo.RetrieveStatus(fullPathFileA)); Commands.Checkout(repo, otherBranchName); // Verify staged entry still exists. - Assert.Equal(1, repo.RetrieveStatus().Staged.Count()); + Assert.Single(repo.RetrieveStatus().Staged); Assert.Equal(FileStatus.ModifiedInIndex, repo.RetrieveStatus(fullPathFileA)); } } @@ -625,7 +625,7 @@ public void CheckoutRetainsIgnoredChanges() "bin/some_ignored_file.txt", "hello from this ignored file."); - Assert.Equal(1, repo.RetrieveStatus(new StatusOptions { IncludeIgnored = true }).Ignored.Count()); + Assert.Single(repo.RetrieveStatus(new StatusOptions { IncludeIgnored = true }).Ignored); Assert.Equal(FileStatus.Ignored, repo.RetrieveStatus(ignoredFilePath)); @@ -652,7 +652,7 @@ public void ForceCheckoutRetainsIgnoredChanges() "bin/some_ignored_file.txt", "hello from this ignored file."); - Assert.Equal(1, repo.RetrieveStatus(new StatusOptions { IncludeIgnored = true }).Ignored.Count()); + Assert.Single(repo.RetrieveStatus(new StatusOptions { IncludeIgnored = true }).Ignored); Assert.Equal(FileStatus.Ignored, repo.RetrieveStatus(ignoredFilePath)); @@ -958,7 +958,7 @@ public void CanCheckoutPath(string originalBranch, string checkoutFrom, string p repo.CheckoutPaths(checkoutFrom, new[] { path }); Assert.Equal(expectedStatus, repo.RetrieveStatus(path)); - Assert.Equal(1, repo.RetrieveStatus().Count()); + Assert.Single(repo.RetrieveStatus()); } } @@ -995,8 +995,7 @@ public void CannotCheckoutPathsWithEmptyOrNullPathArgument() Assert.False(repo.RetrieveStatus().IsDirty); // Passing null 'paths' parameter should throw - Assert.Throws(typeof(ArgumentNullException), - () => repo.CheckoutPaths("i-do-numbers", null)); + Assert.Throws(() => repo.CheckoutPaths("i-do-numbers", null)); // Passing empty list should do nothing repo.CheckoutPaths("i-do-numbers", Enumerable.Empty()); diff --git a/LibGit2Sharp.Tests/CherryPickFixture.cs b/LibGit2Sharp.Tests/CherryPickFixture.cs index 1bbff1428..3c0026df5 100644 --- a/LibGit2Sharp.Tests/CherryPickFixture.cs +++ b/LibGit2Sharp.Tests/CherryPickFixture.cs @@ -66,7 +66,7 @@ public void CherryPickWithConflictDoesNotCommit() Assert.Equal(CherryPickStatus.Conflicts, cherryPickResult.Status); Assert.Null(cherryPickResult.Commit); - Assert.Equal(1, repo.Index.Conflicts.Count()); + Assert.Single(repo.Index.Conflicts); var conflict = repo.Index.Conflicts.First(); var changes = repo.Diff.Compare(repo.Lookup(conflict.Theirs.Id), repo.Lookup(conflict.Ours.Id)); @@ -139,7 +139,7 @@ public void CanCherryPickCommit() var result = repo.ObjectDatabase.CherryPickCommit(commitToMerge, ours, 0, null); Assert.Equal(MergeTreeStatus.Succeeded, result.Status); - Assert.Equal(0, result.Conflicts.Count()); + Assert.Empty(result.Conflicts); } } diff --git a/LibGit2Sharp.Tests/CleanFixture.cs b/LibGit2Sharp.Tests/CleanFixture.cs index f674285c6..39c7a6152 100644 --- a/LibGit2Sharp.Tests/CleanFixture.cs +++ b/LibGit2Sharp.Tests/CleanFixture.cs @@ -14,13 +14,13 @@ public void CanCleanWorkingDirectory() { // Verify that there are the expected number of entries and untracked files Assert.Equal(6, repo.RetrieveStatus().Count()); - Assert.Equal(1, repo.RetrieveStatus().Untracked.Count()); + Assert.Single(repo.RetrieveStatus().Untracked); repo.RemoveUntrackedFiles(); // Verify that there are the expected number of entries and 0 untracked files Assert.Equal(5, repo.RetrieveStatus().Count()); - Assert.Equal(0, repo.RetrieveStatus().Untracked.Count()); + Assert.Empty(repo.RetrieveStatus().Untracked); } } diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs index 84fa5f312..00dc9fee6 100644 --- a/LibGit2Sharp.Tests/CloneFixture.cs +++ b/LibGit2Sharp.Tests/CloneFixture.cs @@ -33,8 +33,8 @@ public void CanClone(string url) Assert.False(repo.Info.IsBare); Assert.True(File.Exists(Path.Combine(scd.RootedDirectoryPath, "master.txt"))); - Assert.Equal(repo.Head.FriendlyName, "master"); - Assert.Equal(repo.Head.Tip.Id.ToString(), "49322bb17d3acc9146f98c97d078513228bbf3c0"); + Assert.Equal("master", repo.Head.FriendlyName); + Assert.Equal("49322bb17d3acc9146f98c97d078513228bbf3c0", repo.Head.Tip.Id.ToString()); } } @@ -74,7 +74,7 @@ private void AssertLocalClone(string url, string path = null, bool isCloningAnEm Assert.Equal(isCloningAnEmptyRepository ? 0 : 1, clonedRepo.Branches.Count(b => !b.IsRemote)); Assert.Equal(originalRepo.Tags.Count(), clonedRepo.Tags.Count()); - Assert.Equal(1, clonedRepo.Network.Remotes.Count()); + Assert.Single(clonedRepo.Network.Remotes); } } @@ -263,7 +263,7 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT Assert.True(valid); var x509 = ((CertificateX509)cert).Certificate; // we get a string with the different fields instead of a structure, so... - Assert.True(x509.Subject.Contains("CN=github.com,")); + Assert.Contains("CN=github.com,", x509.Subject); checksHappy = true; return false; } diff --git a/LibGit2Sharp.Tests/CommitFixture.cs b/LibGit2Sharp.Tests/CommitFixture.cs index b522e3c34..179a4975c 100644 --- a/LibGit2Sharp.Tests/CommitFixture.cs +++ b/LibGit2Sharp.Tests/CommitFixture.cs @@ -70,7 +70,7 @@ public void CanEnumerateCommitsInDetachedHeadState() ObjectId parentOfHead = repo.Head.Tip.Parents.First().Id; repo.Refs.Add("HEAD", parentOfHead.Sha, true); - Assert.Equal(true, repo.Info.IsHeadDetached); + Assert.True(repo.Info.IsHeadDetached); Assert.Equal(6, repo.Commits.Count()); } @@ -156,7 +156,7 @@ public void CanEnumerateCommitsWithReverseTimeSorting() })) { Assert.NotNull(commit); - Assert.True(commit.Sha.StartsWith(reversedShas[count])); + Assert.StartsWith(reversedShas[count], commit.Sha); count++; } } @@ -204,7 +204,7 @@ public void CanGetParentsCount() string path = SandboxBareTestRepo(); using (var repo = new Repository(path)) { - Assert.Equal(1, repo.Commits.First().Parents.Count()); + Assert.Single(repo.Commits.First().Parents); } } @@ -222,7 +222,7 @@ public void CanEnumerateCommitsWithTimeSorting() })) { Assert.NotNull(commit); - Assert.True(commit.Sha.StartsWith(expectedShas[count])); + Assert.StartsWith(expectedShas[count], commit.Sha); count++; } } @@ -484,7 +484,7 @@ public void CanReadCommitData() Assert.Equal("181037049a54a1eb5fab404658a3a250b44335d7", commit.Tree.Sha); - Assert.Equal(0, commit.Parents.Count()); + Assert.Empty(commit.Parents); } } @@ -590,8 +590,8 @@ public void CommitParentsAreMergeHeads() Assert.Equal(CurrentOperation.None, repo.Info.CurrentOperation); Assert.Equal(2, newMergedCommit.Parents.Count()); - Assert.Equal(newMergedCommit.Parents.First().Sha, "c47800c7266a2be04c571c04d5a6614691ea99bd"); - Assert.Equal(newMergedCommit.Parents.Skip(1).First().Sha, "9fd738e8f7967c078dceed8190330fc8648ee56a"); + Assert.Equal("c47800c7266a2be04c571c04d5a6614691ea99bd", newMergedCommit.Parents.First().Sha); + Assert.Equal("9fd738e8f7967c078dceed8190330fc8648ee56a", newMergedCommit.Parents.Skip(1).First().Sha); // Assert reflog entry is created var reflogEntry = repo.Refs.Log(repo.Refs.Head).First(); @@ -670,11 +670,11 @@ public void CanCommitALittleBit() AssertBlobContent(repo.Head[relativeFilepath], "nulltoken\n"); AssertBlobContent(commit[relativeFilepath], "nulltoken\n"); - Assert.Equal(0, commit.Parents.Count()); + Assert.Empty(commit.Parents); Assert.False(repo.Info.IsHeadUnborn); // Assert a reflog entry is created on HEAD - Assert.Equal(1, repo.Refs.Log("HEAD").Count()); + Assert.Single(repo.Refs.Log("HEAD")); var reflogEntry = repo.Refs.Log("HEAD").First(); Assert.Equal(identity.Name, reflogEntry.Committer.Name); @@ -689,7 +689,7 @@ public void CanCommitALittleBit() // Assert a reflog entry is created on HEAD target var targetCanonicalName = repo.Refs.Head.TargetIdentifier; - Assert.Equal(1, repo.Refs.Log(targetCanonicalName).Count()); + Assert.Single(repo.Refs.Log(targetCanonicalName)); Assert.Equal(commit.Id, repo.Refs.Log(targetCanonicalName).First().To); File.WriteAllText(filePath, "nulltoken commits!\n"); @@ -701,7 +701,7 @@ public void CanCommitALittleBit() AssertBlobContent(repo.Head[relativeFilepath], "nulltoken commits!\n"); AssertBlobContent(commit2[relativeFilepath], "nulltoken commits!\n"); - Assert.Equal(1, commit2.Parents.Count()); + Assert.Single(commit2.Parents); Assert.Equal(commit.Id, commit2.Parents.First().Id); // Assert the reflog is shifted @@ -721,7 +721,7 @@ public void CanCommitALittleBit() AssertBlobContent(repo.Head[relativeFilepath], "davidfowl commits!\n"); AssertBlobContent(commit3[relativeFilepath], "davidfowl commits!\n"); - Assert.Equal(1, commit3.Parents.Count()); + Assert.Single(commit3.Parents); Assert.Equal(commit.Id, commit3.Parents.First().Id); AssertBlobContent(firstCommitBranch[relativeFilepath], "nulltoken\n"); @@ -776,17 +776,17 @@ public void CanAmendARootCommit() using (var repo = new Repository(repoPath)) { - Assert.Equal(1, repo.Head.Commits.Count()); + Assert.Single(repo.Head.Commits); Commit originalCommit = repo.Head.Tip; - Assert.Equal(0, originalCommit.Parents.Count()); + Assert.Empty(originalCommit.Parents); CreateAndStageANewFile(repo); Commit amendedCommit = repo.Commit("I'm rewriting the history!", Constants.Signature, Constants.Signature, new CommitOptions { AmendPreviousCommit = true }); - Assert.Equal(1, repo.Head.Commits.Count()); + Assert.Single(repo.Head.Commits); AssertCommitHasBeenAmended(repo, amendedCommit, originalCommit); } @@ -918,7 +918,7 @@ public void CanCommitOnOrphanedBranch() Commands.Stage(repo, relativeFilepath); repo.Commit("Initial commit", Constants.Signature, Constants.Signature); - Assert.Equal(1, repo.Head.Commits.Count()); + Assert.Single(repo.Head.Commits); } } @@ -1000,8 +1000,8 @@ public void CanCommitAnEmptyCommitWhenMerging() Commit newMergedCommit = repo.Commit("Merge commit", Constants.Signature, Constants.Signature); Assert.Equal(2, newMergedCommit.Parents.Count()); - Assert.Equal(newMergedCommit.Parents.First().Sha, "32eab9cb1f450b5fe7ab663462b77d7f4b703344"); - Assert.Equal(newMergedCommit.Parents.Skip(1).First().Sha, "f705abffe7015f2beacf2abe7a36583ebee3487e"); + Assert.Equal("32eab9cb1f450b5fe7ab663462b77d7f4b703344", newMergedCommit.Parents.First().Sha); + Assert.Equal("f705abffe7015f2beacf2abe7a36583ebee3487e", newMergedCommit.Parents.Skip(1).First().Sha); } } diff --git a/LibGit2Sharp.Tests/ConfigurationFixture.cs b/LibGit2Sharp.Tests/ConfigurationFixture.cs index 3e071c3b7..5bb985b68 100644 --- a/LibGit2Sharp.Tests/ConfigurationFixture.cs +++ b/LibGit2Sharp.Tests/ConfigurationFixture.cs @@ -59,9 +59,9 @@ public void CanReadBooleanValue() Assert.True(repo.Config.Get("core.ignorecase").Value); Assert.True(repo.Config.GetValueOrDefault("core.ignorecase")); - Assert.Equal(false, repo.Config.GetValueOrDefault("missing.key")); - Assert.Equal(true, repo.Config.GetValueOrDefault("missing.key", true)); - Assert.Equal(true, repo.Config.GetValueOrDefault("missing.key", () => true)); + Assert.False(repo.Config.GetValueOrDefault("missing.key")); + Assert.True(repo.Config.GetValueOrDefault("missing.key", true)); + Assert.True(repo.Config.GetValueOrDefault("missing.key", () => true)); } } @@ -110,26 +110,26 @@ public void CanReadStringValue() Assert.Equal("+refs/heads/*:refs/remotes/origin/*", repo.Config.GetValueOrDefault("remote", "origin", "fetch")); Assert.Equal("+refs/heads/*:refs/remotes/origin/*", repo.Config.GetValueOrDefault(new[] { "remote", "origin", "fetch" })); - Assert.Equal(null, repo.Config.GetValueOrDefault("missing.key")); - Assert.Equal(null, repo.Config.GetValueOrDefault("missing.key", default(string))); + Assert.Null(repo.Config.GetValueOrDefault("missing.key")); + Assert.Null(repo.Config.GetValueOrDefault("missing.key", default(string))); Assert.Throws(() => repo.Config.GetValueOrDefault("missing.key", default(Func))); Assert.Equal("value", repo.Config.GetValueOrDefault("missing.key", "value")); Assert.Equal("value", repo.Config.GetValueOrDefault("missing.key", () => "value")); - Assert.Equal(null, repo.Config.GetValueOrDefault("missing.key", ConfigurationLevel.Local)); - Assert.Equal(null, repo.Config.GetValueOrDefault("missing.key", ConfigurationLevel.Local, default(string))); + Assert.Null(repo.Config.GetValueOrDefault("missing.key", ConfigurationLevel.Local)); + Assert.Null(repo.Config.GetValueOrDefault("missing.key", ConfigurationLevel.Local, default(string))); Assert.Throws(() => repo.Config.GetValueOrDefault("missing.key", ConfigurationLevel.Local, default(Func))); Assert.Equal("value", repo.Config.GetValueOrDefault("missing.key", ConfigurationLevel.Local, "value")); Assert.Equal("value", repo.Config.GetValueOrDefault("missing.key", ConfigurationLevel.Local, () => "value")); - Assert.Equal(null, repo.Config.GetValueOrDefault("missing", "config", "key")); - Assert.Equal(null, repo.Config.GetValueOrDefault("missing", "config", "key", default(string))); + Assert.Null(repo.Config.GetValueOrDefault("missing", "config", "key")); + Assert.Null(repo.Config.GetValueOrDefault("missing", "config", "key", default(string))); Assert.Throws(() => repo.Config.GetValueOrDefault("missing", "config", "key", default(Func))); Assert.Equal("value", repo.Config.GetValueOrDefault("missing", "config", "key", "value")); Assert.Equal("value", repo.Config.GetValueOrDefault("missing", "config", "key", () => "value")); - Assert.Equal(null, repo.Config.GetValueOrDefault(new[] { "missing", "key" })); - Assert.Equal(null, repo.Config.GetValueOrDefault(new[] { "missing", "key" }, default(string))); + Assert.Null(repo.Config.GetValueOrDefault(new[] { "missing", "key" })); + Assert.Null(repo.Config.GetValueOrDefault(new[] { "missing", "key" }, default(string))); Assert.Throws(() => repo.Config.GetValueOrDefault(new[] { "missing", "key" }, default(Func))); Assert.Equal("value", repo.Config.GetValueOrDefault(new[] { "missing", "key" }, "value")); Assert.Equal("value", repo.Config.GetValueOrDefault(new[] { "missing", "key" }, () => "value")); diff --git a/LibGit2Sharp.Tests/ConflictFixture.cs b/LibGit2Sharp.Tests/ConflictFixture.cs index cabf4a4cf..b28270b7e 100644 --- a/LibGit2Sharp.Tests/ConflictFixture.cs +++ b/LibGit2Sharp.Tests/ConflictFixture.cs @@ -75,7 +75,7 @@ public void CanResolveConflictsByRemovingFromTheIndex( Assert.Equal(existsBeforeRemove, File.Exists(fullpath)); Assert.NotNull(repo.Index.Conflicts[filename]); - Assert.Equal(0, repo.Index.Conflicts.ResolvedConflicts.Count()); + Assert.Empty(repo.Index.Conflicts.ResolvedConflicts); Commands.Remove(repo, filename, removeFromWorkdir); @@ -84,7 +84,7 @@ public void CanResolveConflictsByRemovingFromTheIndex( Assert.Equal(existsAfterRemove, File.Exists(fullpath)); Assert.Equal(lastStatus, repo.RetrieveStatus(filename)); - Assert.Equal(1, repo.Index.Conflicts.ResolvedConflicts.Count()); + Assert.Single(repo.Index.Conflicts.ResolvedConflicts); Assert.NotNull(repo.Index.Conflicts.ResolvedConflicts[filename]); } } diff --git a/LibGit2Sharp.Tests/DiffTreeToTargetFixture.cs b/LibGit2Sharp.Tests/DiffTreeToTargetFixture.cs index 71aad3755..2fb359f24 100644 --- a/LibGit2Sharp.Tests/DiffTreeToTargetFixture.cs +++ b/LibGit2Sharp.Tests/DiffTreeToTargetFixture.cs @@ -46,7 +46,7 @@ public void CanCompareASimpleTreeAgainstTheWorkDir() using (var changes = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.WorkingDirectory)) { - Assert.Equal(1, changes.Modified.Count()); + Assert.Single(changes.Modified); } using (var patch = repo.Diff.Compare(repo.Head.Tip.Tree, @@ -116,7 +116,7 @@ public void CanCompareASimpleTreeAgainstTheWorkDirAndTheIndex() using (var changes = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.Index | DiffTargets.WorkingDirectory)) { - Assert.Equal(1, changes.Modified.Count()); + Assert.Single(changes.Modified); } using (var patch = repo.Diff.Compare(repo.Head.Tip.Tree, @@ -178,8 +178,8 @@ public void ShowcaseTheDifferenceBetweenTheTwoKindOfComparison() using (var wrkDirToIdxToTree = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.Index | DiffTargets.WorkingDirectory)) { - Assert.Equal(1, wrkDirToIdxToTree.Deleted.Count()); - Assert.Equal(0, wrkDirToIdxToTree.Modified.Count()); + Assert.Single(wrkDirToIdxToTree.Deleted); + Assert.Empty(wrkDirToIdxToTree.Modified); } using (var patch = repo.Diff.Compare(repo.Head.Tip.Tree, @@ -200,8 +200,8 @@ public void ShowcaseTheDifferenceBetweenTheTwoKindOfComparison() using (var wrkDirToTree = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.WorkingDirectory)) { - Assert.Equal(0, wrkDirToTree.Deleted.Count()); - Assert.Equal(1, wrkDirToTree.Modified.Count()); + Assert.Empty(wrkDirToTree.Deleted); + Assert.Single(wrkDirToTree.Modified); } using (var patch = repo.Diff.Compare(repo.Head.Tip.Tree, @@ -244,7 +244,7 @@ public void CanCompareASimpleTreeAgainstTheIndex() using (var changes = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.Index)) { - Assert.Equal(1, changes.Modified.Count()); + Assert.Single(changes.Modified); } using (var patch = repo.Diff.Compare(repo.Head.Tip.Tree, @@ -331,7 +331,7 @@ public void CanCompareASubsetofTheTreeAgainstTheIndex() { Assert.NotNull(changes); - Assert.Equal(1, changes.Count()); + Assert.Single(changes); Assert.Equal("deleted_staged_file.txt", changes.Deleted.Single().Path); } } @@ -340,7 +340,7 @@ public void CanCompareASubsetofTheTreeAgainstTheIndex() private static void AssertCanCompareASubsetOfTheTreeAgainstTheIndex(TreeChanges changes) { Assert.NotNull(changes); - Assert.Equal(1, changes.Count()); + Assert.Single(changes); Assert.Equal("deleted_staged_file.txt", changes.Deleted.Single().Path); } @@ -413,7 +413,7 @@ public void CanCopeWithEndOfFileNewlineChanges() using (var changes = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.Index)) { - Assert.Equal(1, changes.Modified.Count()); + Assert.Single(changes.Modified); } using (var patch = repo.Diff.Compare(repo.Head.Tip.Tree, DiffTargets.Index)) @@ -462,8 +462,8 @@ public void CanCompareANullTreeAgainstTheIndex() using (var changes = repo.Diff.Compare(null, DiffTargets.Index)) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Added.Count()); + Assert.Single(changes); + Assert.Single(changes.Added); Assert.Equal("file.txt", changes.Added.Single().Path); } @@ -482,8 +482,8 @@ public void CanCompareANullTreeAgainstTheWorkdir() using (var changes = repo.Diff.Compare(null, DiffTargets.WorkingDirectory)) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Added.Count()); + Assert.Single(changes); + Assert.Single(changes.Added); Assert.Equal("file.txt", changes.Added.Single().Path); } @@ -502,8 +502,8 @@ public void CanCompareANullTreeAgainstTheWorkdirAndTheIndex() using (var changes = repo.Diff.Compare(null, DiffTargets.WorkingDirectory | DiffTargets.Index)) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Added.Count()); + Assert.Single(changes); + Assert.Single(changes.Added); Assert.Equal("file.txt", changes.Added.Single().Path); } diff --git a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs index e1e6359e1..dba762bfe 100644 --- a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs +++ b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs @@ -64,8 +64,8 @@ public void CanCompareACommitTreeAgainstItsParent() using (var changes = repo.Diff.Compare(parentCommitTree, commitTree)) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Added.Count()); + Assert.Single(changes); + Assert.Single(changes.Added); TreeEntryChanges treeEntryChanges = changes.Single(c => c.Path == "1.txt"); @@ -172,7 +172,7 @@ public void CanCompareASubsetofTheTreeAgainstOneOfItsAncestor() { Assert.NotNull(changes); - Assert.Equal(1, changes.Count()); + Assert.Single(changes); Assert.Equal(subBranchFilePath, changes.Added.Single().Path); } } @@ -205,7 +205,7 @@ public void CanCompareACommitTreeAgainstATreeWithNoCommonAncestor() { Assert.Equal(10, changes.Count()); Assert.Equal(9, changes.Added.Count()); - Assert.Equal(1, changes.Deleted.Count()); + Assert.Single(changes.Deleted); Assert.Equal("readme.txt", changes.Deleted.Single().Path); Assert.Equal(new[] { "1.txt", subBranchFilePath, "README", "branch_file.txt", "deleted_staged_file.txt", "deleted_unstaged_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new.txt" }, @@ -233,13 +233,13 @@ public void CanCompareATreeAgainstAnotherTreeWithLaxExplicitPathsValidationAndNo using (var changes = repo.Diff.Compare(commitTreeWithDifferentAncestor, commitTree, new[] { "if-I-exist-this-test-is-really-unlucky.txt" }, new ExplicitPathsOptions { ShouldFailOnUnmatchedPath = false })) { - Assert.Equal(0, changes.Count()); + Assert.Empty(changes); } using (var changes = repo.Diff.Compare(commitTreeWithDifferentAncestor, commitTree, new[] { "if-I-exist-this-test-is-really-unlucky.txt" })) { - Assert.Equal(0, changes.Count()); + Assert.Empty(changes); } } } @@ -288,9 +288,9 @@ public void DetectsTheRenamingOfAModifiedFileByDefault() using (var changes = repo.Diff.Compare(rootCommitTree, commitTreeWithRenamedFile)) { - Assert.Equal(1, changes.Count()); + Assert.Single(changes); Assert.Equal("my-name-does-not-feel-right.txt", changes.Single(c => c.Path == "super-file.txt").OldPath); - Assert.Equal(1, changes.Renamed.Count()); + Assert.Single(changes.Renamed); } } } @@ -317,8 +317,8 @@ public void DetectsTheExactRenamingOfFilesByDefault() using (var changes = repo.Diff.Compare(old.Tree, @new.Tree)) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Renamed.Count()); + Assert.Single(changes); + Assert.Single(changes.Renamed); Assert.Equal(originalPath, changes.Renamed.Single().OldPath); Assert.Equal(renamedPath, changes.Renamed.Single().Path); } @@ -370,7 +370,7 @@ public void RenameThresholdsAreObeyed() compareOptions.Similarity.RenameThreshold = 90; using (var changes = repo.Diff.Compare(old.Tree, @new.Tree, compareOptions: compareOptions)) - Assert.False(changes.Any(x => x.Status == ChangeKind.Renamed)); + Assert.DoesNotContain(changes, x => x.Status == ChangeKind.Renamed); } } @@ -400,8 +400,8 @@ public void ExactModeDetectsExactRenames() Similarity = SimilarityOptions.Exact, })) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Renamed.Count()); + Assert.Single(changes); + Assert.Single(changes.Renamed); Assert.Equal(originalPath, changes.Renamed.Single().OldPath); Assert.Equal(renamedPath, changes.Renamed.Single().Path); } @@ -435,8 +435,8 @@ public void ExactModeDetectsExactCopies() Similarity = SimilarityOptions.Exact, })) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Copied.Count()); + Assert.Single(changes); + Assert.Single(changes.Copied); } } } @@ -470,9 +470,9 @@ public void ExactModeDoesntDetectRenamesWithEdits() })) { Assert.Equal(2, changes.Count()); - Assert.Equal(0, changes.Renamed.Count()); - Assert.Equal(1, changes.Added.Count()); - Assert.Equal(1, changes.Deleted.Count()); + Assert.Empty(changes.Renamed); + Assert.Single(changes.Added); + Assert.Single(changes.Deleted); } } } @@ -509,8 +509,8 @@ public void CanIncludeUnmodifiedEntriesWhenDetectingTheExactRenamingOfFilesWhenE })) { Assert.Equal(2, changes.Count()); - Assert.Equal(1, changes.Unmodified.Count()); - Assert.Equal(1, changes.Copied.Count()); + Assert.Single(changes.Unmodified); + Assert.Single(changes.Copied); Assert.Equal(originalPath, changes.Copied.Single().OldPath); Assert.Equal(copiedPath, changes.Copied.Single().Path); } @@ -545,7 +545,7 @@ public void CanNotDetectTheExactRenamingFilesWhenNotEnabled() })) { Assert.Equal(2, changes.Count()); - Assert.Equal(0, changes.Renamed.Count()); + Assert.Empty(changes.Renamed); } } } @@ -580,8 +580,8 @@ public void CanDetectTheExactCopyingOfNonModifiedFilesWhenEnabled() Similarity = SimilarityOptions.CopiesHarder, })) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Copied.Count()); + Assert.Single(changes); + Assert.Single(changes.Copied); Assert.Equal(originalPath, changes.Copied.Single().OldPath); Assert.Equal(copiedPath, changes.Copied.Single().Path); } @@ -613,8 +613,8 @@ public void CanNotDetectTheExactCopyingOfNonModifiedFilesWhenNotEnabled() using (var changes = repo.Diff.Compare(old.Tree, @new.Tree)) { - Assert.Equal(1, changes.Count()); - Assert.Equal(0, changes.Copied.Count()); + Assert.Single(changes); + Assert.Empty(changes.Copied); } } } @@ -653,7 +653,7 @@ public void CanDetectTheExactCopyingOfModifiedFilesWhenEnabled() })) { Assert.Equal(2, changes.Count()); - Assert.Equal(1, changes.Copied.Count()); + Assert.Single(changes.Copied); Assert.Equal(originalPath, changes.Copied.Single().OldPath); Assert.Equal(copiedPath, changes.Copied.Single().Path); } @@ -689,7 +689,7 @@ public void CanNotDetectTheExactCopyingOfModifiedFilesWhenNotEnabled() using (var changes = repo.Diff.Compare(old.Tree, @new.Tree)) { Assert.Equal(2, changes.Count()); - Assert.Equal(0, changes.Copied.Count()); + Assert.Empty(changes.Copied); } } } @@ -715,8 +715,8 @@ public void CanIncludeUnmodifiedEntriesWhenEnabled() compareOptions: new CompareOptions { IncludeUnmodified = true })) { Assert.Equal(2, changes.Count()); - Assert.Equal(1, changes.Unmodified.Count()); - Assert.Equal(1, changes.Modified.Count()); + Assert.Single(changes.Unmodified); + Assert.Single(changes.Modified); } } } @@ -768,8 +768,8 @@ public void CanDetectTheExactRenamingExactCopyingOfNonModifiedAndModifiedFilesWh })) { Assert.Equal(4, changes.Count()); - Assert.Equal(1, changes.Modified.Count()); - Assert.Equal(1, changes.Renamed.Count()); + Assert.Single(changes.Modified); + Assert.Single(changes.Renamed); Assert.Equal(originalPath, changes.Renamed.Single().OldPath); Assert.Equal(renamedPath, changes.Renamed.Single().Path); Assert.Equal(2, changes.Copied.Count()); @@ -818,8 +818,8 @@ public void CanCompareTwoVersionsOfAFileWithATrailingNewlineDeletion(int context using (var changes = repo.Diff.Compare(rootCommitTree, commitTreeWithUpdatedFile)) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Modified.Count()); + Assert.Single(changes); + Assert.Single(changes.Modified); } using (var patch = repo.Diff.Compare(rootCommitTree, commitTreeWithUpdatedFile, @@ -917,9 +917,9 @@ public void CanCompareTwoVersionsOfAFileWithADiffOfTwoHunks(int contextLines, in using (var changes = repo.Diff.Compare(rootCommitTree, mergedCommitTree, compareOptions: compareOptions)) { Assert.Equal(3, changes.Count()); - Assert.Equal(1, changes.Modified.Count()); - Assert.Equal(1, changes.Deleted.Count()); - Assert.Equal(1, changes.Added.Count()); + Assert.Single(changes.Modified); + Assert.Single(changes.Deleted); + Assert.Single(changes.Added); Assert.Equal(Mode.Nonexistent, changes.Single(c => c.Path == "my-name-does-not-feel-right.txt").Mode); } @@ -983,8 +983,8 @@ public void CanHandleTwoTreeEntryChangesWithTheSamePathUsingSimilarityNone() (path, changes) => { Assert.Equal(2, changes.Count()); - Assert.Equal(1, changes.Deleted.Count()); - Assert.Equal(1, changes.TypeChanged.Count()); + Assert.Single(changes.Deleted); + Assert.Single(changes.TypeChanged); TreeEntryChanges change = changes.Single(c => c.Path== path); Assert.Equal(Mode.SymbolicLink, change.OldMode); @@ -1005,8 +1005,8 @@ public void CanHandleTwoTreeEntryChangesWithTheSamePathUsingSimilarityDefault() (path, changes) => { Assert.Equal(2, changes.Count()); - Assert.Equal(1, changes.Deleted.Count()); - Assert.Equal(1, changes.Renamed.Count()); + Assert.Single(changes.Deleted); + Assert.Single(changes.Renamed); TreeEntryChanges renamed = changes.Renamed.Single(); Assert.Equal(Mode.NonExecutableFile, renamed.OldMode); @@ -1032,16 +1032,16 @@ public void CanCompareATreeAgainstANullTree() using (var changes = repo.Diff.Compare(tree, null)) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Deleted.Count()); + Assert.Single(changes); + Assert.Single(changes.Deleted); Assert.Equal("readme.txt", changes.Deleted.Single().Path); } using (var changes = repo.Diff.Compare(null, tree)) { - Assert.Equal(1, changes.Count()); - Assert.Equal(1, changes.Added.Count()); + Assert.Single(changes); + Assert.Single(changes.Added); Assert.Equal("readme.txt", changes.Added.Single().Path); } @@ -1056,7 +1056,7 @@ public void ComparingTwoNullTreesReturnsAnEmptyTreeChanges() { using (var changes = repo.Diff.Compare(default(Tree), default(Tree))) { - Assert.Equal(0, changes.Count()); + Assert.Empty(changes); } } } @@ -1089,7 +1089,7 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny() SetFilemode(repo, true); using(var changes = repo.Diff.Compare(new[] { file })) { - Assert.Equal(1, changes.Count()); + Assert.Single(changes); var change = changes.Modified.Single(); Assert.Equal(Mode.ExecutableFile, change.OldMode); @@ -1102,7 +1102,7 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny() SetFilemode(repo, false); using (var changes = repo.Diff.Compare(new[] { file })) { - Assert.Equal(0, changes.Count()); + Assert.Empty(changes); } } } diff --git a/LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs b/LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs index ba7658ebc..430859577 100644 --- a/LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs +++ b/LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs @@ -54,12 +54,12 @@ public void CanCompareTheWorkDirAgainstTheIndexWithLaxUnmatchedExplicitPathsVali using (var changes = repo.Diff.Compare(new[] { relativePath }, false, new ExplicitPathsOptions { ShouldFailOnUnmatchedPath = false })) { - Assert.Equal(0, changes.Count()); + Assert.Empty(changes); } using (var changes = repo.Diff.Compare(new[] { relativePath })) { - Assert.Equal(0, changes.Count()); + Assert.Empty(changes); } } } @@ -139,7 +139,7 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny() SetFilemode(repo, true); using(var changes = repo.Diff.Compare(new[] { file })) { - Assert.Equal(1, changes.Count()); + Assert.Single(changes); var change = changes.Modified.Single(); Assert.Equal(Mode.ExecutableFile, change.OldMode); @@ -152,7 +152,7 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny() SetFilemode(repo, false); using(var changes = repo.Diff.Compare(new[] { file })) { - Assert.Equal(0, changes.Count()); + Assert.Empty(changes); } } } diff --git a/LibGit2Sharp.Tests/FetchFixture.cs b/LibGit2Sharp.Tests/FetchFixture.cs index 6c88317dc..dfe958fc0 100644 --- a/LibGit2Sharp.Tests/FetchFixture.cs +++ b/LibGit2Sharp.Tests/FetchFixture.cs @@ -110,7 +110,7 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url) expectedFetchState.CheckUpdatedReferences(repo); // Verify the reflog entries - Assert.Equal(1, repo.Refs.Log(string.Format("refs/remotes/{0}/master", remoteName)).Count()); // Branches are also retrieved + Assert.Single(repo.Refs.Log(string.Format("refs/remotes/{0}/master", remoteName))); // Branches are also retrieved } } @@ -157,7 +157,7 @@ public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string local // Verify the reflog entries var reflogEntry = repo.Refs.Log(string.Format("refs/remotes/{0}/{1}", remoteName, localBranchName)).Single(); - Assert.True(reflogEntry.Message.StartsWith("fetch ")); + Assert.StartsWith("fetch ", reflogEntry.Message); } } diff --git a/LibGit2Sharp.Tests/FileHistoryFixture.cs b/LibGit2Sharp.Tests/FileHistoryFixture.cs index 096cdbeeb..5380e66de 100644 --- a/LibGit2Sharp.Tests/FileHistoryFixture.cs +++ b/LibGit2Sharp.Tests/FileHistoryFixture.cs @@ -30,7 +30,7 @@ public void CanDealWithFollowTest(string url) // $ git log --follow --format=oneline untouched.txt // c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit fileHistoryEntries = repo.Commits.QueryBy("untouched.txt").ToList(); - Assert.Equal(1, fileHistoryEntries.Count()); + Assert.Single(fileHistoryEntries); Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[0].Commit.Sha); // $ git log --follow --format=oneline under-test.txt @@ -223,8 +223,8 @@ public void CanTellSingleCommitHistory() IEnumerable history = repo.Commits.QueryBy(path).ToList(); var changedBlobs = history.Blobs().Distinct(); - Assert.Equal(1, history.Count()); - Assert.Equal(1, changedBlobs.Count()); + Assert.Single(history); + Assert.Single(changedBlobs); Assert.Equal(path, history.First().Path); Assert.Equal(commit, history.First().Commit); @@ -239,8 +239,8 @@ public void EmptyRepositoryHasNoHistory() using (var repo = new Repository(repoPath)) { IEnumerable history = repo.Commits.QueryBy("Test.txt").ToList(); - Assert.Equal(0, history.Count()); - Assert.Equal(0, history.Blobs().Count()); + Assert.Empty(history); + Assert.Empty(history.Blobs()); } } diff --git a/LibGit2Sharp.Tests/FilterBranchFixture.cs b/LibGit2Sharp.Tests/FilterBranchFixture.cs index d71cb22d8..60aee38f3 100644 --- a/LibGit2Sharp.Tests/FilterBranchFixture.cs +++ b/LibGit2Sharp.Tests/FilterBranchFixture.cs @@ -366,7 +366,7 @@ public void OnlyRewriteSelectedCommits() var commit = repo.Branches["packed"].Tip; var parent = commit.Parents.Single(); - Assert.True(parent.Sha.StartsWith("5001298")); + Assert.StartsWith("5001298", parent.Sha); Assert.NotEqual(Constants.Signature, commit.Author); Assert.NotEqual(Constants.Signature, parent.Author); @@ -557,7 +557,7 @@ public void CanNotOverWriteAnExistingReference() AssertErrorFired(ex); AssertSucceedingNotFired(); - Assert.Equal(0, repo.Refs.FromGlob("refs/original/*").Count()); + Assert.Empty(repo.Refs.FromGlob("refs/original/*")); } // Graft the orphan "test" branch to the tip of "packed" @@ -633,7 +633,7 @@ public void CanRewriteParentWithRewrittenCommit() var commitToRewrite = repo.Lookup("6dcf9bf"); var newParent = repo.Branches["packed"].Tip; - Assert.True(newParent.Sha.StartsWith("41bc8c6")); + Assert.StartsWith("41bc8c6", newParent.Sha); repo.Refs.RewriteHistory(new RewriteHistoryOptions { @@ -649,22 +649,22 @@ public void CanRewriteParentWithRewrittenCommit() AssertSucceedingButNotError(); // Assert "packed" hasn't been rewritten - Assert.True(repo.Branches["packed"].Tip.Sha.StartsWith("41bc8c6")); + Assert.StartsWith("41bc8c6", repo.Branches["packed"].Tip.Sha); // Assert (test, tag: lw, tag: e90810b, tag: test) have been rewritten var rewrittenTestCommit = repo.Branches["test"].Tip; - Assert.True(rewrittenTestCommit.Sha.StartsWith("f558880")); + Assert.StartsWith("f558880", rewrittenTestCommit.Sha); Assert.Equal(rewrittenTestCommit, repo.Lookup("refs/tags/lw^{commit}")); Assert.Equal(rewrittenTestCommit, repo.Lookup("refs/tags/e90810b^{commit}")); Assert.Equal(rewrittenTestCommit, repo.Lookup("refs/tags/test^{commit}")); // Assert parent of rewritten commit var rewrittenTestCommitParent = rewrittenTestCommit.Parents.Single(); - Assert.True(rewrittenTestCommitParent.Sha.StartsWith("0c25efa")); + Assert.StartsWith("0c25efa", rewrittenTestCommitParent.Sha); // Assert grand parent of rewritten commit var rewrittenTestCommitGrandParent = rewrittenTestCommitParent.Parents.Single(); - Assert.True(rewrittenTestCommitGrandParent.Sha.StartsWith("41bc8c6")); + Assert.StartsWith("41bc8c6", rewrittenTestCommitGrandParent.Sha); } [Fact] diff --git a/LibGit2Sharp.Tests/FilterFixture.cs b/LibGit2Sharp.Tests/FilterFixture.cs index 0e2a32428..4de354003 100644 --- a/LibGit2Sharp.Tests/FilterFixture.cs +++ b/LibGit2Sharp.Tests/FilterFixture.cs @@ -314,23 +314,23 @@ public void CanFilterLargeFiles() [Fact] public void DoubleRegistrationFailsButDoubleDeregistrationDoesNot() { - Assert.Equal(0, GlobalSettings.GetRegisteredFilters().Count()); + Assert.Empty(GlobalSettings.GetRegisteredFilters()); var filter = new EmptyFilter(FilterName, attributes); var registration = GlobalSettings.RegisterFilter(filter); Assert.Throws(() => { GlobalSettings.RegisterFilter(filter); }); - Assert.Equal(1, GlobalSettings.GetRegisteredFilters().Count()); + Assert.Single(GlobalSettings.GetRegisteredFilters()); Assert.True(registration.IsValid, "FilterRegistration.IsValid should be true."); GlobalSettings.DeregisterFilter(registration); - Assert.Equal(0, GlobalSettings.GetRegisteredFilters().Count()); + Assert.Empty(GlobalSettings.GetRegisteredFilters()); Assert.False(registration.IsValid, "FilterRegistration.IsValid should be false."); GlobalSettings.DeregisterFilter(registration); - Assert.Equal(0, GlobalSettings.GetRegisteredFilters().Count()); + Assert.Empty(GlobalSettings.GetRegisteredFilters()); Assert.False(registration.IsValid, "FilterRegistration.IsValid should be false."); } diff --git a/LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs b/LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs index a8705fe81..89b61c546 100644 --- a/LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs +++ b/LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs @@ -122,8 +122,8 @@ public void WhenStagedFileDoesNotMatchPathSpecFileIsNotFiltered(string pathSpec, [InlineData("rot13", "*.txt filter=rot13", 1)] [InlineData("rot13", "*.txt filter=fake", 0)] [InlineData("rot13", "*.bat filter=rot13", 0)] - [InlineData("rot13", "*.txt filter=fake", 0)] [InlineData("fake", "*.txt filter=fake", 1)] + [InlineData("fake", "*.txt filter=rot13", 0)] [InlineData("fake", "*.bat filter=fake", 0)] [InlineData("rot13", "*.txt filter=rot13 -crlf", 1)] public void CleanIsCalledIfAttributeEntryMatches(string filterAttribute, string attributeEntry, int cleanCount) diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs index d5dee6992..76b2c2ad3 100644 --- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs +++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs @@ -45,7 +45,7 @@ public void CanRetrieveValidVersionString() public void TryingToResetNativeLibraryPathAfterLoadedThrows() { // Do something that loads the native library - Assert.NotNull(GlobalSettings.Version.Features); + var features = GlobalSettings.Version.Features; Assert.Throws(() => { GlobalSettings.NativeLibraryPath = "C:/Foo"; }); } diff --git a/LibGit2Sharp.Tests/IgnoreFixture.cs b/LibGit2Sharp.Tests/IgnoreFixture.cs index f085d35a2..fc9d65bc2 100644 --- a/LibGit2Sharp.Tests/IgnoreFixture.cs +++ b/LibGit2Sharp.Tests/IgnoreFixture.cs @@ -16,15 +16,15 @@ public void TemporaryRulesShouldApplyUntilCleared() { Touch(repo.Info.WorkingDirectory, "Foo.cs", "Bar"); - Assert.True(repo.RetrieveStatus().Untracked.Select(s => s.FilePath).Contains("Foo.cs")); + Assert.Contains("Foo.cs", repo.RetrieveStatus().Untracked.Select(s => s.FilePath)); repo.Ignore.AddTemporaryRules(new[] { "*.cs" }); - Assert.False(repo.RetrieveStatus().Untracked.Select(s => s.FilePath).Contains("Foo.cs")); + Assert.DoesNotContain("Foo.cs", repo.RetrieveStatus().Untracked.Select(s => s.FilePath)); repo.Ignore.ResetAllTemporaryRules(); - Assert.True(repo.RetrieveStatus().Untracked.Select(s => s.FilePath).Contains("Foo.cs")); + Assert.Contains("Foo.cs", repo.RetrieveStatus().Untracked.Select(s => s.FilePath)); } } diff --git a/LibGit2Sharp.Tests/IndexFixture.cs b/LibGit2Sharp.Tests/IndexFixture.cs index 0aea8cd99..4c0d150f0 100644 --- a/LibGit2Sharp.Tests/IndexFixture.cs +++ b/LibGit2Sharp.Tests/IndexFixture.cs @@ -462,18 +462,18 @@ public void CanMimicGitAddAll() using (var repo = new Repository(path)) { var before = repo.RetrieveStatus(); - Assert.True(before.Any(se => se.State == FileStatus.NewInWorkdir)); - Assert.True(before.Any(se => se.State == FileStatus.ModifiedInWorkdir)); - Assert.True(before.Any(se => se.State == FileStatus.DeletedFromWorkdir)); + Assert.Contains(before, se => se.State == FileStatus.NewInWorkdir); + Assert.Contains(before, se => se.State == FileStatus.ModifiedInWorkdir); + Assert.Contains(before, se => se.State == FileStatus.DeletedFromWorkdir); AddSomeCornerCases(repo); Commands.Stage(repo, "*"); var after = repo.RetrieveStatus(); - Assert.False(after.Any(se => se.State == FileStatus.NewInWorkdir)); - Assert.False(after.Any(se => se.State == FileStatus.ModifiedInWorkdir)); - Assert.False(after.Any(se => se.State == FileStatus.DeletedFromWorkdir)); + Assert.DoesNotContain(after, se => se.State == FileStatus.NewInWorkdir); + Assert.DoesNotContain(after, se => se.State == FileStatus.ModifiedInWorkdir); + Assert.DoesNotContain(after, se => se.State == FileStatus.DeletedFromWorkdir); } } diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index e98f150ac..bacf2e1ff 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -1,29 +1,27 @@  - net46;netcoreapp2.0 - true - $(DefineConstants);DESKTOP - false + net461;netcoreapp2.0 + $(DefineConstants);DESKTOP - - - + - + + + + + + - - - - - - + + + diff --git a/LibGit2Sharp.Tests/LogFixture.cs b/LibGit2Sharp.Tests/LogFixture.cs index b74fe97b0..b8d43fe36 100644 --- a/LibGit2Sharp.Tests/LogFixture.cs +++ b/LibGit2Sharp.Tests/LogFixture.cs @@ -25,13 +25,13 @@ public void CanEnableAndDisableLogging() GlobalSettings.LogConfiguration = new LogConfiguration(LogLevel.Warning, (l, m) => { level = l; message = m; }); Assert.Equal(LogLevel.None, level); - Assert.Equal(null, message); + Assert.Null(message); // Similarly, turning logging off should produce no messages. GlobalSettings.LogConfiguration = LogConfiguration.None; Assert.Equal(LogLevel.None, level); - Assert.Equal(null, message); + Assert.Null(message); } } } diff --git a/LibGit2Sharp.Tests/MergeFixture.cs b/LibGit2Sharp.Tests/MergeFixture.cs index 9feff9c79..8b236aa82 100644 --- a/LibGit2Sharp.Tests/MergeFixture.cs +++ b/LibGit2Sharp.Tests/MergeFixture.cs @@ -16,7 +16,7 @@ public void ANewRepoIsFullyMerged() using (var repo = new Repository(repoPath)) { - Assert.Equal(true, repo.Index.IsFullyMerged); + Assert.True(repo.Index.IsFullyMerged); } } @@ -26,7 +26,7 @@ public void AFullyMergedRepoOnlyContainsStagedIndexEntries() string path = SandboxStandardTestRepo(); using (var repo = new Repository(path)) { - Assert.Equal(true, repo.Index.IsFullyMerged); + Assert.True(repo.Index.IsFullyMerged); foreach (var entry in repo.Index) { @@ -41,7 +41,7 @@ public void SoftResetARepoWithUnmergedEntriesThrows() var path = SandboxMergedTestRepo(); using (var repo = new Repository(path)) { - Assert.Equal(false, repo.Index.IsFullyMerged); + Assert.False(repo.Index.IsFullyMerged); var headCommit = repo.Head.Tip; var firstCommitParent = headCommit.Parents.First(); @@ -56,7 +56,7 @@ public void CommitAgainARepoWithUnmergedEntriesThrows() var path = SandboxMergedTestRepo(); using (var repo = new Repository(path)) { - Assert.Equal(false, repo.Index.IsFullyMerged); + Assert.False(repo.Index.IsFullyMerged); var author = Constants.Signature; Assert.Throws( @@ -204,7 +204,7 @@ public void CanFastForwardRepos(bool shouldMergeOccurInDetachedHeadState) Assert.Equal(repo.Branches["FirstBranch"].Tip, repo.Head.Tip); Assert.Equal(repo.Head.Tip, mergeResult.Commit); - Assert.Equal(0, repo.RetrieveStatus().Count()); + Assert.Empty(repo.RetrieveStatus()); Assert.Equal(shouldMergeOccurInDetachedHeadState, repo.Info.IsHeadDetached); if (!shouldMergeOccurInDetachedHeadState) @@ -246,7 +246,7 @@ public void ConflictingMergeRepos() Assert.Equal(MergeStatus.Conflicts, mergeResult.Status); Assert.Null(mergeResult.Commit); - Assert.Equal(1, repo.Index.Conflicts.Count()); + Assert.Single(repo.Index.Conflicts); var conflict = repo.Index.Conflicts.First(); var changes = repo.Diff.Compare(repo.Lookup(conflict.Theirs.Id), repo.Lookup(conflict.Ours.Id)); @@ -285,7 +285,7 @@ public void ConflictingMergeReposBinary() Assert.Equal(MergeStatus.Conflicts, mergeResult.Status); - Assert.Equal(1, repo.Index.Conflicts.Count()); + Assert.Single(repo.Index.Conflicts); Conflict conflict = repo.Index.Conflicts.First(); @@ -515,12 +515,12 @@ public void CanMergeAndNotCommit() MergeResult result = repo.Merge(commitToMerge, Constants.Signature, new MergeOptions() { CommitOnSuccess = false}); Assert.Equal(MergeStatus.NonFastForward, result.Status); - Assert.Equal(null, result.Commit); + Assert.Null(result.Commit); RepositoryStatus repoStatus = repo.RetrieveStatus(); // Verify that there is a staged entry. - Assert.Equal(1, repoStatus.Count()); + Assert.Single(repoStatus); Assert.Equal(FileStatus.ModifiedInIndex, repo.RetrieveStatus("b.txt")); } } @@ -570,7 +570,7 @@ public void VerifyUpToDateMerge() MergeResult result = repo.Merge(commitToMerge, Constants.Signature, new MergeOptions() { FastForwardStrategy = FastForwardStrategy.NoFastForward }); Assert.Equal(MergeStatus.UpToDate, result.Status); - Assert.Equal(null, result.Commit); + Assert.Null(result.Commit); Assert.False(repo.RetrieveStatus().Any()); } } @@ -776,7 +776,7 @@ public void CanMergeTreeIntoSameTree() var result = repo.ObjectDatabase.MergeCommits(master, master, null); Assert.Equal(MergeTreeStatus.Succeeded, result.Status); - Assert.Equal(0, result.Conflicts.Count()); + Assert.Empty(result.Conflicts); } } @@ -800,7 +800,7 @@ public void CanMergeTreeIntoTreeFromUnbornBranch() var result = repo.ObjectDatabase.MergeCommits(master, branch, null); Assert.Equal(MergeTreeStatus.Succeeded, result.Status); Assert.NotNull(result.Tree); - Assert.Equal(0, result.Conflicts.Count()); + Assert.Empty(result.Conflicts); } } @@ -822,7 +822,7 @@ public void CanMergeCommitsAndDetectConflicts() var result = repo.ObjectDatabase.MergeCommits(master, branch, null); Assert.Equal(MergeTreeStatus.Conflicts, result.Status); Assert.Null(result.Tree); - Assert.NotEqual(0, result.Conflicts.Count()); + Assert.NotEmpty(result.Conflicts); } } @@ -838,7 +838,7 @@ public void CanMergeFastForwardTreeWithoutConflicts() var result = repo.ObjectDatabase.MergeCommits(master, branch, null); Assert.Equal(MergeTreeStatus.Succeeded, result.Status); Assert.NotNull(result.Tree); - Assert.Equal(0, result.Conflicts.Count()); + Assert.Empty(result.Conflicts); } } @@ -856,7 +856,7 @@ public void CanIdentifyConflictsInMergeCommits() Assert.Equal(MergeTreeStatus.Conflicts, result.Status); Assert.Null(result.Tree); - Assert.Equal(1, result.Conflicts.Count()); + Assert.Single(result.Conflicts); var conflict = result.Conflicts.First(); Assert.Equal(new ObjectId("8e9daea300fbfef6c0da9744c6214f546d55b279"), conflict.Ancestor.Id); diff --git a/LibGit2Sharp.Tests/NetworkFixture.cs b/LibGit2Sharp.Tests/NetworkFixture.cs index 9153ffeb0..3ac73a2e8 100644 --- a/LibGit2Sharp.Tests/NetworkFixture.cs +++ b/LibGit2Sharp.Tests/NetworkFixture.cs @@ -168,13 +168,13 @@ public void CanPull(FastForwardStrategy fastForwardStrategy) if(fastForwardStrategy == FastForwardStrategy.Default || fastForwardStrategy == FastForwardStrategy.FastForwardOnly) { - Assert.Equal(mergeResult.Status, MergeStatus.FastForward); + Assert.Equal(MergeStatus.FastForward, mergeResult.Status); Assert.Equal(mergeResult.Commit, repo.Branches["refs/remotes/origin/master"].Tip); Assert.Equal(repo.Head.Tip, repo.Branches["refs/remotes/origin/master"].Tip); } else { - Assert.Equal(mergeResult.Status, MergeStatus.NonFastForward); + Assert.Equal(MergeStatus.NonFastForward, mergeResult.Status); } } } @@ -199,7 +199,7 @@ public void CanPullIntoEmptyRepo() // Pull! MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, new PullOptions()); - Assert.Equal(mergeResult.Status, MergeStatus.FastForward); + Assert.Equal(MergeStatus.FastForward, mergeResult.Status); Assert.Equal(mergeResult.Commit, repo.Branches["refs/remotes/origin/master"].Tip); Assert.Equal(repo.Head.Tip, repo.Branches["refs/remotes/origin/master"].Tip); } @@ -260,7 +260,7 @@ public void CanMergeFetchedRefs() }; MergeResult mergeResult = repo.MergeFetchedRefs(Constants.Signature, mergeOptions); - Assert.Equal(mergeResult.Status, MergeStatus.NonFastForward); + Assert.Equal(MergeStatus.NonFastForward, mergeResult.Status); } } diff --git a/LibGit2Sharp.Tests/NoteFixture.cs b/LibGit2Sharp.Tests/NoteFixture.cs index 48ad98eee..e3cb9d7a0 100644 --- a/LibGit2Sharp.Tests/NoteFixture.cs +++ b/LibGit2Sharp.Tests/NoteFixture.cs @@ -20,7 +20,7 @@ public void RetrievingNotesFromANonExistingGitObjectYieldsNoResult() { var notes = repo.Notes[ObjectId.Zero]; - Assert.Equal(0, notes.Count()); + Assert.Empty(notes); } } @@ -32,7 +32,7 @@ public void RetrievingNotesFromAGitObjectWhichHasNoNoteYieldsNoResult() { var notes = repo.Notes[new ObjectId("4c062a6361ae6959e06292c1fa5e2822d9c96345")]; - Assert.Equal(0, notes.Count()); + Assert.Empty(notes); } } @@ -308,19 +308,19 @@ public void CanRetrieveTheListOfNotesForAGivenNamespace() } } - [Fact] - public void CanRetrieveNotesWhenThereAreNotAny() - { - string path = InitNewRepository(); // doesn't reproduce an error when using a sandbox repository so we have to create an actual repo. - using (var repo = new Repository(path)) - { - foreach (var note in repo.Notes) - { - Assert.NotNull(note); - } - Assert.Equal(0, repo.Notes.Count()); - } - } + [Fact] + public void CanRetrieveNotesWhenThereAreNotAny() + { + string path = InitNewRepository(); // doesn't reproduce an error when using a sandbox repository so we have to create an actual repo. + using (var repo = new Repository(path)) + { + foreach (var note in repo.Notes) + { + Assert.NotNull(note); + } + Assert.Empty(repo.Notes); + } + } private static T[] SortedNotes(IEnumerable notes, Func selector) diff --git a/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs b/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs index fc06ef713..767732487 100644 --- a/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs +++ b/LibGit2Sharp.Tests/ObjectDatabaseFixture.cs @@ -61,7 +61,7 @@ public void RetrieveObjectMetadataReturnsCorrectSizeAndTypeForBlob() GitObjectMetadata blobMetadata = repo.ObjectDatabase.RetrieveObjectMetadata(blob.Id); Assert.Equal(blobMetadata.Size, blob.Size); - Assert.Equal(blobMetadata.Type, ObjectType.Blob); + Assert.Equal(ObjectType.Blob, blobMetadata.Type); Blob fetchedBlob = repo.Lookup(blob.Id); Assert.Equal(blobMetadata.Size, fetchedBlob.Size); @@ -449,7 +449,7 @@ public void CanCreateABinaryBlobFromAStream() { Blob blob = repo.ObjectDatabase.CreateBlob(stream); Assert.Equal(6, blob.Size); - Assert.Equal(true, blob.IsBinary); + Assert.True(blob.IsBinary); } } } diff --git a/LibGit2Sharp.Tests/ObjectIdFixture.cs b/LibGit2Sharp.Tests/ObjectIdFixture.cs index e118cfdb8..8d3468bdd 100644 --- a/LibGit2Sharp.Tests/ObjectIdFixture.cs +++ b/LibGit2Sharp.Tests/ObjectIdFixture.cs @@ -133,7 +133,7 @@ public void TryParse(string maybeSha, bool isValidSha) Assert.NotNull(parsedObjectId); Assert.Equal(maybeSha, parsedObjectId.Sha); - Assert.True(maybeSha.StartsWith(parsedObjectId.ToString(3))); + Assert.StartsWith(parsedObjectId.ToString(3), maybeSha); Assert.Equal(maybeSha, parsedObjectId.ToString(42)); } diff --git a/LibGit2Sharp.Tests/RebaseFixture.cs b/LibGit2Sharp.Tests/RebaseFixture.cs index 28c49738e..240ca8985 100644 --- a/LibGit2Sharp.Tests/RebaseFixture.cs +++ b/LibGit2Sharp.Tests/RebaseFixture.cs @@ -253,10 +253,10 @@ public void VerifyRebaseDetailed(string attributes, string lineEnding, string[] repo.Rebase.Start(null, upstreamBranch, null, Constants.Identity2, options); - Assert.Equal(true, wasCheckoutNotifyCalledForResetingHead); - Assert.Equal(true, wasCheckoutProgressCalledForResetingHead); - Assert.Equal(true, wasCheckoutNotifyCalled); - Assert.Equal(true, wasCheckoutProgressCalled); + Assert.True(wasCheckoutNotifyCalledForResetingHead); + Assert.True(wasCheckoutProgressCalledForResetingHead); + Assert.True(wasCheckoutNotifyCalled); + Assert.True(wasCheckoutProgressCalled); // Verify the chain of resultant rebased commits. CommitFilter commitFilter = new CommitFilter() diff --git a/LibGit2Sharp.Tests/RefSpecFixture.cs b/LibGit2Sharp.Tests/RefSpecFixture.cs index b8f2b6a09..50bf3343b 100644 --- a/LibGit2Sharp.Tests/RefSpecFixture.cs +++ b/LibGit2Sharp.Tests/RefSpecFixture.cs @@ -15,7 +15,7 @@ public void CanCountRefSpecs() using (var repo = new Repository(path)) { var remote = repo.Network.Remotes["origin"]; - Assert.Equal(1, remote.RefSpecs.Count()); + Assert.Single(remote.RefSpecs); } } @@ -63,7 +63,7 @@ public void CanReadRefSpecDetails() Assert.Equal("refs/heads/*", refSpec.Source); Assert.Equal("refs/remotes/origin/*", refSpec.Destination); - Assert.Equal(true, refSpec.ForceUpdate); + Assert.True(refSpec.ForceUpdate); } } @@ -225,7 +225,6 @@ public void CanCheckForMatches(string reference, bool shouldMatchSource, bool sh [Theory] [InlineData("refs/heads/master", "refs/remotes/foo/master")] [InlineData("refs/heads/bar/master", "refs/remotes/foo/bar/master")] - [InlineData("refs/heads/master", "refs/remotes/foo/master")] public void CanTransformRefspecs(string lhs, string rhs) { using (var repo = new Repository(InitNewRepository())) diff --git a/LibGit2Sharp.Tests/ReferenceFixture.cs b/LibGit2Sharp.Tests/ReferenceFixture.cs index ac2af3c24..186d2e869 100644 --- a/LibGit2Sharp.Tests/ReferenceFixture.cs +++ b/LibGit2Sharp.Tests/ReferenceFixture.cs @@ -295,12 +295,12 @@ public void RemovingAReferenceDecreasesTheRefsCount() const string refName = "refs/heads/test"; List refs = repo.Refs.Select(r => r.CanonicalName).ToList(); - Assert.True(refs.Contains(refName)); + Assert.Contains(refName, refs); repo.Refs.Remove(refName); List refs2 = repo.Refs.Select(r => r.CanonicalName).ToList(); - Assert.False(refs2.Contains(refName)); + Assert.DoesNotContain(refName, refs2); Assert.Equal(refs.Count - 1, refs2.Count); } @@ -736,13 +736,13 @@ public void RenamingAReferenceDoesNotDecreaseTheRefsCount() const string newName = "refs/atic/tagtest"; List refs = repo.Refs.Select(r => r.CanonicalName).ToList(); - Assert.True(refs.Contains(oldName)); + Assert.Contains(oldName, refs); repo.Refs.Rename(oldName, newName); List refs2 = repo.Refs.Select(r => r.CanonicalName).ToList(); - Assert.False(refs2.Contains(oldName)); - Assert.True(refs2.Contains(newName)); + Assert.DoesNotContain(oldName, refs2); + Assert.Contains(newName, refs2); Assert.Equal(refs2.Count, refs.Count); } @@ -774,7 +774,7 @@ public void CanFilterReferencesWithAGlob() Assert.Equal(5, repo.Refs.FromGlob("refs/heads/*").Count()); Assert.Equal(5, repo.Refs.FromGlob("refs/tags/*").Count()); Assert.Equal(3, repo.Refs.FromGlob("*t?[pqrs]t*").Count()); - Assert.Equal(0, repo.Refs.FromGlob("test").Count()); + Assert.Empty(repo.Refs.FromGlob("test")); } } diff --git a/LibGit2Sharp.Tests/ReflogFixture.cs b/LibGit2Sharp.Tests/ReflogFixture.cs index fa5a0d842..f93952e6e 100644 --- a/LibGit2Sharp.Tests/ReflogFixture.cs +++ b/LibGit2Sharp.Tests/ReflogFixture.cs @@ -23,7 +23,7 @@ public void CanReadReflog() // Initial commit assertions Assert.Equal("timothy.clem@gmail.com", reflog.Last().Committer.Email); - Assert.True(reflog.Last().Message.StartsWith("clone: from")); + Assert.StartsWith("clone: from", reflog.Last().Message); Assert.Equal(ObjectId.Zero, reflog.Last().From); // second commit assertions @@ -78,7 +78,7 @@ public void CommitShouldCreateReflogEntryOnHeadAndOnTargetedDirectReference() Commit commit = repo.Commit(commitMessage, author, author); // Assert a reflog entry is created on HEAD - Assert.Equal(1, repo.Refs.Log("HEAD").Count()); + Assert.Single(repo.Refs.Log("HEAD")); var reflogEntry = repo.Refs.Log("HEAD").First(); Assert.Equal(identity.Name, reflogEntry.Committer.Name); @@ -91,7 +91,7 @@ public void CommitShouldCreateReflogEntryOnHeadAndOnTargetedDirectReference() Assert.Equal(ObjectId.Zero, reflogEntry.From); // Assert the same reflog entry is created on refs/heads/master - Assert.Equal(1, repo.Refs.Log("refs/heads/master").Count()); + Assert.Single(repo.Refs.Log("refs/heads/master")); reflogEntry = repo.Refs.Log("HEAD").First(); Assert.Equal(identity.Name, reflogEntry.Committer.Name); @@ -103,7 +103,7 @@ public void CommitShouldCreateReflogEntryOnHeadAndOnTargetedDirectReference() Assert.Equal(ObjectId.Zero, reflogEntry.From); // Assert no reflog entry is created on refs/heads/unit_test - Assert.Equal(0, repo.Refs.Log("refs/heads/unit_test").Count()); + Assert.Empty(repo.Refs.Log("refs/heads/unit_test")); } } @@ -123,7 +123,7 @@ public void CommitOnUnbornReferenceShouldCreateReflogEntryWithInitialTag() repo.Commit(commitMessage, author, author); // Assert the reflog entry message is correct - Assert.Equal(1, repo.Refs.Log("HEAD").Count()); + Assert.Single(repo.Refs.Log("HEAD")); Assert.Equal(string.Format("commit (initial): {0}", commitMessage), repo.Refs.Log("HEAD").First().Message); } } diff --git a/LibGit2Sharp.Tests/RemoteFixture.cs b/LibGit2Sharp.Tests/RemoteFixture.cs index 28049f0e0..36990bb6e 100644 --- a/LibGit2Sharp.Tests/RemoteFixture.cs +++ b/LibGit2Sharp.Tests/RemoteFixture.cs @@ -203,7 +203,7 @@ public void DoesNotThrowWhenARemoteHasNoUrlSet() { var noUrlRemote = repo.Network.Remotes["no_url"]; Assert.NotNull(noUrlRemote); - Assert.Equal(null, noUrlRemote.Url); + Assert.Null(noUrlRemote.Url); var remotes = repo.Network.Remotes.ToList(); Assert.Equal(1, remotes.Count(r => r.Name == "no_url")); diff --git a/LibGit2Sharp.Tests/RemoveFixture.cs b/LibGit2Sharp.Tests/RemoveFixture.cs index a89977fce..e97636d9c 100644 --- a/LibGit2Sharp.Tests/RemoveFixture.cs +++ b/LibGit2Sharp.Tests/RemoveFixture.cs @@ -28,14 +28,14 @@ public class RemoveFixture : BaseFixture * 'git rm ' fails ("error: '' has local modifications"). */ [InlineData(false, "modified_unstaged_file.txt", false, FileStatus.ModifiedInWorkdir, true, true, FileStatus.NewInWorkdir | FileStatus.DeletedFromIndex)] - [InlineData(true, "modified_unstaged_file.txt", true, FileStatus.ModifiedInWorkdir, true, true, 0)] + [InlineData(true, "modified_unstaged_file.txt", true, FileStatus.ModifiedInWorkdir, true, true, FileStatus.Unaltered)] /*** * Test case: modified file in wd, the modifications have already been promoted to the index. * 'git rm --cached ' works (removes the file from the index) * 'git rm ' fails ("error: '' has changes staged in the index") */ [InlineData(false, "modified_staged_file.txt", false, FileStatus.ModifiedInIndex, true, true, FileStatus.NewInWorkdir | FileStatus.DeletedFromIndex)] - [InlineData(true, "modified_staged_file.txt", true, FileStatus.ModifiedInIndex, true, true, 0)] + [InlineData(true, "modified_staged_file.txt", true, FileStatus.ModifiedInIndex, true, true, FileStatus.Unaltered)] /*** * Test case: modified file in wd, the modifications have already been promoted to the index, and * the file does not exist in the HEAD. @@ -43,7 +43,7 @@ public class RemoveFixture : BaseFixture * 'git rm ' throws ("error: '' has changes staged in the index") */ [InlineData(false, "new_tracked_file.txt", false, FileStatus.NewInIndex, true, true, FileStatus.NewInWorkdir)] - [InlineData(true, "new_tracked_file.txt", true, FileStatus.NewInIndex, true, true, 0)] + [InlineData(true, "new_tracked_file.txt", true, FileStatus.NewInIndex, true, true, FileStatus.Unaltered)] public void CanRemoveAnUnalteredFileFromTheIndexWithoutRemovingItFromTheWorkingDirectory( bool removeFromWorkdir, string filename, bool throws, FileStatus initialStatus, bool existsBeforeRemove, bool existsAfterRemove, FileStatus lastStatus) { @@ -88,7 +88,7 @@ public void RemovingAModifiedFileWhoseChangesHaveBeenPromotedToTheIndexAndWithAd { string fullpath = Path.Combine(repo.Info.WorkingDirectory, filename); - Assert.Equal(true, File.Exists(fullpath)); + Assert.True(File.Exists(fullpath)); File.AppendAllText(fullpath, "additional content"); Assert.Equal(FileStatus.ModifiedInIndex | FileStatus.ModifiedInWorkdir, repo.RetrieveStatus(filename)); diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs index 4934629b9..b8a84a4e9 100644 --- a/LibGit2Sharp.Tests/RepositoryFixture.cs +++ b/LibGit2Sharp.Tests/RepositoryFixture.cs @@ -123,7 +123,7 @@ public void CanCreateStandardRepoAndSpecifyAFolderWhichWillContainTheNewlyCreate Assert.True(Repository.IsValid(repo.Info.WorkingDirectory)); Assert.True(Repository.IsValid(repo.Info.Path)); - Assert.Equal(false, repo.Info.IsBare); + Assert.False(repo.Info.IsBare); char sep = Path.DirectorySeparatorChar; Assert.Equal(scd1.RootedDirectoryPath + sep, repo.Info.WorkingDirectory); @@ -148,7 +148,7 @@ public void CanCreateStandardRepoAndDirectlySpecifyAGitDirectory() Assert.True(Repository.IsValid(repo.Info.WorkingDirectory)); Assert.True(Repository.IsValid(repo.Info.Path)); - Assert.Equal(false, repo.Info.IsBare); + Assert.False(repo.Info.IsBare); char sep = Path.DirectorySeparatorChar; Assert.Equal(scd1.RootedDirectoryPath + sep, repo.Info.WorkingDirectory); @@ -267,18 +267,18 @@ private static void AssertInitializedRepository(IRepository repo, string expecte Assert.Equal(headRef.TargetIdentifier, repo.Head.CanonicalName); Assert.Null(repo.Head.Tip); - Assert.Equal(0, repo.Commits.Count()); - Assert.Equal(0, repo.Commits.QueryBy(new CommitFilter()).Count()); - Assert.Equal(0, repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = repo.Refs.Head }).Count()); - Assert.Equal(0, repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = repo.Head }).Count()); - Assert.Equal(0, repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = "HEAD" }).Count()); - Assert.Equal(0, repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = expectedHeadTargetIdentifier }).Count()); + Assert.Empty(repo.Commits); + Assert.Empty(repo.Commits.QueryBy(new CommitFilter())); + Assert.Empty(repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = repo.Refs.Head })); + Assert.Empty(repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = repo.Head })); + Assert.Empty(repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = "HEAD" })); + Assert.Empty(repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = expectedHeadTargetIdentifier })); Assert.Null(repo.Head["subdir/I-do-not-exist"]); - Assert.Equal(0, repo.Branches.Count()); - Assert.Equal(0, repo.Refs.Count()); - Assert.Equal(0, repo.Tags.Count()); + Assert.Empty(repo.Branches); + Assert.Empty(repo.Refs); + Assert.Empty(repo.Tags); } [Fact] diff --git a/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs b/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs index b7c56ff4f..707e0ecae 100644 --- a/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs +++ b/LibGit2Sharp.Tests/RepositoryOptionsFixture.cs @@ -174,8 +174,8 @@ public void CanCommitOnBareRepository() Commands.Stage(repo, relativeFilepath); Assert.NotNull(repo.Commit("Initial commit", Constants.Signature, Constants.Signature)); - Assert.Equal(1, repo.Head.Commits.Count()); - Assert.Equal(1, repo.Commits.Count()); + Assert.Single(repo.Head.Commits); + Assert.Single(repo.Commits); } } } diff --git a/LibGit2Sharp.Tests/ResetHeadFixture.cs b/LibGit2Sharp.Tests/ResetHeadFixture.cs index 0379c855a..83a7efcb9 100644 --- a/LibGit2Sharp.Tests/ResetHeadFixture.cs +++ b/LibGit2Sharp.Tests/ResetHeadFixture.cs @@ -256,7 +256,7 @@ public void HardResetUpdatesTheContentOfTheWorkingDirectory() names = new DirectoryInfo(repo.Info.WorkingDirectory).GetFileSystemInfos().Select(fsi => fsi.Name).ToList(); names.Sort(StringComparer.Ordinal); - Assert.Equal(true, progressCalled); + Assert.True(progressCalled); Assert.Equal(new[] { ".git", "README", "WillNotBeRemoved.txt", "branch_file.txt", "new.txt", "new_untracked_file.txt" }, names); } } diff --git a/LibGit2Sharp.Tests/ResetIndexFixture.cs b/LibGit2Sharp.Tests/ResetIndexFixture.cs index 2e8257f22..97a1eef88 100644 --- a/LibGit2Sharp.Tests/ResetIndexFixture.cs +++ b/LibGit2Sharp.Tests/ResetIndexFixture.cs @@ -62,7 +62,7 @@ public void ResetTheIndexWithTheHeadUnstagesEverything() repo.Index.Replace(repo.Head.Tip); RepositoryStatus newStatus = repo.RetrieveStatus(); - Assert.Equal(0, newStatus.Where(IsStaged).Count()); + Assert.Empty(newStatus.Where(IsStaged)); // Assert that no reflog entry is created Assert.Equal(reflogEntriesCount, repo.Refs.Log(repo.Refs.Head).Count()); @@ -120,7 +120,7 @@ public void CanResetTheIndexWhenARenameExists() repo.Index.Replace(repo.Lookup("32eab9c")); RepositoryStatus status = repo.RetrieveStatus(); - Assert.Equal(0, status.Where(IsStaged).Count()); + Assert.Empty(status.Where(IsStaged)); } } @@ -132,14 +132,14 @@ public void CanResetSourceOfARenameInIndex() Commands.Move(repo, "branch_file.txt", "renamed_branch_file.txt"); RepositoryStatus oldStatus = repo.RetrieveStatus(); - Assert.Equal(1, oldStatus.RenamedInIndex.Count()); + Assert.Single(oldStatus.RenamedInIndex); Assert.Equal(FileStatus.Nonexistent, oldStatus["branch_file.txt"].State); Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State); repo.Index.Replace(repo.Lookup("32eab9c"), new string[] { "branch_file.txt" }); RepositoryStatus newStatus = repo.RetrieveStatus(); - Assert.Equal(0, newStatus.RenamedInIndex.Count()); + Assert.Empty(newStatus.RenamedInIndex); Assert.Equal(FileStatus.DeletedFromWorkdir, newStatus["branch_file.txt"].State); Assert.Equal(FileStatus.NewInIndex, newStatus["renamed_branch_file.txt"].State); } @@ -153,13 +153,13 @@ public void CanResetTargetOfARenameInIndex() Commands.Move(repo, "branch_file.txt", "renamed_branch_file.txt"); RepositoryStatus oldStatus = repo.RetrieveStatus(); - Assert.Equal(1, oldStatus.RenamedInIndex.Count()); + Assert.Single(oldStatus.RenamedInIndex); Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State); repo.Index.Replace(repo.Lookup("32eab9c"), new string[] { "renamed_branch_file.txt" }); RepositoryStatus newStatus = repo.RetrieveStatus(); - Assert.Equal(0, newStatus.RenamedInIndex.Count()); + Assert.Empty(newStatus.RenamedInIndex); Assert.Equal(FileStatus.NewInWorkdir, newStatus["renamed_branch_file.txt"].State); Assert.Equal(FileStatus.DeletedFromIndex, newStatus["branch_file.txt"].State); } diff --git a/LibGit2Sharp.Tests/RevertFixture.cs b/LibGit2Sharp.Tests/RevertFixture.cs index cf17dcfe1..b0f12b9dc 100644 --- a/LibGit2Sharp.Tests/RevertFixture.cs +++ b/LibGit2Sharp.Tests/RevertFixture.cs @@ -421,7 +421,7 @@ public void RevertWithNothingToRevert(bool commitOnSuccess) new RevertOptions() { CommitOnSuccess = commitOnSuccess }); Assert.NotNull(result); - Assert.Equal(null, result.Commit); + Assert.Null(result.Commit); Assert.Equal(RevertStatus.NothingToRevert, result.Status); if (commitOnSuccess) diff --git a/LibGit2Sharp.Tests/StashFixture.cs b/LibGit2Sharp.Tests/StashFixture.cs index 6d6d5565d..7ba379621 100644 --- a/LibGit2Sharp.Tests/StashFixture.cs +++ b/LibGit2Sharp.Tests/StashFixture.cs @@ -69,7 +69,7 @@ public void CanAddAndRemoveStash() //Remove one stash repo.Stashes.Remove(0); - Assert.Equal(1, repo.Stashes.Count()); + Assert.Single(repo.Stashes); Stash newTopStash = repo.Stashes.First(); Assert.Equal("stash@{0}", newTopStash.CanonicalName); Assert.Equal(stash.WorkTree.Sha, newTopStash.WorkTree.Sha); @@ -220,7 +220,7 @@ public void CanStashAndApplyWithOptions() Assert.Equal(StashApplyStatus.Applied, repo.Stashes.Apply(0)); Assert.Equal(FileStatus.NewInIndex, repo.RetrieveStatus(filename)); - Assert.Equal(1, repo.Stashes.Count()); + Assert.Single(repo.Stashes); Commands.Stage(repo, filename); @@ -245,7 +245,7 @@ public void CanStashAndPop() { var stasher = Constants.Signature; - Assert.Equal(0, repo.Stashes.Count()); + Assert.Empty(repo.Stashes); const string filename = "staged_file_path.txt"; const string contents = "I'm staged"; @@ -253,10 +253,10 @@ public void CanStashAndPop() Commands.Stage(repo, filename); repo.Stashes.Add(stasher, "This stash with default options"); - Assert.Equal(1, repo.Stashes.Count()); + Assert.Single(repo.Stashes); Assert.Equal(StashApplyStatus.Applied, repo.Stashes.Pop(0)); - Assert.Equal(0, repo.Stashes.Count()); + Assert.Empty(repo.Stashes); Assert.Equal(FileStatus.NewInIndex, repo.RetrieveStatus(filename)); Assert.Equal(contents, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, filename))); @@ -290,7 +290,7 @@ public void StashFailsWithUncommittedChangesIntheIndex() { ApplyModifiers = StashApplyModifiers.ReinstateIndex, })); - Assert.Equal(1, repo.Stashes.Count()); + Assert.Single(repo.Stashes); Assert.Equal(newContents, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, filename))); Assert.Equal(newContents, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, filename2))); } @@ -321,7 +321,7 @@ public void StashCallsTheCallback() ProgressHandler = (progress) => { called = true; return true; } }); - Assert.Equal(true, called); + Assert.True(called); repo.Reset(ResetMode.Hard); @@ -331,7 +331,7 @@ public void StashCallsTheCallback() ProgressHandler = (progress) => { called = true; return true; } }); - Assert.Equal(true, called); + Assert.True(called); } } diff --git a/LibGit2Sharp.Tests/StatusFixture.cs b/LibGit2Sharp.Tests/StatusFixture.cs index 270ae276c..7ba561def 100644 --- a/LibGit2Sharp.Tests/StatusFixture.cs +++ b/LibGit2Sharp.Tests/StatusFixture.cs @@ -255,15 +255,15 @@ public void CanRetrieveTheStatusOfANewRepository(bool includeUnaltered) { RepositoryStatus status = repo.RetrieveStatus(new StatusOptions() { IncludeUnaltered = includeUnaltered }); Assert.NotNull(status); - Assert.Equal(0, status.Count()); + Assert.Empty(status); Assert.False(status.IsDirty); - Assert.Equal(0, status.Untracked.Count()); - Assert.Equal(0, status.Modified.Count()); - Assert.Equal(0, status.Missing.Count()); - Assert.Equal(0, status.Added.Count()); - Assert.Equal(0, status.Staged.Count()); - Assert.Equal(0, status.Removed.Count()); + Assert.Empty(status.Untracked); + Assert.Empty(status.Modified); + Assert.Empty(status.Missing); + Assert.Empty(status.Added); + Assert.Empty(status.Staged); + Assert.Empty(status.Removed); } } @@ -286,7 +286,7 @@ public void RetrievingTheStatusOfARepositoryReturnsGitPaths() // Get the repository status RepositoryStatus repoStatus = repo.RetrieveStatus(); - Assert.Equal(1, repoStatus.Count()); + Assert.Single(repoStatus); StatusEntry statusEntry = repoStatus.Single(); Assert.Equal(relFilePath.Replace('\\', '/'), statusEntry.FilePath); @@ -515,7 +515,7 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectivesThroug newStatus = repo.RetrieveStatus(new StatusOptions { IncludeIgnored = true }); Assert.Equal(new[] { "bin/look-ma.txt" }, newStatus.Ignored.Select(s => s.FilePath)); - Assert.True(newStatus.Untracked.Select(s => s.FilePath).Contains("bin/what-about-me.txt")); + Assert.Contains("bin/what-about-me.txt", newStatus.Untracked.Select(s => s.FilePath)); } } @@ -571,8 +571,8 @@ public void CanRetrieveTheStatusOfARelativeWorkingDirectory() Assert.Equal(2, status.Untracked.Count()); status = repo.RetrieveStatus(new StatusOptions() { PathSpec = new[] { "just_a_dir/another_dir" } }); - Assert.Equal(1, status.Count()); - Assert.Equal(1, status.Untracked.Count()); + Assert.Single(status); + Assert.Single(status.Untracked); } } @@ -656,7 +656,7 @@ public void UnalteredFilesDontMarkIndexAsDirty() RepositoryStatus status = repo.RetrieveStatus(new StatusOptions() { IncludeUnaltered = true }); - Assert.Equal(false, status.IsDirty); + Assert.False(status.IsDirty); Assert.Equal(9, status.Count()); } } diff --git a/LibGit2Sharp.Tests/TagFixture.cs b/LibGit2Sharp.Tests/TagFixture.cs index e6897935e..5c1628a7b 100644 --- a/LibGit2Sharp.Tests/TagFixture.cs +++ b/LibGit2Sharp.Tests/TagFixture.cs @@ -606,12 +606,12 @@ public void RemovingATagDecreasesTheTagsCount() const string tagName = "e90810b"; List tags = repo.Tags.Select(r => r.FriendlyName).ToList(); - Assert.True(tags.Contains(tagName)); + Assert.Contains(tagName, tags); repo.Tags.Remove(tagName); List tags2 = repo.Tags.Select(r => r.FriendlyName).ToList(); - Assert.False(tags2.Contains(tagName)); + Assert.DoesNotContain(tagName, tags2); Assert.Equal(tags.Count - 1, tags2.Count); } @@ -661,7 +661,7 @@ public void CanListAllTagsInAEmptyRepository() using (var repo = new Repository(repoPath)) { Assert.True(repo.Info.IsHeadUnborn); - Assert.Equal(0, repo.Tags.Count()); + Assert.Empty(repo.Tags); } } diff --git a/LibGit2Sharp.Tests/TreeFixture.cs b/LibGit2Sharp.Tests/TreeFixture.cs index 5187cd142..31ca85c2d 100644 --- a/LibGit2Sharp.Tests/TreeFixture.cs +++ b/LibGit2Sharp.Tests/TreeFixture.cs @@ -82,7 +82,7 @@ public void CanEnumerateSubTrees() .Select(e => e.Target) .Cast(); - Assert.Equal(1, subTrees.Count()); + Assert.Single(subTrees); } } diff --git a/LibGit2Sharp.Tests/UnstageFixture.cs b/LibGit2Sharp.Tests/UnstageFixture.cs index c4791d10d..a5dc143d3 100644 --- a/LibGit2Sharp.Tests/UnstageFixture.cs +++ b/LibGit2Sharp.Tests/UnstageFixture.cs @@ -167,8 +167,8 @@ public void CanUnstageUntrackedFileAgainstAnOrphanedHead() Commands.Unstage(repo, relativePath); RepositoryStatus status = repo.RetrieveStatus(); - Assert.Equal(0, status.Staged.Count()); - Assert.Equal(1, status.Untracked.Count()); + Assert.Empty(status.Staged); + Assert.Single(status.Untracked); Assert.Throws(() => Commands.Unstage(repo, "i-dont-exist", new ExplicitPathsOptions())); } @@ -264,14 +264,14 @@ public void CanUnstageSourceOfARename() Commands.Move(repo, "branch_file.txt", "renamed_branch_file.txt"); RepositoryStatus oldStatus = repo.RetrieveStatus(); - Assert.Equal(1, oldStatus.RenamedInIndex.Count()); + Assert.Single(oldStatus.RenamedInIndex); Assert.Equal(FileStatus.Nonexistent, oldStatus["branch_file.txt"].State); Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State); Commands.Unstage(repo, new string[] { "branch_file.txt" }); RepositoryStatus newStatus = repo.RetrieveStatus(); - Assert.Equal(0, newStatus.RenamedInIndex.Count()); + Assert.Empty(newStatus.RenamedInIndex); Assert.Equal(FileStatus.DeletedFromWorkdir, newStatus["branch_file.txt"].State); Assert.Equal(FileStatus.NewInIndex, newStatus["renamed_branch_file.txt"].State); } @@ -285,13 +285,13 @@ public void CanUnstageTargetOfARename() Commands.Move(repo, "branch_file.txt", "renamed_branch_file.txt"); RepositoryStatus oldStatus = repo.RetrieveStatus(); - Assert.Equal(1, oldStatus.RenamedInIndex.Count()); + Assert.Single(oldStatus.RenamedInIndex); Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State); Commands.Unstage(repo, new string[] { "renamed_branch_file.txt" }); RepositoryStatus newStatus = repo.RetrieveStatus(); - Assert.Equal(0, newStatus.RenamedInIndex.Count()); + Assert.Empty(newStatus.RenamedInIndex); Assert.Equal(FileStatus.NewInWorkdir, newStatus["renamed_branch_file.txt"].State); Assert.Equal(FileStatus.DeletedFromIndex, newStatus["branch_file.txt"].State); } diff --git a/LibGit2Sharp.Tests/app.config b/LibGit2Sharp.Tests/app.config deleted file mode 100644 index 34dc4a041..000000000 --- a/LibGit2Sharp.Tests/app.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/LibGit2Sharp.Tests/desktop/ShadowCopyFixture.cs b/LibGit2Sharp.Tests/desktop/ShadowCopyFixture.cs index dd3fdbaab..34719635e 100644 --- a/LibGit2Sharp.Tests/desktop/ShadowCopyFixture.cs +++ b/LibGit2Sharp.Tests/desktop/ShadowCopyFixture.cs @@ -55,7 +55,7 @@ public void CanProbeForNativeBinariesFromAShadowCopiedAssembly() // ...that the assembly in the other domain is stored in the shadow copy cache... string cachedAssembliesPath = Path.Combine(setup.CachePath, setup.ApplicationName); - Assert.True(cachedAssemblyLocation.StartsWith(cachedAssembliesPath)); + Assert.StartsWith(cachedAssembliesPath, cachedAssemblyLocation); if (!Constants.IsRunningOnUnix) { diff --git a/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs b/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs index d55785baa..950b6fc85 100644 --- a/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs +++ b/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs @@ -117,7 +117,7 @@ public void CanUseCredentials(string scheme, string url, string user, string pas // Perform the actual fetch Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto, - CredentialsProvider = (_user, _valid, _hostname) => new UsernamePasswordCredentials() { Username = "libgit3", Password = "libgit3" }, + CredentialsProvider = (_user, _valid, _hostname) => new UsernamePasswordCredentials() { Username = user, Password = pass }, }, null); // Verify the expected diff --git a/LibGit2Sharp/CodeGenerator.targets b/LibGit2Sharp/CodeGenerator.targets index 845f3cf03..a317d9261 100644 --- a/LibGit2Sharp/CodeGenerator.targets +++ b/LibGit2Sharp/CodeGenerator.targets @@ -13,19 +13,14 @@ - - - - - - + namespace LibGit2Sharp.Core { internal static class NativeDllName { - public const string Name = "$(libgit2FileName)"%3b + public const string Name = "$(libgit2_filename)"%3b } } @@ -65,32 +60,27 @@ - - - - - + - + - - - - + + unknown + $(GitCommitId) namespace LibGit2Sharp { internal static class AssemblyCommitIds { - public const string LibGit2CommitSha = "$(libgit2hash)"%3b - public const string LibGit2SharpCommitSha = "$(GitCommitId)"%3b + public const string LibGit2CommitSha = "$(libgit2_hash)"%3b + public const string LibGit2SharpCommitSha = "$(LibGit2SharpCommitSha)"%3b } } diff --git a/LibGit2Sharp/Core/ArrayMarshaler.cs b/LibGit2Sharp/Core/ArrayMarshaler.cs index 13a50c1ad..4a37d241b 100644 --- a/LibGit2Sharp/Core/ArrayMarshaler.cs +++ b/LibGit2Sharp/Core/ArrayMarshaler.cs @@ -13,7 +13,7 @@ public ArrayMarshaler(T[] objs) for (var i = 0; i < objs.Length; i++) { - IntPtr ptr = Marshal.AllocHGlobal(MarshalPortable.SizeOf()); + IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf()); ptrs[i] = ptr; Marshal.StructureToPtr(objs[i], ptr, false); } diff --git a/LibGit2Sharp/Core/GitOdbBackend.cs b/LibGit2Sharp/Core/GitOdbBackend.cs index a3f5777fe..a83c7d424 100644 --- a/LibGit2Sharp/Core/GitOdbBackend.cs +++ b/LibGit2Sharp/Core/GitOdbBackend.cs @@ -8,7 +8,7 @@ internal struct GitOdbBackend { static GitOdbBackend() { - GCHandleOffset = MarshalPortable.OffsetOf(nameof(GCHandle)).ToInt32(); + GCHandleOffset = Marshal.OffsetOf(nameof(GCHandle)).ToInt32(); } public uint Version; diff --git a/LibGit2Sharp/Core/GitOdbBackendStream.cs b/LibGit2Sharp/Core/GitOdbBackendStream.cs index d2771f598..5e51baabe 100644 --- a/LibGit2Sharp/Core/GitOdbBackendStream.cs +++ b/LibGit2Sharp/Core/GitOdbBackendStream.cs @@ -15,7 +15,7 @@ internal class GitOdbBackendStream { static GitOdbBackendStream() { - GCHandleOffset = MarshalPortable.OffsetOf(nameof(GCHandle)).ToInt32(); + GCHandleOffset = Marshal.OffsetOf(nameof(GCHandle)).ToInt32(); } public IntPtr Backend; diff --git a/LibGit2Sharp/Core/GitSmartSubtransport.cs b/LibGit2Sharp/Core/GitSmartSubtransport.cs index 9c545d3c0..b0a321635 100644 --- a/LibGit2Sharp/Core/GitSmartSubtransport.cs +++ b/LibGit2Sharp/Core/GitSmartSubtransport.cs @@ -8,7 +8,7 @@ internal class GitSmartSubtransport { static GitSmartSubtransport() { - GCHandleOffset = MarshalPortable.OffsetOf(nameof(GCHandle)).ToInt32(); + GCHandleOffset = Marshal.OffsetOf(nameof(GCHandle)).ToInt32(); } public action_callback Action; diff --git a/LibGit2Sharp/Core/GitSmartSubtransportStream.cs b/LibGit2Sharp/Core/GitSmartSubtransportStream.cs index 90853b415..4bf531e82 100644 --- a/LibGit2Sharp/Core/GitSmartSubtransportStream.cs +++ b/LibGit2Sharp/Core/GitSmartSubtransportStream.cs @@ -8,7 +8,7 @@ internal class GitSmartSubtransportStream { static GitSmartSubtransportStream() { - GCHandleOffset = MarshalPortable.OffsetOf(nameof(GCHandle)).ToInt32(); + GCHandleOffset = Marshal.OffsetOf(nameof(GCHandle)).ToInt32(); } public IntPtr SmartTransport; diff --git a/LibGit2Sharp/Core/MarshalPortable.cs b/LibGit2Sharp/Core/MarshalPortable.cs deleted file mode 100644 index 034675004..000000000 --- a/LibGit2Sharp/Core/MarshalPortable.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace LibGit2Sharp.Core -{ - internal static class MarshalPortable - { - internal static int SizeOf() - { -#if NET40 - return Marshal.SizeOf(typeof(T)); -#else - return Marshal.SizeOf(); -#endif - } - - internal static IntPtr OffsetOf(string fieldName) - { -#if NET40 - return Marshal.OffsetOf(typeof(T), fieldName); -#else - return Marshal.OffsetOf(fieldName); -#endif - } - - internal static T PtrToStructure(IntPtr ptr) - { -#if NET40 - return (T)Marshal.PtrToStructure(ptr, typeof(T)); -#else - return Marshal.PtrToStructure(ptr); -#endif - } - } -} diff --git a/LibGit2Sharp/Core/Platform.cs b/LibGit2Sharp/Core/Platform.cs index 19aed7ccb..a07d5172e 100644 --- a/LibGit2Sharp/Core/Platform.cs +++ b/LibGit2Sharp/Core/Platform.cs @@ -1,5 +1,4 @@ using System; -using System.IO; using System.Runtime.InteropServices; namespace LibGit2Sharp.Core @@ -13,68 +12,29 @@ internal enum OperatingSystemType internal static class Platform { - private static Lazy _operatingSystem = new Lazy( - DetermineOperatingSystem, - System.Threading.LazyThreadSafetyMode.PublicationOnly); + public static string ProcessorArchitecture => IntPtr.Size == 8 ? "x64" : "x86"; - public static string ProcessorArchitecture + public static OperatingSystemType OperatingSystem { - get { return IntPtr.Size == 8 ? "x64" : "x86"; } - } - - public static OperatingSystemType OperatingSystem => _operatingSystem.Value; - - private static OperatingSystemType DetermineOperatingSystem() - { -#if DESKTOP - // See http://www.mono-project.com/docs/faq/technical/#how-to-detect-the-execution-platform - switch ((int)Environment.OSVersion.Platform) + get { - case 4: - case 128: + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return OperatingSystemType.Windows; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { return OperatingSystemType.Unix; + } - case 6: + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { return OperatingSystemType.MacOSX; + } - default: - return OperatingSystemType.Windows; - } -#else - try - { - return OperatingSystem_CoreFxStyle(); - } - catch (FileNotFoundException) - { - // We're probably running on .NET 4.6.1 or earlier where the API isn't available. - // This would suggest we're running on Windows. Although if our portable library - // is being used on mono, it could be *nix or OSX too. - return OperatingSystemType.Windows; - } -#endif - } - -#if !DESKTOP - private static OperatingSystemType OperatingSystem_CoreFxStyle() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return OperatingSystemType.Windows; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - return OperatingSystemType.Unix; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return OperatingSystemType.MacOSX; - } - else - { throw new InvalidOperationException(); } } -#endif } } diff --git a/LibGit2Sharp/Filter.cs b/LibGit2Sharp/Filter.cs index 723b50359..1fd0587e5 100644 --- a/LibGit2Sharp/Filter.cs +++ b/LibGit2Sharp/Filter.cs @@ -261,8 +261,8 @@ int StreamCreateCallback(out IntPtr git_writestream_out, GitFilter self, IntPtr Marshal.StructureToPtr(state.thisStream, state.thisPtr, false); state.nextPtr = git_writestream_next; - state.nextStream = MarshalPortable.PtrToStructure(state.nextPtr); - + state.nextStream = Marshal.PtrToStructure(state.nextPtr); + state.filterSource = FilterSource.FromNativePtr(filterSourcePtr); state.output = new WriteStream(state.nextStream, state.nextPtr); @@ -270,7 +270,7 @@ int StreamCreateCallback(out IntPtr git_writestream_out, GitFilter self, IntPtr if (!activeStreams.TryAdd(state.thisPtr, state)) { - // AFAICT this is a theoretical error that could only happen if we manage + // AFAICT this is a theoretical error that could only happen if we manage // to free the stream pointer but fail to remove the dictionary entry. throw new InvalidOperationException("Overlapping stream pointers"); } diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs index eef92c07c..3868a671b 100644 --- a/LibGit2Sharp/GlobalSettings.cs +++ b/LibGit2Sharp/GlobalSettings.cs @@ -23,7 +23,6 @@ static GlobalSettings() { if (Platform.OperatingSystem == OperatingSystemType.Windows) { -#if DESKTOP /* Assembly.CodeBase is not actually a correctly formatted * URI. It's merely prefixed with `file:///` and has its * backslashes flipped. This is superior to EscapedCodeBase, @@ -45,9 +44,6 @@ static GlobalSettings() } managedPath = Path.GetDirectoryName(managedPath); -#else - string managedPath = AppContext.BaseDirectory; -#endif nativeLibraryPath = Path.Combine(managedPath, "lib", "win32"); } diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 0b37bf6af..a9bbb7499 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -1,7 +1,7 @@  - net40;netstandard2.0 + netstandard2.0 true LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .Net and Mono. LibGit2Sharp contributors @@ -9,10 +9,9 @@ libgit2 git https://github.com/libgit2/libgit2sharp/ LibGit2Sharp contributors + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb true ..\libgit2sharp.snk - true - $(DefineConstants);DESKTOP @@ -33,9 +32,10 @@ - - - + + + + diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs index 1f42d82dc..379d3e048 100644 --- a/LibGit2Sharp/ObjectDatabase.cs +++ b/LibGit2Sharp/ObjectDatabase.cs @@ -239,7 +239,7 @@ private unsafe Blob CreateBlob(Stream stream, string hintpath, long? numberOfByt } IntPtr writestream_ptr = Proxy.git_blob_create_fromstream(repo.Handle, hintpath); - GitWriteStream writestream = MarshalPortable.PtrToStructure(writestream_ptr); + GitWriteStream writestream = Marshal.PtrToStructure(writestream_ptr); try { diff --git a/appveyor.yml b/appveyor.yml index e8dbeaab5..8cb01abab 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -90,16 +90,16 @@ test_script: { .\packages\OpenCover\tools\OpenCover.Console.exe ` -register:user ` - "-target:""$Env:userprofile\.nuget\packages\xunit.runner.console\2.2.0\tools\$runner""" ` - "-targetargs:""$Env:APPVEYOR_BUILD_FOLDER\bin\LibGit2Sharp.Tests\Release\net46\LibGit2Sharp.Tests.dll"" -noshadow" ` + "-target:""$Env:userprofile\.nuget\packages\xunit.runner.console\2.3.1\tools\net452\$runner""" ` + "-targetargs:""$Env:APPVEYOR_BUILD_FOLDER\bin\LibGit2Sharp.Tests\Release\net461\LibGit2Sharp.Tests.dll"" -noshadow" ` "-filter:+[LibGit2Sharp]* -[LibGit2Sharp.Tests]*" ` -hideskipped:All ` -output:opencoverCoverage.xml } ElseIf ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $False) { - & "$Env:userprofile\.nuget\packages\xunit.runner.console\2.2.0\tools\$runner" ` - "$Env:APPVEYOR_BUILD_FOLDER\bin\LibGit2Sharp.Tests\Release\net46\LibGit2Sharp.Tests.dll" -noshadow + & "$Env:userprofile\.nuget\packages\xunit.runner.console\2.3.1\tools\net452\$runner" ` + "$Env:APPVEYOR_BUILD_FOLDER\bin\LibGit2Sharp.Tests\Release\net461\LibGit2Sharp.Tests.dll" -noshadow } } diff --git a/buildandtest.cmd b/buildandtest.cmd index b99f4d08e..d1b114076 100644 --- a/buildandtest.cmd +++ b/buildandtest.cmd @@ -31,7 +31,7 @@ dotnet build "%~dp0\" /v:minimal /nologo /property:ExtraDefine="%EXTRADEFINE%" @IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% :: Run tests on Desktop and CoreCLR -"%userprofile%\.nuget\packages\xunit.runner.console\2.2.0\tools\xunit.console.exe" "%~dp0bin\LibGit2Sharp.Tests\%Configuration%\net46\LibGit2Sharp.Tests.dll" -noshadow +"%userprofile%\.nuget\packages\xunit.runner.console\2.3.1\tools\net452\xunit.console.exe" "%~dp0bin\LibGit2Sharp.Tests\%Configuration%\net461\LibGit2Sharp.Tests.dll" -noshadow @IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% dotnet test "%~dp0LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj" -f netcoreapp2.0 --no-restore --no-build @IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% diff --git a/nuget.config b/nuget.config index 82b40bac5..19d85b78f 100644 --- a/nuget.config +++ b/nuget.config @@ -2,7 +2,5 @@ - -