Skip to content

Commit

Permalink
Modernize project and target .NET Standard 2.0
Browse files Browse the repository at this point in the history
* Upgrade projects to the new "SDK style" csproj format
  * Remove the packages directory and packages.config file
  * Remove `AssemblyInfo.cs` files (replaced with equivalent csproj properties)
  * Remove `*.vsmdi` and `*.testsettings` files
  * Run tests on .NET Framework 4.7.2 + .NET Core 3.1 + .NET 6.0
  * Update test dependencies to their latest version 
    * Microsoft.NET.Test.Sdk → 17.1.0
    * Moq → 4.16.1
    * MSTest.TestAdapter → 2.2.8
    * MSTest.TestFramework → 2.2.8

* Use `System.Text.Json` instead of `System.Web.Script.Serialization`
  * Use `JsonPropertyNameAttribute` instead of `FieldAttribute`
  * Make properties `{ get; init; }` instead of `{ get; internal set; }` with the help of the `IsExternalInit` NuGet package to support .NET Standard 2.0
  * Define `JsonPropertyName` attributes for all enums and use `JsonStringEnumMemberConverter` from the `Macross.Json.Extensions` NuGet package to workaround [issues in JsonStringEnumConverter](dotnet/runtime#31619)

Fixes emmettnicholas#11
  • Loading branch information
0xced committed Feb 17, 2022
1 parent d48ddb6 commit 0c90f16
Show file tree
Hide file tree
Showing 82 changed files with 932 additions and 17,278 deletions.
10 changes: 0 additions & 10 deletions Local.testsettings

This file was deleted.

35 changes: 0 additions & 35 deletions StacMan.Tests/Properties/AssemblyInfo.cs

This file was deleted.

89 changes: 14 additions & 75 deletions StacMan.Tests/StacMan.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,82 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5FBD3A5B-93AE-43B7-9566-C7D08A71C8E9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<IsPackable>false</IsPackable>
<RootNamespace>StackExchange.StacMan.Tests</RootNamespace>
<AssemblyName>StacMan.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.0.10827\lib\NET40\Moq.dll</HintPath>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="ApiVersion21Tests.cs" />
<Compile Include="BackoffTests.cs" />
<Compile Include="InfoMethodTests.cs" />
<Compile Include="QuestionMethodTests.cs" />
<Compile Include="SiteMethodTests.cs" />
<Compile Include="TagMethodTests.cs" />
<Compile Include="UserMethodTests.cs" />
<Compile Include="Utilities\Assert2.cs" />
<Compile Include="Utilities\ExtensionMethods.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StacManResponseTests.cs" />
<Compile Include="ValidationTests.cs" />
<Compile Include="WrapperTests.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\StacMan\StacMan.csproj">
<Project>{3C310AC6-6229-41FB-B33F-8381CF4FECBF}</Project>
<Name>StacMan</Name>
</ProjectReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
</ItemGroup>

<ItemGroup>
<None Include="packages.config" />
<ProjectReference Include="..\StacMan\StacMan.csproj" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
4 changes: 0 additions & 4 deletions StacMan.Tests/packages.config

This file was deleted.

7 changes: 0 additions & 7 deletions StacMan.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StacMan", "StacMan\StacMan.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StacMan.Tests", "StacMan.Tests\StacMan.Tests.csproj", "{5FBD3A5B-93AE-43B7-9566-C7D08A71C8E9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{940A5141-7F86-40E6-BB3D-046EE0A79FB7}"
ProjectSection(SolutionItems) = preProject
Local.testsettings = Local.testsettings
StacMan.vsmdi = StacMan.vsmdi
TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
EndProjectSection
EndProject
Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = StacMan.vsmdi
Expand Down
6 changes: 0 additions & 6 deletions StacMan.vsmdi

This file was deleted.

6 changes: 5 additions & 1 deletion StacMan/Badges/BadgeType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace StackExchange.StacMan.Badges
using System.Text.Json.Serialization;

namespace StackExchange.StacMan.Badges
{
/// <summary>
/// badge_type
Expand All @@ -8,11 +10,13 @@ public enum BadgeType
/// <summary>
/// name
/// </summary>
[JsonPropertyName("name")]
Named,

/// <summary>
/// tag_based
/// </summary>
[JsonPropertyName("tag_based")]
TagBased
}
}
7 changes: 6 additions & 1 deletion StacMan/Badges/Rank.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace StackExchange.StacMan.Badges
using System.Text.Json.Serialization;

namespace StackExchange.StacMan.Badges
{
/// <summary>
/// rank
Expand All @@ -8,16 +10,19 @@ public enum Rank
/// <summary>
/// gold
/// </summary>
[JsonPropertyName("gold")]
Gold,

/// <summary>
/// silver
/// </summary>
[JsonPropertyName("silver")]
Silver,

/// <summary>
/// bronze
/// </summary>
[JsonPropertyName("bronze")]
Bronze
}
}
17 changes: 9 additions & 8 deletions StacMan/Codegen/AccessToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// </auto-generated>

using System;
using System.Text.Json.Serialization;

namespace StackExchange.StacMan
{
Expand All @@ -17,26 +18,26 @@ public partial class AccessToken : StacManType
/// <summary>
/// access_token
/// </summary>
[Field("access_token")]
public string AccessTokenName { get; internal set; }
[JsonPropertyName("access_token")]
public string AccessTokenName { get; init; }

/// <summary>
/// account_id
/// </summary>
[Field("account_id")]
public int AccountId { get; internal set; }
[JsonPropertyName("account_id")]
public int AccountId { get; init; }

/// <summary>
/// expires_on_date
/// </summary>
[Field("expires_on_date")]
public DateTime? ExpiresOnDate { get; internal set; }
[JsonPropertyName("expires_on_date")]
public DateTime? ExpiresOnDate { get; init; }

/// <summary>
/// scope
/// </summary>
[Field("scope")]
public string[] Scope { get; internal set; }
[JsonPropertyName("scope")]
public string[] Scope { get; init; }

}
}
13 changes: 7 additions & 6 deletions StacMan/Codegen/AccountMerge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// </auto-generated>

using System;
using System.Text.Json.Serialization;

namespace StackExchange.StacMan
{
Expand All @@ -17,20 +18,20 @@ public partial class AccountMerge : StacManType
/// <summary>
/// merge_date -- introduced in API version 2.1
/// </summary>
[Field("merge_date")]
public DateTime MergeDate { get; internal set; }
[JsonPropertyName("merge_date")]
public DateTime MergeDate { get; init; }

/// <summary>
/// new_account_id -- introduced in API version 2.1
/// </summary>
[Field("new_account_id")]
public int NewAccountId { get; internal set; }
[JsonPropertyName("new_account_id")]
public int NewAccountId { get; init; }

/// <summary>
/// old_account_id -- introduced in API version 2.1
/// </summary>
[Field("old_account_id")]
public int OldAccountId { get; internal set; }
[JsonPropertyName("old_account_id")]
public int OldAccountId { get; init; }

}
}
Loading

0 comments on commit 0c90f16

Please sign in to comment.