-
Notifications
You must be signed in to change notification settings - Fork 136
/
MetadataTests.cs
183 lines (145 loc) · 6.54 KB
/
MetadataTests.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System.IO;
using System.Threading.Tasks;
using CloudNimble.Breakdance.Assemblies;
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Restier.Breakdance;
using Microsoft.Restier.Tests.Shared;
using Microsoft.Restier.Tests.Shared.Scenarios.Library;
using Microsoft.Restier.Tests.Shared.Scenarios.Marvel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#if NET6_0_OR_GREATER
namespace Microsoft.Restier.Tests.AspNetCore.FeatureTests
#else
namespace Microsoft.Restier.Tests.AspNet.FeatureTests
#endif
{
#if NET6_0_OR_GREATER
[TestClass]
[TestCategory("Endpoint Routing")]
public class MetadataTests_EndpointRouting : MetadataTests
{
public MetadataTests_EndpointRouting() : base(true)
{
}
}
[TestClass]
[TestCategory("Legacy Routing")]
public class MetadataTests_LegacyRouting : MetadataTests
{
public MetadataTests_LegacyRouting() : base(false)
{
}
}
/// <summary>
///
/// </summary>
[TestClass]
public abstract class MetadataTests : RestierTestBase<LibraryApi>
{
public MetadataTests(bool useEndpointRouting) : base(useEndpointRouting)
{
//AddRestierAction = builder =>
//{
// builder.AddRestierApi<LibraryApi>(services => services.AddEntityFrameworkServices<LibraryContext>());
//};
//MapRestierAction = routeBuilder =>
//{
// routeBuilder.MapApiRoute<LibraryApi>(WebApiConstants.RouteName, WebApiConstants.RoutePrefix, false);
//};
}
//[TestInitialize]
//public void ClaimsTestSetup() => TestSetup();
#else
/// <summary>
///
/// </summary>
[TestClass]
public class MetadataTests : RestierTestBase
{
#endif
#region Private Members
#if EFCore
private const string relativePath = "..//..//..//..//Microsoft.Restier.Tests.AspNetCore//";
#endif
#if EF6
private const string relativePath = "..//..//..//..//Microsoft.Restier.Tests.AspNet//";
#endif
private const string baselineFolder = "Baselines//";
#endregion
#region LibraryApi
[TestMethod]
public async Task LibraryApi_CompareCurrentApiMetadataToPriorRun()
{
/* JHC Note:
* in Restier.Tests.AspNet, this test fails because we haven't generated an updated ApiMetadata after some changes
* */
var fileName = $"{Path.Combine(relativePath, baselineFolder)}{typeof(LibraryApi).Name}-ApiMetadata.txt";
File.Exists(fileName).Should().BeTrue();
var oldReport = File.ReadAllText(fileName);
var newReport = await RestierTestHelpers.GetApiMetadataAsync<LibraryApi>(serviceCollection: (services) => services.AddEntityFrameworkServices<LibraryContext>(),
useEndpointRouting: UseEndpointRouting);
TestContext.WriteLine($"Old Report: {oldReport}");
TestContext.WriteLine($"New Report: {newReport}");
oldReport.Should().BeEquivalentTo(newReport.ToString());
}
//[DataRow(relativePath)]
//[DataTestMethod]
[BreakdanceManifestGenerator]
public async Task LibraryApi_SaveMetadataDocument(string projectPath)
{
await RestierTestHelpers.WriteCurrentApiMetadata<LibraryApi>(Path.Combine(projectPath, baselineFolder),
serviceCollection: (services) => services.AddEntityFrameworkServices<LibraryContext>(), useEndpointRouting: UseEndpointRouting);
File.Exists($"{Path.Combine(projectPath, baselineFolder)}{typeof(LibraryApi).Name}-ApiMetadata.txt").Should().BeTrue();
}
#endregion
#region MarvelApi
[TestMethod]
public async Task MarvelApi_CompareCurrentApiMetadataToPriorRun()
{
var fileName = $"{Path.Combine(relativePath, baselineFolder)}{typeof(MarvelApi).Name}-ApiMetadata.txt";
File.Exists(fileName).Should().BeTrue();
var oldReport = File.ReadAllText(fileName);
var newReport = await RestierTestHelpers.GetApiMetadataAsync<MarvelApi>(serviceCollection: (services) => services.AddEntityFrameworkServices<MarvelContext>(),
useEndpointRouting: UseEndpointRouting);
TestContext.WriteLine($"Old Report: {oldReport}");
TestContext.WriteLine($"New Report: {newReport}");
oldReport.Should().BeEquivalentTo(newReport.ToString());
}
//[DataRow(relativePath)]
//[DataTestMethod]
[BreakdanceManifestGenerator]
public async Task MarvelApi_SaveMetadataDocument(string projectPath)
{
await RestierTestHelpers.WriteCurrentApiMetadata<MarvelApi>(Path.Combine(projectPath, baselineFolder),
serviceCollection: (services) => services.AddEntityFrameworkServices<MarvelContext>(), useEndpointRouting: UseEndpointRouting);
File.Exists($"{Path.Combine(projectPath, baselineFolder)}{typeof(MarvelApi).Name}-ApiMetadata.txt").Should().BeTrue();
}
#endregion
#region StoreApi
[TestMethod]
public async Task StoreApi_CompareCurrentApiMetadataToPriorRun()
{
var fileName = $"{Path.Combine(relativePath, baselineFolder)}{typeof(StoreApi).Name}-ApiMetadata.txt";
File.Exists(fileName).Should().BeTrue();
var oldReport = File.ReadAllText(fileName);
var newReport = await RestierTestHelpers.GetApiMetadataAsync<StoreApi>(serviceCollection: (services) => services.AddTestStoreApiServices(),
useEndpointRouting: UseEndpointRouting);
TestContext.WriteLine($"Old Report: {oldReport}");
TestContext.WriteLine($"New Report: {newReport}");
oldReport.Should().BeEquivalentTo(newReport.ToString());
}
//[DataRow(relativePath)]
//[DataTestMethod]
[BreakdanceManifestGenerator]
public async Task StoreApi_SaveMetadataDocument(string projectPath)
{
await RestierTestHelpers.WriteCurrentApiMetadata<StoreApi>(Path.Combine(projectPath, baselineFolder), serviceCollection: (services) => services.AddTestStoreApiServices(),
useEndpointRouting: UseEndpointRouting);
File.Exists($"{Path.Combine(projectPath, baselineFolder)}{typeof(StoreApi).Name}-ApiMetadata.txt").Should().BeTrue();
}
#endregion
}
}