Skip to content

Commit 327b455

Browse files
committed
Started porting unit tests from NuGetGallery
1 parent c4bb9a1 commit 327b455

12 files changed

Lines changed: 758 additions & 2 deletions

File tree

NuGet.Server.sln

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{D54B
2828
EndProject
2929
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Server.V2.Samples.OwinHost", "samples\NuGet.Server.V2.Samples.OwinHost\NuGet.Server.V2.Samples.OwinHost.csproj", "{5CF9DB92-53DE-488E-82F9-4C3F867516B2}"
3030
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.Server.V2.Tests", "test\NuGet.Server.V2.Tests\NuGet.Server.V2.Tests.csproj", "{BE64E341-7D99-43D9-A0D2-A38E977B7D97}"
32+
EndProject
3133
Global
3234
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3335
Coverage|Any CPU = Coverage|Any CPU
@@ -162,6 +164,26 @@ Global
162164
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Release|Any CPU.Build.0 = Release|Any CPU
163165
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
164166
{5CF9DB92-53DE-488E-82F9-4C3F867516B2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
167+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Coverage|Any CPU.ActiveCfg = Release|Any CPU
168+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Coverage|Any CPU.Build.0 = Release|Any CPU
169+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Coverage|Mixed Platforms.ActiveCfg = Release|Any CPU
170+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Coverage|Mixed Platforms.Build.0 = Release|Any CPU
171+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
172+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Debug|Any CPU.Build.0 = Debug|Any CPU
173+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
174+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
175+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Debug|Any CPU.ActiveCfg = Debug|Any CPU
176+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Debug|Any CPU.Build.0 = Debug|Any CPU
177+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
178+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Debug|Mixed Platforms.Build.0 = Debug|Any CPU
179+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Release|Any CPU.ActiveCfg = Release|Any CPU
180+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Release|Any CPU.Build.0 = Release|Any CPU
181+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Release|Mixed Platforms.ActiveCfg = Release|Any CPU
182+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Mono Release|Mixed Platforms.Build.0 = Release|Any CPU
183+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Release|Any CPU.ActiveCfg = Release|Any CPU
184+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Release|Any CPU.Build.0 = Release|Any CPU
185+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
186+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97}.Release|Mixed Platforms.Build.0 = Release|Any CPU
165187
EndGlobalSection
166188
GlobalSection(SolutionProperties) = preSolution
167189
HideSolutionNode = FALSE
@@ -173,5 +195,6 @@ Global
173195
{FDE8DDFB-E01B-47FD-9945-0A151F3AE589} = {E7B39EAD-EA32-4011-845A-C949A336389A}
174196
{273E4575-4054-4578-9D14-8D4E640A365F} = {0F277539-E9D7-4A06-A731-D525D9AFCE54}
175197
{5CF9DB92-53DE-488E-82F9-4C3F867516B2} = {D54BB20B-57E8-4D4F-BD9D-CF284CBFAB3B}
198+
{BE64E341-7D99-43D9-A0D2-A38E977B7D97} = {E7B39EAD-EA32-4011-845A-C949A336389A}
176199
EndGlobalSection
177200
EndGlobal

build.cmd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ call :ExecuteCmd packages\xunit.runner.console.2.1.0\tools\xunit.console.exe tes
3434
IF %ERRORLEVEL% NEQ 0 goto error
3535
call :ExecuteCmd packages\xunit.runner.console.2.1.0\tools\xunit.console.exe test\NuGet.Server.Tests\bin\%config%\NuGet.Server.Tests.dll
3636
IF %ERRORLEVEL% NEQ 0 goto error
37+
call :ExecuteCmd packages\xunit.runner.console.2.1.0\tools\xunit.console.exe test\NuGet.Server.V2.Tests\bin\%config%\NuGet.Server.V2.Tests.dll
38+
IF %ERRORLEVEL% NEQ 0 goto error
3739

3840

3941
REM Package

src/NuGet.Server.V2/Controllers/NuGetODataController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public virtual IHttpActionResult Get(ODataQueryOptions<ODataPackage> options, st
6868
var package = RetrieveFromRepository(id, version);
6969

7070
if (package == null)
71-
throw new HttpResponseException(HttpStatusCode.NotFound);
71+
return NotFound();
7272

7373
var queryable = (new[] { package.AsODataPackage() }).AsQueryable();
7474
var queryResult = QueryResult(options, queryable, _maxPageSize);

src/NuGet.Server.V2/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
[assembly: AssemblyTitle("NuGet.Server.V2")]
88
[assembly: AssemblyDescription("Library to host one or more simple NuGet V2 feeds as Web API controllers.")]
9-
[assembly: InternalsVisibleTo("NuGet.Server.Tests")]
9+
[assembly: InternalsVisibleTo("NuGet.Server.V2.Tests")]
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using NuGet.Server.Core.Infrastructure;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Runtime.Versioning;
8+
using Moq;
9+
using NuGet.Server.Core.DataServices;
10+
11+
namespace NuGet.Server.V2.Tests.Infrastructure
12+
{
13+
public class ControllerTestHelpers
14+
{
15+
public static Mock<IServerPackageRepository> SetupTestPackageRepository()
16+
{
17+
//var fooPackage = new PackageRegistration { Id = "Foo" };
18+
//var barPackage = new PackageRegistration { Id = "Bar" };
19+
//var bazPackage = new PackageRegistration { Id = "Baz" };
20+
21+
var repo = new Mock<IServerPackageRepository>(MockBehavior.Strict);
22+
repo.Setup(r => r.GetPackages()).Returns(new[]
23+
{
24+
new ServerPackage
25+
{
26+
//PackageRegistration = fooPackage,
27+
Id="Foo",
28+
Version = SemanticVersion.Parse("1.0.0"),
29+
//IsPrerelease = false,
30+
Listed = true,
31+
Authors = new [] { "Test" },
32+
Owners = new [] { "Test" },
33+
Description = "Foo",
34+
Summary = "Foo",
35+
Tags = "Foo CommonTag"
36+
},
37+
new ServerPackage
38+
{
39+
//PackageRegistration = fooPackage,
40+
Id="Foo",
41+
Version = SemanticVersion.Parse("1.0.1-a"),
42+
//IsPrerelease = true,
43+
Listed = true,
44+
Authors = new [] { "Test" },
45+
Owners = new [] { "Test" },
46+
Description = "Foo",
47+
Summary = "Foo",
48+
Tags = "Foo CommonTag"
49+
},
50+
new ServerPackage
51+
{
52+
//PackageRegistration = barPackage,
53+
Id = "Bar",
54+
Version = SemanticVersion.Parse("1.0.0"),
55+
//IsPrerelease = false,
56+
Listed = true,
57+
Authors = new [] { "Test" },
58+
Owners = new [] { "Test" },
59+
Description = "Bar",
60+
Summary = "Bar",
61+
Tags = "Bar CommonTag"
62+
},
63+
new ServerPackage
64+
{
65+
//PackageRegistration = barPackage,
66+
Id = "Bar",
67+
Version = SemanticVersion.Parse("2.0.0"),
68+
//IsPrerelease = false,
69+
Listed = true,
70+
Authors = new [] { "Test" },
71+
Owners = new [] { "Test" },
72+
Description = "Bar",
73+
Summary = "Bar",
74+
Tags = "Bar CommonTag"
75+
},
76+
new ServerPackage
77+
{
78+
//PackageRegistration = barPackage,
79+
Id = "Bar",
80+
Version = SemanticVersion.Parse("2.0.1-a"),
81+
//IsPrerelease = true,
82+
Listed = true,
83+
Authors = new [] { "Test" },
84+
Owners = new [] { "Test" },
85+
Description = "Bar",
86+
Summary = "Bar",
87+
Tags = "Bar CommonTag"
88+
},
89+
new ServerPackage
90+
{
91+
//PackageRegistration = barPackage,
92+
Id = "Bar",
93+
Version = SemanticVersion.Parse("2.0.1-b"),
94+
//IsPrerelease = true,
95+
Listed = false,
96+
Authors = new [] { "Test" },
97+
Owners = new [] { "Test" },
98+
Description = "Bar",
99+
Summary = "Bar",
100+
Tags = "Bar CommonTag"
101+
},
102+
new ServerPackage
103+
{
104+
//PackageRegistration = bazPackage,
105+
Id = "Baz",
106+
Version = SemanticVersion.Parse("1.0.0"),
107+
//IsPrerelease = false,
108+
Listed = false,
109+
//Deleted = true, // plot twist: this package is a soft-deleted one
110+
Authors = new [] { "Test" },
111+
Owners = new [] { "Test" },
112+
Description = "Baz",
113+
Summary = "Baz",
114+
Tags = "Baz CommonTag"
115+
}
116+
}.AsQueryable());
117+
118+
return repo;
119+
}
120+
121+
}
122+
}
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" />
4+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{BE64E341-7D99-43D9-A0D2-A38E977B7D97}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>NuGet.Server.V2.Tests</RootNamespace>
12+
<AssemblyName>NuGet.Server.V2.Tests</AssemblyName>
13+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<NuGetPackageImportStamp>
16+
</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>TRACE;DEBUG;CODE_ANALYSIS</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="Castle.Core">
38+
<HintPath>..\..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
39+
<Private>True</Private>
40+
</Reference>
41+
<Reference Include="Microsoft.Data.Edm, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
42+
<SpecificVersion>False</SpecificVersion>
43+
<HintPath>..\..\packages\Microsoft.Data.Edm.5.7.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
44+
<Private>True</Private>
45+
</Reference>
46+
<Reference Include="Microsoft.Data.OData, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
47+
<SpecificVersion>False</SpecificVersion>
48+
<HintPath>..\..\packages\Microsoft.Data.OData.5.7.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
49+
<Private>True</Private>
50+
</Reference>
51+
<Reference Include="Microsoft.Web.XmlTransform">
52+
<HintPath>..\..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
53+
<Private>True</Private>
54+
</Reference>
55+
<Reference Include="Moq">
56+
<HintPath>..\..\packages\Moq.4.5.8\lib\net45\Moq.dll</HintPath>
57+
<Private>True</Private>
58+
</Reference>
59+
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
60+
<SpecificVersion>False</SpecificVersion>
61+
<HintPath>..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
62+
<Private>True</Private>
63+
</Reference>
64+
<Reference Include="NuGet.Core, Version=2.11.1.812, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
65+
<SpecificVersion>False</SpecificVersion>
66+
<HintPath>..\..\packages\NuGet.Core.2.11.1\lib\net40-Client\NuGet.Core.dll</HintPath>
67+
<Private>True</Private>
68+
</Reference>
69+
<Reference Include="System" />
70+
<Reference Include="System.Core" />
71+
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
72+
<SpecificVersion>False</SpecificVersion>
73+
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
74+
<Private>True</Private>
75+
</Reference>
76+
<Reference Include="System.Spatial, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
77+
<SpecificVersion>False</SpecificVersion>
78+
<HintPath>..\..\packages\System.Spatial.5.7.0\lib\net40\System.Spatial.dll</HintPath>
79+
<Private>True</Private>
80+
</Reference>
81+
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
82+
<SpecificVersion>False</SpecificVersion>
83+
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
84+
<Private>True</Private>
85+
</Reference>
86+
<Reference Include="System.Web.Http.OData">
87+
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.OData.5.7.0\lib\net45\System.Web.Http.OData.dll</HintPath>
88+
<Private>True</Private>
89+
</Reference>
90+
<Reference Include="System.Xml.Linq" />
91+
<Reference Include="System.Data.DataSetExtensions" />
92+
<Reference Include="Microsoft.CSharp" />
93+
<Reference Include="System.Data" />
94+
<Reference Include="System.Net.Http" />
95+
<Reference Include="System.Xml" />
96+
<Reference Include="xunit.abstractions">
97+
<HintPath>..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
98+
<Private>True</Private>
99+
</Reference>
100+
<Reference Include="xunit.assert">
101+
<HintPath>..\..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
102+
<Private>True</Private>
103+
</Reference>
104+
<Reference Include="xunit.core">
105+
<HintPath>..\..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
106+
<Private>True</Private>
107+
</Reference>
108+
<Reference Include="xunit.execution.desktop">
109+
<HintPath>..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
110+
<Private>True</Private>
111+
</Reference>
112+
</ItemGroup>
113+
<ItemGroup>
114+
<Compile Include="Infrastructure\ControllerTestHelpers.cs" />
115+
<Compile Include="NuGetODataControllerTests.cs" />
116+
<Compile Include="Properties\AssemblyInfo.cs" />
117+
<Compile Include="TestableNuGetODataController.cs" />
118+
<Compile Include="TestUtils\HttpActionResultExtensions.cs" />
119+
</ItemGroup>
120+
<ItemGroup>
121+
<None Include="app.config" />
122+
<None Include="packages.config" />
123+
</ItemGroup>
124+
<ItemGroup>
125+
<ProjectReference Include="..\..\src\NuGet.Server.Core\NuGet.Server.Core.csproj">
126+
<Project>{1FE62F82-927A-4437-91F1-1A965E51682B}</Project>
127+
<Name>NuGet.Server.Core</Name>
128+
</ProjectReference>
129+
<ProjectReference Include="..\..\src\NuGet.Server.V2\NuGet.Server.V2.csproj">
130+
<Project>{273e4575-4054-4578-9d14-8d4e640a365f}</Project>
131+
<Name>NuGet.Server.V2</Name>
132+
</ProjectReference>
133+
</ItemGroup>
134+
<ItemGroup>
135+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
136+
</ItemGroup>
137+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
138+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
139+
<PropertyGroup>
140+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
141+
</PropertyGroup>
142+
<Error Condition="!Exists('..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.runner.visualstudio.2.1.0\build\net20\xunit.runner.visualstudio.props'))" />
143+
</Target>
144+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
145+
Other similar extension points exist, see Microsoft.Common.targets.
146+
<Target Name="BeforeBuild">
147+
</Target>
148+
<Target Name="AfterBuild">
149+
</Target>
150+
-->
151+
</Project>

0 commit comments

Comments
 (0)