public void ThrowsWeavingExceptionIfNonStringParameterHasAllowEmptyAttribute(OptimizationLevel optimizationLevel) { string sourceCode = @" using Xtensions.ArgumentGuard; public class Target { public static void TestMethod([AllowEmpty] Target value) { } }"; WeavingException exception = Assert.Throws <WeavingException>(() => this.WeaveAssembly(sourceCode, optimizationLevel)); Assert.Equal( expected: "Attribute 'Xtensions.ArgumentGuard.AllowEmptyAttribute' is not allowed on parameter 'value' of method 'Target.TestMethod'.", actual: exception.Message); }
public void ThrowsWeavingExceptionWhenValueTypeConstraintIsMissingOnGenericType(OptimizationLevel optimizationLevel) { string sourceCode = @" using System; public static class Target<T> where T : Enum { public static void TestMethod(T value) { } }"; WeavingException exception = Assert.Throws <WeavingException>(() => this.WeaveAssembly(sourceCode, optimizationLevel)); Assert.Equal( expected: "Generic parameter 'T' of method (or one of its containing types) 'Target`1.TestMethod' should be constrained to value types (enums are always value types).", actual: exception.Message); }