|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) |
| 3 | + * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers |
| 4 | + * for more information concerning the license and the contributors participating to this project. |
| 5 | + */ |
| 6 | + |
| 7 | +using System; |
| 8 | +using System.Collections.Generic; |
| 9 | +using System.IO; |
| 10 | +using System.Linq; |
| 11 | +using System.Reflection; |
| 12 | +using System.Threading; |
| 13 | +using System.Threading.Tasks; |
| 14 | +using System.Xml.Linq; |
| 15 | +using Shouldly; |
| 16 | +using Xunit; |
| 17 | + |
| 18 | +namespace AspNet.Security.OAuth |
| 19 | +{ |
| 20 | + public static class PackageMetadataTests |
| 21 | + { |
| 22 | + private static readonly string? _solutionRoot = typeof(PackageMetadataTests).Assembly |
| 23 | + .GetCustomAttributes<AssemblyMetadataAttribute>() |
| 24 | + .Where((p) => string.Equals("SolutionRoot", p.Key, StringComparison.Ordinal)) |
| 25 | + .Select((p) => p.Value) |
| 26 | + .First(); |
| 27 | + |
| 28 | + public static IEnumerable<object[]> Projects() |
| 29 | + { |
| 30 | + foreach (string directory in Directory.EnumerateDirectories(Path.Combine(_solutionRoot!, "src"))) |
| 31 | + { |
| 32 | + foreach (string project in Directory.EnumerateFiles(directory, "*.csproj")) |
| 33 | + { |
| 34 | + string projectName = Path.GetFileNameWithoutExtension(project); |
| 35 | + |
| 36 | + foreach (string propertyName in new[] { "Authors", "Description", "PackageTags" }) |
| 37 | + { |
| 38 | + yield return new object[] { projectName, propertyName }; |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + [Theory] |
| 45 | + [MemberData(nameof(Projects))] |
| 46 | + public static async Task Project_Has_Expected_Package_Metadata(string projectName, string propertyName) |
| 47 | + { |
| 48 | + // Arrange |
| 49 | + string path = Path.Combine(_solutionRoot!, "src", projectName, projectName) + ".csproj"; |
| 50 | + |
| 51 | + using var stream = File.OpenRead(path); |
| 52 | + XElement project = await XElement.LoadAsync(stream, LoadOptions.None, CancellationToken.None); |
| 53 | + |
| 54 | + AssertPackageMetadata(project, propertyName); |
| 55 | + } |
| 56 | + |
| 57 | + private static void AssertPackageMetadata(XElement project, string propertyName) |
| 58 | + { |
| 59 | + bool found = false; |
| 60 | + |
| 61 | + foreach (XElement item in project.Descendants("PropertyGroup").Descendants()) |
| 62 | + { |
| 63 | + if (string.Equals(item.Name.LocalName, propertyName, StringComparison.Ordinal)) |
| 64 | + { |
| 65 | + item.Value.ShouldNotBeNullOrWhiteSpace($"The {propertyName} MSBuild property has no value."); |
| 66 | + found = true; |
| 67 | + break; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + found.ShouldBeTrue($"The {propertyName} MSBuild property cannot be found."); |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments