Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 1ef0692

Browse files
author
scottbommarito
committed
Merge branch 'master' of https://github.com/NuGet/NuGet.Jobs
2 parents 37fe8c1 + d88d497 commit 1ef0692

4 files changed

Lines changed: 45 additions & 12 deletions

File tree

src/Stats.ImportAzureCdnStatistics/Dimensions/ToolDimension.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
using System;
34

45
namespace Stats.ImportAzureCdnStatistics
56
{
@@ -19,7 +20,9 @@ public ToolDimension(string toolId, string toolVersion, string fileName)
1920

2021
protected bool Equals(ToolDimension other)
2122
{
22-
return string.Equals(ToolId, other.ToolId) && string.Equals(ToolVersion, other.ToolVersion) && string.Equals(FileName, other.FileName);
23+
return string.Equals(ToolId, other.ToolId, StringComparison.OrdinalIgnoreCase)
24+
&& string.Equals(ToolVersion, other.ToolVersion, StringComparison.OrdinalIgnoreCase)
25+
&& string.Equals(FileName, other.FileName, StringComparison.OrdinalIgnoreCase);
2326
}
2427

2528
public override bool Equals(object obj)
@@ -34,9 +37,9 @@ public override int GetHashCode()
3437
{
3538
unchecked
3639
{
37-
var hashCode = (ToolId != null ? ToolId.GetHashCode() : 0);
38-
hashCode = (hashCode*397) ^ (ToolVersion != null ? ToolVersion.GetHashCode() : 0);
39-
hashCode = (hashCode*397) ^ (FileName != null ? FileName.GetHashCode() : 0);
40+
var hashCode = (ToolId != null ? ToolId.ToLower().GetHashCode() : 0);
41+
hashCode = (hashCode*397) ^ (ToolVersion != null ? ToolVersion.ToLower().GetHashCode() : 0);
42+
hashCode = (hashCode*397) ^ (FileName != null ? FileName.ToLower().GetHashCode() : 0);
4043
return hashCode;
4144
}
4245
}

src/Stats.ImportAzureCdnStatistics/Warehouse.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -620,14 +620,7 @@ private async Task<IReadOnlyCollection<ToolDimension>> RetrieveToolDimensions(IR
620620
return results;
621621
}
622622

623-
results.AddRange(_cachedToolDimensions
624-
.Where(p1 => tools
625-
.FirstOrDefault(p2 =>
626-
string.Equals(p1.ToolId, p2.ToolId, StringComparison.OrdinalIgnoreCase)
627-
&& string.Equals(p1.ToolVersion, p2.ToolVersion, StringComparison.OrdinalIgnoreCase)
628-
&& string.Equals(p1.FileName, p2.FileName, StringComparison.OrdinalIgnoreCase)) != null
629-
)
630-
);
623+
results.AddRange(_cachedToolDimensions.Where(p1 => tools.FirstOrDefault(p2 => p2.Equals(p1)) != null));
631624

632625
var nonCachedToolDimensions = tools.Except(results).ToList();
633626

tests/Tests.Stats.ImportAzureCdnStatistics/Tests.Stats.ImportAzureCdnStatistics.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<Compile Include="PackageDimensionFacts.cs" />
101101
<Compile Include="PackageTranslatorFacts.cs" />
102102
<Compile Include="StatisticsParserFacts.cs" />
103+
<Compile Include="ToolDimensionFacts.cs" />
103104
<Compile Include="ToolStatisticsParserFacts.cs" />
104105
<Compile Include="UserAgentParserFacts.cs" />
105106
<Compile Include="Properties\AssemblyInfo.cs" />
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using Stats.ImportAzureCdnStatistics;
8+
using Xunit;
9+
10+
namespace Tests.Stats.ImportAzureCdnStatistics
11+
{
12+
public class ToolDimensionFacts
13+
{
14+
[Theory]
15+
[InlineData("win-x86-commandline", "v3.5.0", "NuGet.exe", "win-x86-commandline", "v3.5.0", "nuget.exe", true)] // Lowercase and uppercase are equal for filename
16+
[InlineData("win-x86-commandline", "v3.5.0", "nuget.exe", "win-x86-commandline", "V3.5.0", "nuget.exe", true)] // Lowercase and uppercase are equal for tool version
17+
[InlineData("WIN-x86-commandline", "v3.5.0", "nuget.exe", "win-x86-commandline", "v3.5.0", "nuget.exe", true)] // Lowercase and uppercase are equal for tool id
18+
[InlineData("win-x86-commandline", "v3.5.0", "NuGet.exe", "win-x86-commandline", "v3.5.0", "NuGet1.exe", false)] // different file name
19+
[InlineData("win-x86-commandline", "v3.5.0", "nuget.exe", "win-x86-commandline", "VV3.5.0", "nuget.exe", false)] // different tool version
20+
[InlineData("win-x86-commandline", "v3.5.0", "nuget.exe", "win-x64-commandline", "v3.5.0", "nuget.exe", false)] // different tool id
21+
public void ComparesToolsDimensionsCorrectly(string toolId1, string toolVersion1, string fileName1,
22+
string toolId2, string toolVersion2, string fileName2, bool expectedResult)
23+
{
24+
var tool1 = new ToolDimension(toolId1, toolVersion1, fileName1);
25+
var tool2 = new ToolDimension(toolId2, toolVersion2, fileName2);
26+
27+
//Act
28+
var actualResultEquals = tool1.Equals(tool2);
29+
var actualResultGetHashCode = tool1.GetHashCode() == tool2.GetHashCode();
30+
31+
// Assert
32+
Assert.Equal(expectedResult, actualResultEquals);
33+
Assert.Equal(expectedResult, actualResultGetHashCode);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)