Skip to content
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

Fix unit test failed due to localized culture and line ending (#7779) #8021

Merged
merged 4 commits into from
Jun 5, 2020

Conversation

lyndaidaii
Copy link
Contributor

Summary of the changes:

  • Change to Assert.StartWith instead of Assert.Equal, avoid checking localized 'parameter'
  • Add new class called 'UseInvariantCultureAttribute', change thread UI culture before test, and reset
    after test
  • Addressed those unit test: 1.NuGetGallery.Packaging.PackageMetadataFacts.ThrowsForEmptyAndNonEmptyDuplicatesWhenDuplicateMetadataElementsDetectedAndParsingIsNotStrict
  1. NuGetGallery.Packaging.PackageMetadataFacts.ThrowsWhenInvalidMinClientVersion
    3.NuGetGallery.PackagesControllerFacts+TheUploadFileActionForPostRequests.WillRejectBrokenZipFiles NuGetGallery.PackagesControllerFacts+TheUploadFileActionForPostRequests.WillShowViewWithErrorsIfPackageIdIsBreaksParsing
    4.NuGetGallery.Authentication.AuthenticationServiceFacts+TheAuthenticateMethod.GivenPasswordCredential_ItThrowsArgumentException
    5.NuGetGallery.Diagnostics.DiagnosticsServiceFacts+TheGetSourceMethod.RequiresNonNullOrEmptyName
    6.NuGetGallery.Services.ContentServiceFacts+TheGetContentItemMethod.GivenANullOrEmptyName_ItShouldThrow

Addresses #123

var packageStream = CreateTestPackageStreamWithDuplicateEmptyAndNonEmptyMetadataElements();
var nupkg = new PackageArchiveReader(packageStream, leaveStreamOpen: false);
var nuspec = nupkg.GetNuspecReader();

useInvariantCultureAttr.Before(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@agr agr Jun 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely shouldn't instantiate the attribute class directly. It already contains all necessary setup, just use [UseInvariantCulture] attribute on appropriate test methods.

@@ -215,7 +218,7 @@ public void ThrowsWhenInvalidMinClientVersion(bool strict)

// Act & Assert
var ex = Assert.Throws<ArgumentException>(() => PackageMetadata.FromNuspecReader(nuspec, strict));
Assert.Equal("'bad' is not a valid version string.\r\nParameter name: value", ex.Message);
Assert.StartsWith("'bad' is not a valid version string.", ex.Message);
Copy link
Contributor

@agr agr Jun 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an additional explicit check for parameter name (that was implicit in old version): Assert.Equal("value", ex.ParamName) here and in other cases.

Copy link
Contributor

@agr agr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add explicit parameter name asserts in all cases where Assert.StartsWith was introduced and add use UseInvariantCultureAttribute as an actual attribute.

{
private CultureInfo originalUICulture;

public CultureInfo OriginalUICulture { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is used anywhere, If not can it be removed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants