-
Notifications
You must be signed in to change notification settings - Fork 748
Expand file tree
/
Copy pathAutoCompleteResourceV3Tests.cs
More file actions
44 lines (38 loc) · 1.85 KB
/
AutoCompleteResourceV3Tests.cs
File metadata and controls
44 lines (38 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Moq;
using NuGet.Common;
using NuGet.Protocol.Core.Types;
using NuGet.Shared;
using NuGet.Test.Utility;
using Test.Utility;
using Xunit;
namespace NuGet.Protocol.Tests
{
public class AutoCompleteResourceV3Tests
{
[Theory]
[InlineData("true")] // NSJ path
[InlineData("false")] // STJ path
public async Task IdStartsWith_BothPaths_ReturnsResultsAsync(string useNsj)
{
var responses = new Dictionary<string, string>();
responses.Add("http://testsource.com/v3/index.json", JsonData.IndexWithoutFlatContainer);
responses.Add("https://api-v3search-0.nuget.org/autocomplete?q=newt&prerelease=true&semVerLevel=2.0.0",
JsonData.AutoCompleteEndpointNewtResult);
var repo = StaticHttpHandler.CreateSource("http://testsource.com/v3/index.json", Repository.Provider.GetCoreV3(), responses);
var resource = (AutoCompleteResourceV3)await repo.GetResourceAsync<AutoCompleteResource>(CancellationToken.None);
var envReader = new Mock<IEnvironmentVariableReader>();
envReader.Setup(e => e.GetEnvironmentVariable(NuGetFeatureFlags.UseNSJDeserializationEnvVar)).Returns(useNsj);
var testResource = new AutoCompleteResourceV3(resource._client, resource._serviceIndex, resource._regResource, envReader.Object);
var logger = new TestLogger();
var result = await testResource.IdStartsWith("newt", true, logger, CancellationToken.None);
Assert.Equal(10, result.Count());
Assert.NotEmpty(logger.Messages);
}
}
}