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

remove redundant Wheres #10017

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ private PackageFrameworkCompatibilityData GetBadgeFramework(IReadOnlyDictionary<
if (table.TryGetValue(productName, out var data))
{
return data
.Where(d => includeComputed || !d.IsComputed)
.FirstOrDefault();
.FirstOrDefault(d => includeComputed || !d.IsComputed);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public ActionResult CorrectIsLatestPackages()
{
Id = pr.Id,
Version = pr.Packages
.Where(p => p.IsLatest || p.IsLatestStable || p.IsLatestSemVer2 || p.IsLatestStableSemVer2)
.FirstOrDefault()
.FirstOrDefault(p => p.IsLatest || p.IsLatestStable || p.IsLatestSemVer2 || p.IsLatestStableSemVer2)
.Version,
IsLatestCount = pr.Packages.Where(p => p.IsLatest).Count(),
IsLatestStableCount = pr.Packages.Where(p => p.IsLatestStable).Count(),
Expand Down
15 changes: 5 additions & 10 deletions src/NuGetGallery/Areas/Admin/Services/ValidationAdminService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ public PackageDeletedStatus GetPackageDeletedStatus(int packageKey)
{
var package = _packages
.GetAll()
.Where(x => x.Key == packageKey)
.FirstOrDefault();
.FirstOrDefault(x => x.Key == packageKey);

if (package == null)
{
Expand All @@ -167,8 +166,7 @@ public PackageDeletedStatus GetSymbolPackageDeletedStatus(int symbolPackageKey)
{
var symbolPackage = _symbolPackages
.GetAll()
.Where(x => x.Key == symbolPackageKey)
.FirstOrDefault();
.FirstOrDefault(x => x.Key == symbolPackageKey);

if (symbolPackage == null)
{
Expand All @@ -189,8 +187,7 @@ private void SearchByValidationSetTrackingId(Dictionary<long, PackageValidationS
var validationSet = _validationSets
.GetAll()
.Include(x => x.PackageValidations)
.Where(x => x.ValidationTrackingId == guid)
.FirstOrDefault();
.FirstOrDefault(x => x.ValidationTrackingId == guid);

if (validationSet != null)
{
Expand All @@ -206,8 +203,7 @@ private void SearchByValidationId(Dictionary<long, PackageValidationSet> validat
var validation = _validations
.GetAll()
.Include(x => x.PackageValidationSet)
.Where(x => x.Key == guid)
.FirstOrDefault();
.FirstOrDefault(x => x.Key == guid);

if (validation != null)
{
Expand All @@ -223,8 +219,7 @@ private void SearchByValidationSetKey(Dictionary<long, PackageValidationSet> val
var validationSet = _validationSets
.GetAll()
.Include(x => x.PackageValidations)
.Where(x => x.Key == integer)
.FirstOrDefault();
.FirstOrDefault(x => x.Key == integer);

if (validationSet != null)
{
Expand Down
3 changes: 1 addition & 2 deletions src/VerifyMicrosoftPackage/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ private async Task<int> ExecuteAsync()

var commitId = _thisAssembly
.GetCustomAttributes<AssemblyMetadataAttribute>()
.Where(x => x.Key == "CommitId")
.FirstOrDefault();
.FirstOrDefault(x => x.Key == "CommitId");
if (commitId != null)
{
_console.WriteLine($"Commit ID: {commitId.Value}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ public FactsBase()
PackageService
.Setup(x => x.FindPackageByIdAndVersionStrict(It.IsAny<string>(), It.IsAny<string>()))
.Returns<string, string>((i, v) => Packages
.Where(x =>
.FirstOrDefault(x =>
x.PackageRegistration.Id.Equals(i, StringComparison.OrdinalIgnoreCase) &&
x.NormalizedVersion.Equals(NuGetVersionFormatter.Normalize(v), StringComparison.OrdinalIgnoreCase))
.FirstOrDefault());
x.NormalizedVersion.Equals(NuGetVersionFormatter.Normalize(v), StringComparison.OrdinalIgnoreCase)));

Target = new AdminControllerBase();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public async Task RemoveNamespaceSuccesfullyDeletesNamespace(string value)
{
// Arrange.
var namespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
var existingNamespace = namespaces.Where(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
var existingNamespace = namespaces.FirstOrDefault(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase));
var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces);
var packageRegistrations = new Mock<IEntityRepository<PackageRegistration>>();
var controller = new ReservedNamespaceController(reservedNamespaceService, packageRegistrations.Object);
Expand All @@ -169,7 +169,7 @@ public async Task AddOwnerDoesNotReturnSuccessForInvalidData(string value, strin
// Arrange.
var namespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
var allUsers = ReservedNamespaceServiceTestData.GetTestUsers();
var existingNamespace = namespaces.Where(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() ?? new ReservedNamespace();
var existingNamespace = namespaces.FirstOrDefault(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase)) ?? new ReservedNamespace();
existingNamespace.Value = value;
var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces, users: allUsers);
var packageRegistrations = new Mock<IEntityRepository<PackageRegistration>>();
Expand All @@ -190,7 +190,7 @@ public async Task AddOwnerSuccessfullyAddsOwnerToReservedNamespace(string value,
// Arrange.
var namespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
var allUsers = ReservedNamespaceServiceTestData.GetTestUsers();
var existingNamespace = namespaces.Where(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
var existingNamespace = namespaces.FirstOrDefault(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase));
var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces, users: allUsers);
var packageRegistrations = new Mock<IEntityRepository<PackageRegistration>>();
var controller = new ReservedNamespaceController(reservedNamespaceService, packageRegistrations.Object);
Expand All @@ -216,7 +216,7 @@ public async Task RemoveOwnerDoesNotReturnSuccessForInvalidData(string value, st
// Arrange.
var namespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
var allUsers = ReservedNamespaceServiceTestData.GetTestUsers();
var existingNamespace = namespaces.Where(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() ?? new ReservedNamespace();
var existingNamespace = namespaces.FirstOrDefault(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase)) ?? new ReservedNamespace();
existingNamespace.Value = value;
var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces, users: allUsers);
var packageRegistrations = new Mock<IEntityRepository<PackageRegistration>>();
Expand All @@ -238,7 +238,7 @@ public async Task RemoveOwnerSuccessfullyRemovesOwnerToReservedNamespace(string
var namespaces = ReservedNamespaceServiceTestData.GetTestNamespaces();
var allUsers = ReservedNamespaceServiceTestData.GetTestUsers();
var testUser = allUsers.First();
var existingNamespace = namespaces.Where(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
var existingNamespace = namespaces.FirstOrDefault(rn => rn.Value.Equals(value, StringComparison.OrdinalIgnoreCase));
existingNamespace.Owners.Add(testUser);
var reservedNamespaceService = new TestableReservedNamespaceService(reservedNamespaces: namespaces, users: allUsers);
var packageRegistrations = new Mock<IEntityRepository<PackageRegistration>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ private Mock<ISupportRequestService> SetupSupportRequestService()
supportService.Setup(m => m.GetIssues(null, null, null, null)).Returns(SupportRequests);
if (_user != null)
{
var issue = SupportRequests.Where(i => string.Equals(i.CreatedBy, _user.Username)).FirstOrDefault();
var issue = SupportRequests.FirstOrDefault(i => string.Equals(i.CreatedBy, _user.Username));
supportService.Setup(m => m.DeleteSupportRequestsAsync(_user))
.Returns(Task.FromResult(true))
.Callback(() => SupportRequests.Remove(issue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public async Task DeleteRequestsNormalPath()
Assert.Equal<int>(2, supportRequestContext.Issues.Count());
Assert.True(supportRequestContext.Issues.Any(issue => string.Equals(issue.CreatedBy, $"{userName}_second")));
Assert.False(supportRequestContext.Issues.Any(issue => string.Equals(issue.IssueTitle, "Joe's OldIssue")));
var deleteRequestIssue = supportRequestContext.Issues.Where(issue => issue.Key == 1).FirstOrDefault();
var deleteRequestIssue = supportRequestContext.Issues.FirstOrDefault(issue => issue.Key == 1);
Assert.NotNull(deleteRequestIssue);
Assert.Equal(deleteRequestIssue.CreatedBy, "_deletedaccount");
Assert.Equal(deleteRequestIssue.IssueStatusId, IssueStatusKeys.Resolved);
Expand Down