|
1 | 1 | // Copyright (c) .NET Foundation. All rights reserved. |
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
3 | 3 |
|
4 | | -using System; |
5 | | -using System.Collections.Generic; |
6 | | -using System.Threading; |
7 | | -using System.Threading.Tasks; |
8 | 4 | using Microsoft.Extensions.Logging; |
9 | 5 | using Moq; |
10 | | -using NuGet.Services.Metadata.Catalog; |
11 | 6 | using NuGet.Services.Metadata.Catalog.Dnx; |
12 | | -using NuGet.Services.Metadata.Catalog.Persistence; |
13 | 7 | using Xunit; |
14 | 8 |
|
15 | 9 | namespace CatalogTests.Dnx |
16 | 10 | { |
17 | 11 | public class DnxPackageVersionIndexCacheControlTests |
18 | 12 | { |
19 | | - [Fact] |
20 | | - public async Task LoadPackageIdsToIncludeAsync_BlobDoesNotExist() |
21 | | - { |
22 | | - var storage = new Mock<IStorage>(); |
23 | | - storage.Setup(s => s.Exists(It.IsAny<string>())).Returns(false); |
24 | | - |
25 | | - DnxPackageVersionIndexCacheControl.PackageIdsToInclude = new HashSet<string>(); |
26 | | - |
27 | | - await DnxPackageVersionIndexCacheControl.LoadPackageIdsToIncludeAsync(storage.Object, Mock.Of<ILogger>(), It.IsAny<CancellationToken>()); |
28 | | - |
29 | | - Assert.Empty(DnxPackageVersionIndexCacheControl.PackageIdsToInclude); |
30 | | - } |
31 | | - |
32 | 13 | [Theory] |
33 | | - [InlineData("{\"ids\":[]}", 0)] |
34 | | - [InlineData("{\"ids\":[\"PackageId1\",\"packageid1\"]}", 1)] |
35 | | - [InlineData("{\"ids\":[\"PackageId1\",\"PackageId2\"]}", 2)] |
36 | | - public async Task LoadPackageIdsToIncludeAsync_BlobExists(string json, int count) |
| 14 | + [InlineData("PackageId1", "max-age=10")] |
| 15 | + [InlineData("BaseTestPackage", "max-age=10")] |
| 16 | + [InlineData("basetestpackage", "no-store")] |
| 17 | + public void GetCacheControl(string packageId, string cacheControl) |
37 | 18 | { |
38 | | - var storage = new Mock<IStorage>(); |
39 | | - storage.Setup(s => s.Exists(It.IsAny<string>())).Returns(true); |
40 | | - storage.Setup(x => x.LoadStringAsync(It.IsAny<Uri>(), It.IsAny<CancellationToken>())).ReturnsAsync(json); |
41 | | - |
42 | | - DnxPackageVersionIndexCacheControl.PackageIdsToInclude = new HashSet<string>(); |
43 | | - |
44 | | - await DnxPackageVersionIndexCacheControl.LoadPackageIdsToIncludeAsync(storage.Object, Mock.Of<ILogger>(), It.IsAny<CancellationToken>()); |
45 | | - |
46 | | - Assert.Equal(count, DnxPackageVersionIndexCacheControl.PackageIdsToInclude.Count); |
47 | | - } |
48 | | - |
49 | | - [Fact] |
50 | | - public void GetCacheControl() |
51 | | - { |
52 | | - DnxPackageVersionIndexCacheControl.PackageIdsToInclude = new HashSet<string>() { "packageid1" }; |
53 | | - |
54 | | - Assert.Equal("max-age=10", DnxPackageVersionIndexCacheControl.GetCacheControl("packageid1", Mock.Of<ILogger>())); |
55 | | - Assert.Equal(Constants.NoStoreCacheControl, DnxPackageVersionIndexCacheControl.GetCacheControl("packageid2", Mock.Of<ILogger>())); |
| 19 | + Assert.Equal(cacheControl, DnxPackageVersionIndexCacheControl.GetCacheControl(packageId, Mock.Of<ILogger>())); |
56 | 20 | } |
57 | 21 | } |
58 | 22 | } |
0 commit comments