-
Notifications
You must be signed in to change notification settings - Fork 899
Resolve FilterFixture NRE #1113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.IO; | ||
using LibGit2Sharp.Tests.TestHelpers; | ||
using Xunit; | ||
|
@@ -26,7 +27,7 @@ public void CanRegisterFilterWithSingleAttribute() | |
[Fact] | ||
public void CanRegisterAndUnregisterTheSameFilter() | ||
{ | ||
var filter = new EmptyFilter(FilterName + 1, attributes); | ||
var filter = new EmptyFilter(FilterName, attributes); | ||
|
||
var registration = GlobalSettings.RegisterFilter(filter); | ||
GlobalSettings.DeregisterFilter(registration); | ||
|
@@ -38,8 +39,7 @@ public void CanRegisterAndUnregisterTheSameFilter() | |
[Fact] | ||
public void CanRegisterAndDeregisterAfterGarbageCollection() | ||
{ | ||
var filter = new EmptyFilter(FilterName + 2, attributes); | ||
var filterRegistration = GlobalSettings.RegisterFilter(filter); | ||
var filterRegistration = GlobalSettings.RegisterFilter(new EmptyFilter(FilterName, attributes)); | ||
|
||
GC.Collect(); | ||
|
||
|
@@ -49,7 +49,7 @@ public void CanRegisterAndDeregisterAfterGarbageCollection() | |
[Fact] | ||
public void SameFilterIsEqual() | ||
{ | ||
var filter = new EmptyFilter(FilterName + 3, attributes); | ||
var filter = new EmptyFilter(FilterName, attributes); | ||
Assert.Equal(filter, filter); | ||
} | ||
|
||
|
@@ -62,16 +62,16 @@ public void InitCallbackNotMadeWhenFilterNeverUsed() | |
called = true; | ||
}; | ||
|
||
var filter = new FakeFilter(FilterName + 11, attributes, | ||
successCallback, | ||
successCallback, | ||
initializeCallback); | ||
|
||
var filterRegistration = GlobalSettings.RegisterFilter(filter); | ||
var filter = new FakeFilter(FilterName, | ||
attributes, | ||
successCallback, | ||
successCallback, | ||
initializeCallback); | ||
var registration = GlobalSettings.RegisterFilter(filter); | ||
|
||
Assert.False(called); | ||
|
||
GlobalSettings.DeregisterFilter(filterRegistration); | ||
GlobalSettings.DeregisterFilter(registration); | ||
} | ||
|
||
[Fact] | ||
|
@@ -83,12 +83,12 @@ public void InitCallbackMadeWhenUsingTheFilter() | |
called = true; | ||
}; | ||
|
||
var filter = new FakeFilter(FilterName + 12, attributes, | ||
successCallback, | ||
successCallback, | ||
initializeCallback); | ||
|
||
var filterRegistration = GlobalSettings.RegisterFilter(filter); | ||
var filter = new FakeFilter(FilterName, | ||
attributes, | ||
successCallback, | ||
successCallback, | ||
initializeCallback); | ||
var registration = GlobalSettings.RegisterFilter(filter); | ||
Assert.False(called); | ||
|
||
string repoPath = InitNewRepository(); | ||
|
@@ -98,7 +98,7 @@ public void InitCallbackMadeWhenUsingTheFilter() | |
Assert.True(called); | ||
} | ||
|
||
GlobalSettings.DeregisterFilter(filterRegistration); | ||
GlobalSettings.DeregisterFilter(registration); | ||
} | ||
|
||
[Fact] | ||
|
@@ -112,17 +112,17 @@ public void WhenStagingFileApplyIsCalledWithCleanForCorrectPath() | |
called = true; | ||
reader.CopyTo(writer); | ||
}; | ||
var filter = new FakeFilter(FilterName + 15, attributes, clean); | ||
|
||
var filterRegistration = GlobalSettings.RegisterFilter(filter); | ||
var filter = new FakeFilter(FilterName, attributes, clean); | ||
var registration = GlobalSettings.RegisterFilter(filter); | ||
|
||
using (var repo = CreateTestRepository(repoPath)) | ||
{ | ||
StageNewFile(repo); | ||
Assert.True(called); | ||
} | ||
|
||
GlobalSettings.DeregisterFilter(filterRegistration); | ||
GlobalSettings.DeregisterFilter(registration); | ||
} | ||
|
||
[Fact] | ||
|
@@ -135,22 +135,20 @@ public void CleanFilterWritesOutputToObjectTree() | |
|
||
Action<Stream, Stream> cleanCallback = SubstitutionCipherFilter.RotateByThirteenPlaces; | ||
|
||
var filter = new FakeFilter(FilterName + 16, attributes, cleanCallback); | ||
|
||
var filterRegistration = GlobalSettings.RegisterFilter(filter); | ||
var filter = new FakeFilter(FilterName, attributes, cleanCallback); | ||
var registration = GlobalSettings.RegisterFilter(filter); | ||
|
||
using (var repo = CreateTestRepository(repoPath)) | ||
{ | ||
FileInfo expectedFile = StageNewFile(repo, decodedInput); | ||
var commit = repo.Commit("Clean that file"); | ||
|
||
var blob = (Blob)commit.Tree[expectedFile.Name].Target; | ||
|
||
var textDetected = blob.GetContentText(); | ||
Assert.Equal(encodedInput, textDetected); | ||
} | ||
|
||
GlobalSettings.DeregisterFilter(filterRegistration); | ||
GlobalSettings.DeregisterFilter(registration); | ||
} | ||
|
||
[Fact] | ||
|
@@ -164,16 +162,16 @@ public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory() | |
|
||
Action<Stream, Stream> smudgeCallback = SubstitutionCipherFilter.RotateByThirteenPlaces; | ||
|
||
var filter = new FakeFilter(FilterName + 17, attributes, null, smudgeCallback); | ||
var filterRegistration = GlobalSettings.RegisterFilter(filter); | ||
var filter = new FakeFilter(FilterName, attributes, null, smudgeCallback); | ||
var registration = GlobalSettings.RegisterFilter(filter); | ||
|
||
FileInfo expectedFile = CheckoutFileForSmudge(repoPath, branchName, encodedInput); | ||
|
||
string combine = Path.Combine(repoPath, "..", expectedFile.Name); | ||
string readAllText = File.ReadAllText(combine); | ||
Assert.Equal(decodedInput, readAllText); | ||
|
||
GlobalSettings.DeregisterFilter(filterRegistration); | ||
GlobalSettings.DeregisterFilter(registration); | ||
} | ||
|
||
[Fact] | ||
|
@@ -186,8 +184,8 @@ public void CanFilterLargeFiles() | |
|
||
string repoPath = InitNewRepository(); | ||
|
||
var filter = new FileExportFilter("exportFilter", attributes); | ||
var filterRegistration = GlobalSettings.RegisterFilter(filter); | ||
var filter = new FileExportFilter(FilterName, attributes); | ||
var registration = GlobalSettings.RegisterFilter(filter); | ||
|
||
string filePath = Path.Combine(Directory.GetParent(repoPath).Parent.FullName, Guid.NewGuid().ToString() + ".blob"); | ||
FileInfo contentFile = new FileInfo(filePath); | ||
|
@@ -233,7 +231,31 @@ public void CanFilterLargeFiles() | |
|
||
contentFile.Delete(); | ||
|
||
GlobalSettings.DeregisterFilter(filterRegistration); | ||
GlobalSettings.DeregisterFilter(registration); | ||
} | ||
|
||
[Fact] | ||
public void DoubleRegistrationFailsButDoubleDeregistrationDoesNot() | ||
{ | ||
Assert.Equal(0, GlobalSettings.GetRegisteredFilters().Count()); | ||
|
||
var filter = new EmptyFilter(FilterName, attributes); | ||
var registration = GlobalSettings.RegisterFilter(filter); | ||
|
||
Assert.Throws<EntryExistsException>(() => { GlobalSettings.RegisterFilter(filter); }); | ||
Assert.Equal(1, GlobalSettings.GetRegisteredFilters().Count()); | ||
|
||
Assert.True(registration.IsValid, "FilterRegistration.IsValid should be true."); | ||
|
||
GlobalSettings.DeregisterFilter(registration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a Assert.False(registration.isValid); |
||
Assert.Equal(0, GlobalSettings.GetRegisteredFilters().Count()); | ||
|
||
Assert.False(registration.IsValid, "FilterRegistration.IsValid should be false."); | ||
|
||
GlobalSettings.DeregisterFilter(registration); | ||
Assert.Equal(0, GlobalSettings.GetRegisteredFilters().Count()); | ||
|
||
Assert.False(registration.IsValid, "FilterRegistration.IsValid should be false."); | ||
} | ||
|
||
private unsafe bool CharArrayAreEqual(char[] array1, char[] array2, int count) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a