public async Task Query_For_Resource_With_NoCompatibleVersion() { // Arrange var source = "https://some-site.org/test.json"; var content = CreateVersionedTestIndex(); var httpProvider = StaticHttpSource.CreateHttpSource(new Dictionary <string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.True(result.Item1); var resource = result.Item2 as ServiceIndexResourceV3; Assert.NotNull(resource); var endpoints = resource.GetServiceEntryUris(NuGetVersion.Parse("0.0.0-beta"), "A"); Assert.True(endpoints.Count == 0); }
public async Task Query_For_Resource_With_Precedence() { // Arrange var source = "https://some-site.org/test.json"; var content = CreateTestIndex(); var httpProvider = StaticHttpSource.CreateHttpSource(new Dictionary <string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.True(result.Item1); var resource = result.Item2 as ServiceIndexResourceV3; Assert.NotNull(resource); var endpoints = resource[new string[] { "Chocolate", "Vegetable" }]; Assert.True(endpoints.Count == 1); var endpointSet = new HashSet <string>(endpoints.Select(u => u.AbsoluteUri)); Assert.True(endpointSet.Contains("http://tempuri.org/chocolate")); }
public async Task Query_For_Particular_Multi_Value_Resource() { // Arrange var source = "https://some-site.org/test.json"; var content = CreateTestIndex(); var httpProvider = StaticHttpSource.CreateHttpSource(new Dictionary <string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.True(result.Item1); var resource = result.Item2 as ServiceIndexResourceV3; Assert.NotNull(resource); var endpoints = resource.GetServiceEntryUris(new NuGetVersion(4, 0, 0), "Fruit"); Assert.True(endpoints.Count == 3); var endpointSet = new HashSet <string>(endpoints.Select(u => u.AbsoluteUri)); Assert.True(endpointSet.Contains("http://tempuri.org/banana")); Assert.True(endpointSet.Contains("http://tempuri.org/apple")); Assert.True(endpointSet.Contains("http://tempuri.org/orange")); }
public async Task Query_For_Resource_With_VersionPrecedence_NoFallbackBetweenTypes() { // Arrange var source = $"https://some-site-{new Guid().ToString()}.org/test.json"; var content = CreateVersionedTestIndex2(); var httpProvider = StaticHttpSource.CreateHttpSource(new Dictionary <string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.True(result.Item1); var resource = result.Item2 as ServiceIndexResourceV3; Assert.NotNull(resource); var endpoints = resource.GetServiceEntryUris(new NuGetVersion(4, 1, 0), "A", "B"); Assert.True(endpoints.Count == 1); var endpointSet = new HashSet <string>(endpoints.Select(u => u.AbsoluteUri)); Assert.True(endpointSet.Contains("http://tempuri.org/B")); }
public async Task TryCreate_CancellationThrows() { // Arrange var source = $"https://some-site-{new Guid().ToString()}.org/test.json"; var content = @"{ version: '3.1.0-beta' }"; //Create an HTTP provider that will cancel the token. var httpProvider = StaticHttpSource.CreateHttpSource( new Dictionary <string, string> { { source, content } }, errorContent: string.Empty, httpSource: null, throwOperationCancelledException: true); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act using (CancellationTokenSource tokenSource = new CancellationTokenSource()) { Task task() => provider.TryCreate(sourceRepository, tokenSource.Token); // Assert await Assert.ThrowsAsync <OperationCanceledException>(task); } }
public async Task Query_For_Resource_ReturnAllOfSameTypeVersion() { // Arrange var source = "https://some-site.org/test.json"; var content = CreateVersionedTestIndex3(); var httpProvider = StaticHttpSource.CreateHttpSource(new Dictionary <string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.True(result.Item1); var resource = result.Item2 as ServiceIndexResourceV3; Assert.NotNull(resource); var endpoints = resource.GetServiceEntryUris(new NuGetVersion(5, 0, 0), "A", "B"); Assert.True(endpoints.Count == 2); var endpointSet = new HashSet <string>(endpoints.Select(u => u.AbsoluteUri)); Assert.True(endpointSet.Contains("http://tempuri.org/A/5.0.0/1")); Assert.True(endpointSet.Contains("http://tempuri.org/A/5.0.0/2")); }
public async Task TryCreate_ReturnsFalse_IfSourceDoesNotHaveAJsonSuffix(string location) { // Arrange var packageSource = new PackageSource(location); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(packageSource, new[] { provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.False(result.Item1); Assert.Null(result.Item2); }
public async Task TryCreate_ReturnsFalse_IfSourceDoesNotHaveAJsonSuffix(string location) { // Arrange var packageSource = new PackageSource(location); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(packageSource, new[] { provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.False(result.Item1); Assert.Null(result.Item2); }
public async Task TryCreate_ReturnsFalse_IfSourceLocationReturnsFailureCode() { // Arrange var source = "https://does-not-exist.server/does-not-exist.json"; // This will return a 404 - NotFound. var handlerProvider = StaticHttpHandler.CreateHttpHandler(new Dictionary<string, string> { { source, string.Empty } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { handlerProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.False(result.Item1); Assert.Null(result.Item2); }
public async Task TryCreate_ReturnsTrue_IfSourceLocationReturnsValidJson() { // Arrange var source = "https://some-site.org/test.json"; var content = @"{ version: '3.1.0-beta' }"; var httpProvider = StaticHttpSource.CreateHttpSource(new Dictionary <string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.True(result.Item1); }
[InlineData("{ version: \"3.0.0.0\" } ")] // not strict semver public async Task TryCreate_ReturnsFalse_IfSourceLocationDoesNotReturnValidJson(string content) { // Arrange var source = "https://fake.server/users.json"; var handlerProvider = StaticHttpHandler.CreateHttpHandler(new Dictionary <string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { handlerProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.False(result.Item1); Assert.Null(result.Item2); }
public async Task TryCreate_ReturnsFalse_IfSourceLocationReturnsFailureCode() { // Arrange var source = "https://does-not-exist.server/does-not-exist.json"; // This will return a 404 - NotFound. var handlerProvider = StaticHttpHandler.CreateHttpHandler(new Dictionary <string, string> { { source, string.Empty } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { handlerProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.False(result.Item1); Assert.Null(result.Item2); }
[InlineData("{ version: { value: 3 } } ")] // version is not a string public async Task TryCreate_Throws_IfNoVersionInJson(string content) { // Arrange var source = "https://fake.server/users.json"; var httpProvider = StaticHttpSource.CreateHttpSource(new Dictionary <string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act var exception = await Assert.ThrowsAsync <FatalProtocolException>(async() => { var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); }); // Assert Assert.Equal("The source does not have the 'version' property.", exception.InnerException.Message); }
[InlineData("{ version: \"3.0.0.0\" } ")] // not strict semver public async Task TryCreate_Throws_IfInvalidVersionInJson(string content) { // Arrange var source = $"https://fake.server-{new Guid().ToString()}/users.json"; var httpProvider = StaticHttpSource.CreateHttpSource(new Dictionary <string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act var exception = await Assert.ThrowsAsync <FatalProtocolException>(async() => { var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); }); // Assert Assert.StartsWith("The source version is not supported", exception.InnerException.Message); }
public async Task TryCreate_Throws_IfSourceLocationDoesNotReturnValidJson(string content) { // Arrange var source = "https://fake.server/users.json"; var httpProvider = StaticHttpSource.CreateHttpSource(new Dictionary <string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act and assert var exception = await Assert.ThrowsAsync <FatalProtocolException>(async() => { var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); }); Assert.IsType <InvalidDataException>(exception.InnerException); Assert.IsType <JsonReaderException>(exception.InnerException.InnerException); }
public async Task TryCreate_Throws_IfSourceLocationReturnsFailureCode() { // Arrange var source = "https://does-not-exist.server/does-not-exist.json"; // This will return a 404 - NotFound. var httpProvider = StaticHttpSource.CreateHttpSource(new Dictionary <string, string> { { source, string.Empty } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { httpProvider, provider }); // Act var exception = await Assert.ThrowsAsync <FatalProtocolException>(async() => { var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); }); Assert.IsType <HttpRequestException>(exception.InnerException); }
public async Task TryCreate_ReturnsTrue_IfSourceLocationReturnsValidJson() { // Arrange var source = "https://some-site.org/test.json"; var content = @"{ version: '3.1.0-beta' }"; var handlerProvider = StaticHttpHandler.CreateHttpHandler(new Dictionary<string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { handlerProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.True(result.Item1); var resource = Assert.IsType<ServiceIndexResourceV3>(result.Item2); Assert.NotNull(resource.Index); }
[InlineData("{ version: \"3.0.0.0\" } ")] // not strict semver public async Task TryCreate_ReturnsFalse_IfSourceLocationDoesNotReturnValidJson(string content) { // Arrange var source = "https://fake.server/users.json"; var handlerProvider = StaticHttpHandler.CreateHttpHandler(new Dictionary<string, string> { { source, content } }); var provider = new ServiceIndexResourceV3Provider(); var sourceRepository = new SourceRepository(new PackageSource(source), new INuGetResourceProvider[] { handlerProvider, provider }); // Act var result = await provider.TryCreate(sourceRepository, default(CancellationToken)); // Assert Assert.False(result.Item1); Assert.Null(result.Item2); }