// check that for every FlurlClient extension method, we have an equivalent Url and string extension public void extension_methods_consistently_supported() { var frExts = ReflectionHelper.GetAllExtensionMethods <IFlurlRequest>(typeof(FlurlClient).GetTypeInfo().Assembly) // URL builder methods on IFlurlClient get a free pass. We're looking for things like HTTP calling methods. .Where(mi => mi.DeclaringType != typeof(UrlBuilderExtensions)) .ToList(); var urlExts = ReflectionHelper.GetAllExtensionMethods <Url>(typeof(FlurlClient).GetTypeInfo().Assembly).ToList(); var stringExts = ReflectionHelper.GetAllExtensionMethods <string>(typeof(FlurlClient).GetTypeInfo().Assembly).ToList(); var uriExts = ReflectionHelper.GetAllExtensionMethods <Uri>(typeof(FlurlClient).GetTypeInfo().Assembly).ToList(); Assert.That(frExts.Count > 20, $"IFlurlRequest only has {frExts.Count} extension methods? Something's wrong here."); // Url and string should contain all extension methods that IFlurlRequest has foreach (var method in frExts) { if (!urlExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { var args = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.Name)); Assert.Fail($"No equivalent Url extension method found for IFlurlRequest.{method.Name}({args})"); } if (!stringExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { var args = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.Name)); Assert.Fail($"No equivalent string extension method found for IFlurlRequest.{method.Name}({args})"); } if (!uriExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { var args = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.Name)); Assert.Fail($"No equivalent System.Uri extension method found for IFlurlRequest.{method.Name}({args})"); } } }
// check that for every Url method, we have an equivalent string extension public void extension_methods_consistently_supported() { var urlMethods = typeof(Url).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly).Where(m => !m.IsSpecialName); var stringExts = ReflectionHelper.GetAllExtensionMethods <string>(typeof(Url).GetTypeInfo().Assembly); var uriExts = ReflectionHelper.GetAllExtensionMethods <Uri>(typeof(Url).GetTypeInfo().Assembly); var whitelist = new[] { "ToString", "IsValid", "ToUri", "Equals", "GetHashCode", "Clone", "Reset" }; // cases where string extension of the same name was excluded intentionally foreach (var method in urlMethods) { if (whitelist.Contains(method.Name)) { continue; } if (!stringExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { var args = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.Name)); Assert.Fail($"No equivalent string extension method found for Url.{method.Name}({args})"); } if (!uriExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { var args = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.Name)); Assert.Fail($"No equivalent System.Uri extension method found for Url.{method.Name}({args})"); } } }
// check that for every FlurlClient extension method, we have an equivalent Url and string extension public void extension_methods_consistently_supported() { var fcExts = ReflectionHelper.GetAllExtensionMethods <FlurlClient>(typeof(FlurlClient).GetTypeInfo().Assembly); var urlExts = ReflectionHelper.GetAllExtensionMethods <Url>(typeof(FlurlClient).GetTypeInfo().Assembly); var stringExts = ReflectionHelper.GetAllExtensionMethods <string>(typeof(FlurlClient).GetTypeInfo().Assembly); var whitelist = new[] { "WithUrl" }; // cases where Url method of the same name was excluded intentionally foreach (var method in fcExts) { if (whitelist.Contains(method.Name)) { continue; } if (!urlExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { var args = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.Name)); Assert.Fail($"No equivalent Url extension method found for FlurlClient.{method.Name}({args})"); } if (!stringExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { var args = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.Name)); Assert.Fail($"No equivalent string extension method found for FlurlClient.{method.Name}({args})"); } } }
// check that for every FlurlClient extension method, we have an equivalent Url and string extension public void extension_methods_consistently_supported() { var fcExts = ReflectionHelper.GetAllExtensionMethods <FlurlClient>(typeof(FlurlClient).Assembly); var urlExts = ReflectionHelper.GetAllExtensionMethods <Url>(typeof(FlurlClient).Assembly); var stringExts = ReflectionHelper.GetAllExtensionMethods <string>(typeof(FlurlClient).Assembly); foreach (var method in fcExts) { if (!urlExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { Assert.Fail("No equivalent URL extension method found for FlurlClient.{0}", method.Name); } if (!stringExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { Assert.Fail("No equivalent string extension method found for FlurlClient.{0}", method.Name); } } }
// check that for every FlurlClient extension method, we have an equivalent Url and string extension public void extension_methods_consistently_supported() { var fcExts = ReflectionHelper.GetAllExtensionMethods <FlurlClient>(typeof(FlurlClient).Assembly); var urlExts = ReflectionHelper.GetAllExtensionMethods <Url>(typeof(FlurlClient).Assembly); var stringExts = ReflectionHelper.GetAllExtensionMethods <string>(typeof(FlurlClient).Assembly); var whitelist = new[] { "GetCookies", "WithUrl" }; // cases where Url method of the same name was excluded intentionally foreach (var method in fcExts) { if (whitelist.Contains(method.Name)) { continue; } if (!urlExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { Assert.Fail("No equivalent URL extension method found for FlurlClient.{0}", method.Name); } if (!stringExts.Any(m => ReflectionHelper.AreSameMethodSignatures(method, m))) { Assert.Fail("No equivalent string extension method found for FlurlClient.{0}", method.Name); } } }