public void MethodDescription_CreateThrowsArgumentException_WhenParameterIsOptional() { // Arrange Type type = typeof(ITestActor); MethodInfo methodInfo = type.GetMethod("MethodWithOptional"); ParameterInfo parameterInfo = methodInfo.GetParameters()[0]; // Act Action action = () => MethodArgumentDescription.Create("actor", methodInfo, parameterInfo); // Assert action.Should().ThrowExactly <ArgumentException>() .WithMessage("Method 'MethodWithOptional' of actor interface '*ITestActor' has out/ref/optional parameter 'value'. The actor interface methods must not have out, ref or optional parameters.*") .And.ParamName.Should().Be("actorInterfaceType"); }
public void MethodDescription_CreateThrowsArgumentException_WhenParameterHasVariableLength() { // Arrange Type type = typeof(ITestActor); MethodInfo methodInfo = type.GetMethod("MethodWithParams"); ParameterInfo parameterInfo = methodInfo.GetParameters()[0]; // Act Action action = () => MethodArgumentDescription.Create("actor", methodInfo, parameterInfo); // Assert action.Should().ThrowExactly <ArgumentException>() .WithMessage("Method 'MethodWithParams' of actor interface '*ITestActor' has variable length parameter 'values'. The actor interface methods must not have variable length parameters.*") .And.ParamName.Should().Be("actorInterfaceType"); }
public void MethodArgumentDescription_CreatMethodArgumentDescription() { // Arrange MethodInfo methodInfo = typeof(ITestActor).GetMethod("MethodWithArguments"); ParameterInfo parameterInfo = methodInfo.GetParameters()[0]; // Act var description = MethodArgumentDescription.Create("actor", methodInfo, parameterInfo); // Assert description.Should().NotBeNull(); using var _ = new AssertionScope(); description.Name.Should().Be("number"); description.ArgumentType.Should().Be <int>(); }
internal static MethodDescription Create(string remotedInterfaceKindName, MethodInfo methodInfo, bool useCRCIdGeneration) { var parameters = methodInfo.GetParameters(); var argumentList = new List <MethodArgumentDescription>(parameters.Length); var hasCancellationToken = false; foreach (var param in parameters) { if (hasCancellationToken) { // If the method has a cancellation token, then it must be the last argument. throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, SR.ErrorRemotedMethodCancellationTokenOutOfOrder, remotedInterfaceKindName, methodInfo.Name, methodInfo.DeclaringType.FullName, param.Name, typeof(CancellationToken)), remotedInterfaceKindName + "InterfaceType"); } if (param.ParameterType == typeof(CancellationToken)) { hasCancellationToken = true; } else { argumentList.Add(MethodArgumentDescription.Create(remotedInterfaceKindName, methodInfo, param)); } } return(new MethodDescription( methodInfo, argumentList.ToArray(), hasCancellationToken, useCRCIdGeneration)); }