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

Permissions tests for Edit, Delete, Manage Package Owners, and SetLicenseReportVisibility (UI) #5151

Merged
merged 4 commits into from
Dec 11, 2017

Conversation

scottbommarito
Copy link
Contributor

@scottbommarito scottbommarito commented Dec 7, 2017

For Edit, SetLicenseReportVisibility, and Delete I parametrized the tests so that they now run with every test user.

For Manage Package Owners I added two simple tests to guarantee it displays the form when expected.

@scottbommarito scottbommarito changed the title Permissions tests for Edit, Delete, and Manage Package Owners Permissions tests for Edit, Delete, and Manage Package Owners (UI) Dec 7, 2017
@scottbommarito scottbommarito changed the title Permissions tests for Edit, Delete, and Manage Package Owners (UI) Permissions tests for Edit, Delete, Manage Package Owners, and SetLicenseReportVisibility (UI) Dec 8, 2017
{
get
{
foreach (var ownerData in Owner_Data)
Copy link
Contributor

@agr agr Dec 8, 2017

Choose a reason for hiding this comment

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

Might look better in test explorer if rewritten as LINQ expression body.

Copy link
Contributor

Choose a reason for hiding this comment

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

(well, probably all of those would have to be rewritten as expression bodied properties, probably not worth it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't think it made much of a difference--I thought it just serialized all of the properties of the object regardless of how it was enumerated.

Either case, I'm going to leave this because as you said, it would have to become expression bodied properties.

var result = controller.Delete(_packageRegistration.Id, _package.Version);

Assert.IsType<HttpNotFoundResult>(result);
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: space between methods

public void DisplaysFullVersionStringAndUsesNormalizedVersionsInUrlsInSelectList()
private static string _packageId = "CrestedGecko";
private static PackageRegistration _packageRegistration;
private static Package _package;
Copy link
Member

Choose a reason for hiding this comment

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

I would beware of reusing the same instance of these test objects across tests... in case changes in state could potentially lead to intermittent test failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know some of the other tests had this, but they might not have been static. Will check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed static

Copy link
Member

Choose a reason for hiding this comment

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

Thanks - assuming new instance of test class is created for each test case? i.e., class variables won't be shared?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've seen some tests with this existing pattern (ReportMyPackage for example). Also, if there was any sort of concurrency issue here, I would expect my tests to have failed when I tested them.

Reason = "Other",
Signature = "John Doe"
};
yield return new object[]
Copy link
Member

Choose a reason for hiding this comment

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

This has a similar pattern to other tests you added that take (currentUser, owner). Did we add a helper in that case to simplify the code?

yield return MemberDataHelpers.UserOnBehalfOfAccount(TestUtility.FakeUser, new User { Key = 5535 });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Helper was added, but because this is a feature branch and I don't want to deal with any annoying rebasing, I was planning on integrating it with the tests that don't have it in a later PR.

private static string _packageId = "CrestedGecko";
private static string _packageVersion = "3.4.2";

private static Package _package = new Package
Copy link
Member

Choose a reason for hiding this comment

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

Beware of reusing this instance across tests. Consider if the test cases run in parallel, or depend on state which changes.

@scottbommarito
Copy link
Contributor Author

@chenriksson I fixed your comments!


[Theory]
[MemberData(nameof(NotOwner_Data))]
public async Task Returns401IfNotOwner(User currentUser, User owner, bool visible)
Copy link
Member

Choose a reason for hiding this comment

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

How is visible used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be passed into SetLicenseReportVisibility--updated to do this

var result = await controller.SetLicenseReportVisibility("Foo", "1.0", visible: false, urlFactory: (pkg, relativeUrl) => @"~\Bar.cshtml");

// Assert
Assert.IsType<HttpStatusCodeResult>(result);
Copy link
Member

Choose a reason for hiding this comment

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

When there is a 401 assertion, we should also verify the dependency (e.g. DB) is not being changed. Applies to all tests here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Upon further investigation, in this particular test, it is already verified because the package service is a strict mock. I do need to analyze the rest of the tests however.

Copy link
Member

@joelverhagen joelverhagen left a comment

Choose a reason for hiding this comment

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

Address comments then :shipit: .

@scottbommarito scottbommarito merged commit 7b5ac95 into sb-feature-orgpermissions Dec 11, 2017
@scottbommarito scottbommarito deleted the sb-test-manage-edit-delete branch December 11, 2017 23:50
scottbommarito pushed a commit that referenced this pull request Dec 21, 2017
scottbommarito pushed a commit that referenced this pull request Dec 21, 2017
scottbommarito pushed a commit that referenced this pull request Dec 21, 2017
scottbommarito pushed a commit that referenced this pull request Jan 2, 2018
scottbommarito pushed a commit that referenced this pull request Jan 2, 2018
scottbommarito pushed a commit that referenced this pull request Jan 8, 2018
@scottbommarito scottbommarito restored the sb-test-manage-edit-delete branch July 22, 2019 23:18
@scottbommarito scottbommarito deleted the sb-test-manage-edit-delete branch July 22, 2019 23:19
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.

4 participants