public async Task AllowsDuplicateIds() { var json = @" { ""NuGet.Core"": [ ""nuget"" ], ""NuGet.Core"": [ ""aspnet"" ], ""nuget.core"": [ ""microsoft"" ] }"; CloudBlob .Setup(x => x.OpenReadAsync(It.IsAny <AccessCondition>())) .ReturnsAsync(() => new MemoryStream(Encoding.UTF8.GetBytes(json))); var output = await Target.ReadLatestIndexedAsync(); Assert.Single(output.Result); Assert.Equal(new[] { "NuGet.Core" }, output.Result.Keys.ToArray()); Assert.Equal(new[] { "aspnet", "microsoft", "nuget" }, output.Result["NuGet.Core"].ToArray()); Assert.Equal(StringComparer.OrdinalIgnoreCase, output.Result.Comparer); Assert.Equal(StringComparer.OrdinalIgnoreCase, output.Result["NuGet.Core"].Comparer); Assert.Equal(ETag, output.AccessCondition.IfMatchETag); TelemetryService.Verify( x => x.TrackReadLatestIndexedOwners( /* packageIdCount: */ 1, It.IsAny <TimeSpan>()), Times.Once); }
public async Task IgnoresEmptyOwnerLists() { var json = JsonConvert.SerializeObject(new Dictionary <string, string[]> { { "NoOwners", new string[0] }, { "NuGet.Core", new[] { "nuget" } }, }); CloudBlob .Setup(x => x.OpenReadAsync(It.IsAny <AccessCondition>())) .ReturnsAsync(() => new MemoryStream(Encoding.UTF8.GetBytes(json))); var output = await Target.ReadLatestIndexedAsync(); Assert.Single(output.Result); Assert.Equal(new[] { "NuGet.Core" }, output.Result.Keys.ToArray()); Assert.Equal(new[] { "nuget" }, output.Result["NuGet.Core"].ToArray()); Assert.Equal(StringComparer.OrdinalIgnoreCase, output.Result.Comparer); Assert.Equal(StringComparer.OrdinalIgnoreCase, output.Result["NuGet.Core"].Comparer); Assert.Equal(ETag, output.AccessCondition.IfMatchETag); TelemetryService.Verify( x => x.TrackReadLatestIndexedOwners( /* packageIdCount: */ 1, It.IsAny <TimeSpan>()), Times.Once); }
public async Task ReadsOwners() { var json = JsonConvert.SerializeObject(new Dictionary <string, string[]> { { "nuget.versioning", new[] { "nuget", "Microsoft" } }, { "EntityFramework", new[] { "Microsoft", "aspnet", "EntityFramework" } }, { "NuGet.Core", new[] { "nuget" } }, { "ZDuplicate", new[] { "ownerA", "ownera", "OWNERA", "ownerB" } }, }); CloudBlob .Setup(x => x.OpenReadAsync(It.IsAny <AccessCondition>())) .ReturnsAsync(() => new MemoryStream(Encoding.UTF8.GetBytes(json))); var output = await Target.ReadLatestIndexedAsync(); Assert.Equal(4, output.Result.Count); Assert.Equal(new[] { "EntityFramework", "NuGet.Core", "nuget.versioning", "ZDuplicate" }, output.Result.Keys.ToArray()); Assert.Equal(new[] { "aspnet", "EntityFramework", "Microsoft" }, output.Result["EntityFramework"].ToArray()); Assert.Equal(new[] { "nuget" }, output.Result["NuGet.Core"].ToArray()); Assert.Equal(new[] { "Microsoft", "nuget" }, output.Result["nuget.versioning"].ToArray()); Assert.Equal(new[] { "ownerA", "ownerB" }, output.Result["ZDuplicate"].ToArray()); Assert.Equal(StringComparer.OrdinalIgnoreCase, output.Result.Comparer); Assert.Equal(StringComparer.OrdinalIgnoreCase, output.Result["EntityFramework"].Comparer); Assert.Equal(StringComparer.OrdinalIgnoreCase, output.Result["NuGet.Core"].Comparer); Assert.Equal(StringComparer.OrdinalIgnoreCase, output.Result["nuget.versioning"].Comparer); Assert.Equal(StringComparer.OrdinalIgnoreCase, output.Result["ZDuplicate"].Comparer); Assert.Equal(ETag, output.AccessCondition.IfMatchETag); CloudBlobContainer.Verify(x => x.GetBlobReference("owners/owners.v2.json"), Times.Once); TelemetryService.Verify( x => x.TrackReadLatestIndexedOwners( /* packageIdCount: */ 4, It.IsAny <TimeSpan>()), Times.Once); }
public async Task AllowsEmptyObject() { var json = JsonConvert.SerializeObject(new Dictionary <string, string[]>()); CloudBlob .Setup(x => x.OpenReadAsync(It.IsAny <AccessCondition>())) .ReturnsAsync(() => new MemoryStream(Encoding.UTF8.GetBytes(json))); var output = await Target.ReadLatestIndexedAsync(); Assert.Empty(output.Result); Assert.Equal(ETag, output.AccessCondition.IfMatchETag); TelemetryService.Verify( x => x.TrackReadLatestIndexedOwners( /* packageIdCount: */ 0, It.IsAny <TimeSpan>()), Times.Once); }
public async Task AllowsMissingBlob() { CloudBlob .Setup(x => x.OpenReadAsync(It.IsAny <AccessCondition>())) .ThrowsAsync(new StorageException( new RequestResult { HttpStatusCode = (int)HttpStatusCode.NotFound, }, message: "Not found.", inner: null)); var output = await Target.ReadLatestIndexedAsync(); Assert.Empty(output.Result); Assert.Equal("*", output.AccessCondition.IfNoneMatchETag); TelemetryService.Verify( x => x.TrackReadLatestIndexedOwners( /* packageIdCount: */ 0, It.IsAny <TimeSpan>()), Times.Once); }
public async Task SerializesVersionsSortedOrder() { var newData = new SortedDictionary <string, SortedSet <string> >(StringComparer.OrdinalIgnoreCase) { { "nuget.versioning", new SortedSet <string>(StringComparer.OrdinalIgnoreCase) { "nuget", "Microsoft" } }, { "ZDuplicate", new SortedSet <string>(StringComparer.OrdinalIgnoreCase) { "ownerA", "ownera", "OWNERA", "ownerB" } }, { "EntityFramework", new SortedSet <string>(StringComparer.OrdinalIgnoreCase) { "Microsoft", "aspnet", "EntityFramework" } }, { "NuGet.Core", new SortedSet <string>(StringComparer.OrdinalIgnoreCase) { "nuget" } }, }; await Target.ReplaceLatestIndexedAsync(newData, AccessCondition.Object); // Pretty-ify the JSON to make the assertion clearer. var json = Assert.Single(SavedStrings); json = JsonConvert.DeserializeObject <JObject>(json).ToString(); Assert.Equal(@"{ ""EntityFramework"": [ ""aspnet"", ""EntityFramework"", ""Microsoft"" ], ""NuGet.Core"": [ ""nuget"" ], ""nuget.versioning"": [ ""Microsoft"", ""nuget"" ], ""ZDuplicate"": [ ""ownerA"", ""ownerB"" ] }", json); TelemetryService.Verify( x => x.TrackReplaceLatestIndexedOwners( /*packageIdCount: */ 4), Times.Once); ReplaceLatestIndexedOwnersDurationMetric.Verify(x => x.Dispose(), Times.Once); }