Skip to content

Commit 64f4bb1

Browse files
committed
Enhanced licensing and added licenses on test projects where needed (#229)
1 parent a047c8a commit 64f4bb1

File tree

26 files changed

+9552
-33
lines changed

26 files changed

+9552
-33
lines changed

MyTested.AspNetCore.Mvc.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.Mod
140140
EndProject
141141
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.Helpers.Test", "test\MyTested.AspNetCore.Mvc.Helpers.Test\MyTested.AspNetCore.Mvc.Helpers.Test.xproj", "{FE5913FD-CD0A-4ED9-9C43-F2892C72ED6E}"
142142
EndProject
143+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MyTested.AspNetCore.Mvc.Lite", "src\MyTested.AspNetCore.Mvc.Lite\MyTested.AspNetCore.Mvc.Lite.xproj", "{092CEA1D-84CC-43D8-9978-15F359163084}"
144+
EndProject
143145
Global
144146
GlobalSection(SolutionConfigurationPlatforms) = preSolution
145147
Debug|Any CPU = Debug|Any CPU
@@ -386,6 +388,10 @@ Global
386388
{FE5913FD-CD0A-4ED9-9C43-F2892C72ED6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
387389
{FE5913FD-CD0A-4ED9-9C43-F2892C72ED6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
388390
{FE5913FD-CD0A-4ED9-9C43-F2892C72ED6E}.Release|Any CPU.Build.0 = Release|Any CPU
391+
{092CEA1D-84CC-43D8-9978-15F359163084}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
392+
{092CEA1D-84CC-43D8-9978-15F359163084}.Debug|Any CPU.Build.0 = Debug|Any CPU
393+
{092CEA1D-84CC-43D8-9978-15F359163084}.Release|Any CPU.ActiveCfg = Release|Any CPU
394+
{092CEA1D-84CC-43D8-9978-15F359163084}.Release|Any CPU.Build.0 = Release|Any CPU
389395
EndGlobalSection
390396
GlobalSection(SolutionProperties) = preSolution
391397
HideSolutionNode = FALSE
@@ -454,5 +460,6 @@ Global
454460
{776BC96D-F536-4788-808E-F0F25C26FB69} = {09353A03-2B0C-496B-8EB1-2CB6A22D758B}
455461
{1CF0545A-8800-4ED1-8A89-A95FE557EE57} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
456462
{FE5913FD-CD0A-4ED9-9C43-F2892C72ED6E} = {D140FA14-A6C2-4279-8A41-35BC55279DA8}
463+
{092CEA1D-84CC-43D8-9978-15F359163084} = {09353A03-2B0C-496B-8EB1-2CB6A22D758B}
457464
EndGlobalSection
458465
EndGlobal

samples/MusicStore/MusicStore.Test/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"preserveCompilationContext": true,
55
"copyToOutput": {
66
"include": [
7-
"config.json"
7+
"config.json",
8+
"testconfig.json"
89
]
910
}
1011
},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"License": "1-0GEPhlzJ+jgqzGg+hQPo19wbRvEN0C4LjGm9YDTErbLzcTROsj3fU177Unj7wlOCNE0ciZCB5aw8jt4EEDczpW6S/lW0PkU8ZBjqh6F2ev42hqcgtlEKmBRwomPKj/PUElAo1iIdkLn3/il3o8HAsum7bKMqv7QPpOSwy/TuAGYxOjIwMTctMTAtMTU6YWRtaW5AbXl0ZXN0ZWRhc3AubmV0Ok11c2ljIFN0b3JlIFNhbXBsZSBUZXN0czpEZXZlbG9wZXI6TXVzaWNTdG9yZS4="
3+
}

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/Application/TestApplication.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,19 @@ internal static void LoadPlugins(DependencyContext dependencyContext)
224224
.GetRuntimeAssemblyNames(RuntimeEnvironment.GetRuntimeIdentifier())
225225
.Where(l => l.Name.StartsWith(TestFrameworkName))
226226
.Select(l => Assembly.Load(new AssemblyName(l.Name)).GetType($"{TestFrameworkName}.Plugins.{l.Name.Replace(TestFrameworkName, string.Empty).Trim('.')}TestPlugin"))
227-
.Where(p => p != null);
227+
.Where(p => p != null)
228+
.ToArray();
228229

229230
if (!plugins.Any())
230231
{
231232
throw new InvalidOperationException("Test plugins could not be loaded. Depending on your project's configuration you may need to set the 'preserveCompilationContext' property under 'buildOptions' to 'true' in the test assembly's 'project.json' file and/or may need to call '.StartsFrom<TStartup>().WithTestAssembly(this)'.");
232233
}
233234

235+
if (plugins.Length == 6 && plugins.Any(t => t.Name.StartsWith("Lite")))
236+
{
237+
TestCounter.SkipValidation = true;
238+
}
239+
234240
plugins.ForEach(t =>
235241
{
236242
var plugin = Activator.CreateInstance(t);

src/MyTested.AspNetCore.Mvc.Licensing/LicenseType.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
{
33
internal class LicenseType
44
{
5-
public const string Internal = "Internal";
6-
public const string Full = "Full";
5+
public const string Internal = "Internal"; // testing purposes, throws exception
6+
public const string Contribution = "Contribution"; // given for free for various contributions
7+
public const string Developer = "Developer"; // given to a single developer, can be purchased through https://mytestedasp.net
8+
public const string Application = "Application"; // given to an application with unlimited developers, can be requested through https://mytestedasp.net
9+
public const string Enterprise = "Enterprise"; // given to a company with unlimited developers and applications, can be requested through https://mytestedasp.net
710
}
811
}

src/MyTested.AspNetCore.Mvc.Licensing/LicenseValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private static void Validate(string license, DateTime releaseDate, string projec
161161
throw new InvalidLicenseException($"License is not valid for this version of My Tested ASP.NET Core MVC. License expired on {licenseDetails.ExpiryDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}. This version of My Tested ASP.NET Core MVC was released on {releaseDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}");
162162
}
163163

164-
if (licenseDetails.NamespacePrefix != "." && !projectNamespace.StartsWith(licenseDetails.NamespacePrefix))
164+
if (licenseDetails.Type != LicenseType.Enterprise && licenseDetails.NamespacePrefix != "." && !projectNamespace.StartsWith(licenseDetails.NamespacePrefix))
165165
{
166166
throw new InvalidLicenseException($"License is not valid for '{projectNamespace}' test project");
167167
}

src/MyTested.AspNetCore.Mvc.Licensing/TestCounter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
internal static class TestCounter
99
{
10-
private const int MaximumAllowedAssertions = 500;
10+
private const int MaximumAllowedAssertions = 100;
1111

1212
private static readonly object Sync;
1313

@@ -26,7 +26,7 @@ static TestCounter()
2626

2727
public static void IncrementAndValidate()
2828
{
29-
if (LicenseValidator.HasValidLicense)
29+
if (SkipValidation || LicenseValidator.HasValidLicense)
3030
{
3131
return;
3232
}
@@ -66,5 +66,7 @@ public static void SetLicenseData(IEnumerable<string> registeredLicenses, DateTi
6666
licensesValidated = false;
6767
totalAssertions = 0;
6868
}
69+
70+
public static bool SkipValidation { get; set; }
6971
}
7072
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
namespace MyTested.AspNetCore.Mvc
2+
{
3+
using System;
4+
using Builders.Contracts.Application;
5+
using Builders.Contracts.Controllers;
6+
using Builders.Contracts.ViewComponents;
7+
using Internal.Application;
8+
9+
/// <summary>
10+
/// Provides methods to specify an ASP.NET Core MVC test case.
11+
/// </summary>
12+
public static class MyMvc
13+
{
14+
static MyMvc()
15+
{
16+
TestApplication.TryInitialize();
17+
}
18+
19+
/// <summary>
20+
/// Configures the tested application with the provided startup class.
21+
/// </summary>
22+
/// <typeparam name="TStartup">Type of startup class.</typeparam>
23+
/// <returns>Builder of <see cref="IApplicationConfigurationBuilder"/> type.</returns>
24+
public static IApplicationConfigurationBuilder StartsFrom<TStartup>()
25+
where TStartup : class
26+
{
27+
return new MyApplication(typeof(TStartup));
28+
}
29+
30+
/// <summary>
31+
/// Starts a controller test.
32+
/// </summary>
33+
/// <typeparam name="TController">Class representing ASP.NET Core MVC controller.</typeparam>
34+
/// <returns>Test builder of <see cref="IControllerBuilder{TController}"/> type.</returns>
35+
public static IControllerBuilder<TController> Controller<TController>()
36+
where TController : class
37+
{
38+
return new MyController<TController>();
39+
}
40+
41+
/// <summary>
42+
/// Starts a controller test.
43+
/// </summary>
44+
/// <typeparam name="TController">Class representing ASP.NET Core MVC controller.</typeparam>
45+
/// <param name="controller">Instance of the ASP.NET Core MVC controller to test.</param>
46+
/// <returns>Test builder of <see cref="IControllerBuilder{TController}"/> type.</returns>
47+
public static IControllerBuilder<TController> Controller<TController>(TController controller)
48+
where TController : class
49+
{
50+
return new MyController<TController>(controller);
51+
}
52+
53+
/// <summary>
54+
/// Starts a controller test.
55+
/// </summary>
56+
/// <typeparam name="TController">Class representing ASP.NET Core MVC controller.</typeparam>
57+
/// <param name="construction">Construction function returning the instantiated controller.</param>
58+
/// <returns>Test builder of <see cref="IControllerBuilder{TController}"/> type.</returns>
59+
public static IControllerBuilder<TController> Controller<TController>(Func<TController> construction)
60+
where TController : class
61+
{
62+
return new MyController<TController>(construction);
63+
}
64+
65+
/// <summary>
66+
/// Starts a view component test.
67+
/// </summary>
68+
/// <typeparam name="TViewComponent">Class representing ASP.NET Core MVC view component.</typeparam>
69+
/// <returns>Test builder of <see cref="IViewComponentBuilder{TViewComponent}"/> type.</returns>
70+
public static IViewComponentBuilder<TViewComponent> ViewComponent<TViewComponent>()
71+
where TViewComponent : class
72+
{
73+
return new MyViewComponent<TViewComponent>();
74+
}
75+
76+
/// <summary>
77+
/// Starts a view component test.
78+
/// </summary>
79+
/// <typeparam name="TViewComponent">Class representing ASP.NET Core MVC view component.</typeparam>
80+
/// <param name="viewComponent">Instance of the ASP.NET Core MVC view component to use.</param>
81+
/// <returns>Test builder of <see cref="IViewComponentBuilder{TViewComponent}"/> type.</returns>
82+
public static IViewComponentBuilder<TViewComponent> ViewComponent<TViewComponent>(TViewComponent viewComponent)
83+
where TViewComponent : class
84+
{
85+
return new MyViewComponent<TViewComponent>(viewComponent);
86+
}
87+
88+
/// <summary>
89+
/// Starts a view component test.
90+
/// </summary>
91+
/// <typeparam name="TViewComponent">Class representing ASP.NET Core MVC view component.</typeparam>
92+
/// <param name="construction">Construction function returning the instantiated view component.</param>
93+
/// <returns>Test builder of <see cref="IViewComponentBuilder{TViewComponent}"/> type.</returns>
94+
public static IViewComponentBuilder<TViewComponent> ViewComponent<TViewComponent>(Func<TViewComponent> construction)
95+
where TViewComponent : class
96+
{
97+
return new MyViewComponent<TViewComponent>(construction);
98+
}
99+
}
100+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>092cea1d-84cc-43d8-9978-15f359163084</ProjectGuid>
10+
<RootNamespace>MyTested.AspNetCore.Mvc</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
13+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
14+
</PropertyGroup>
15+
<PropertyGroup>
16+
<SchemaVersion>2.0</SchemaVersion>
17+
</PropertyGroup>
18+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
19+
<Target Name="AfterBuild">
20+
<Exec Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'" Command="dotnet pack --configuration Release --output ../../artifacts --no-build" />
21+
</Target>
22+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace MyTested.AspNetCore.Mvc.Plugins
2+
{
3+
using System;
4+
using Microsoft.Extensions.DependencyInjection;
5+
6+
public class LiteTestPlugin : IDefaultRegistrationPlugin
7+
{
8+
public long Priority => 0;
9+
10+
public Action<IServiceCollection> DefaultServiceRegistrationDelegate
11+
=> serviceCollection => serviceCollection.AddMvc();
12+
}
13+
}

0 commit comments

Comments
 (0)