/// <summary> /// Helper method. If the parameter type is contained in <see cref="ExpectedConversions"/>, /// converts the specified values to that type and asserts that the attribute produces those /// exact values. Otherwise, asserts that a type coercion exception is thrown. /// </summary> public void AssertCoercionErrorOrMatchingSequence(Type parameterType, IEnumerable valuesToConvert) { var param = StubParameterInfo.OfType(parameterType); if (ExpectedConversions.Contains(parameterType)) { // Important: do not use conversion procedure from NUnit framework. That is part of the system // under test. This conversion procedure must be dead simple, no more than a wrapper over // new byte[] { 1, 2, 3 }, new sbyte { 1, 2, 3 }, etc. var convertedValues = valuesToConvert.Cast <object>().Select(value => Convert.ChangeType(value, parameterType)); Assert.That(Attribute.GetData(null, param), Is.EqualTo(convertedValues).AsCollection.Using((IEqualityComparer)EqualityComparer <object> .Default)); } else { Assert.That(() => Attribute.GetData(null, param), Throws.Exception.Message.Contains("cannot be passed to a parameter of type")); } }
private static object[] GetData(RangeAttribute rangeAttribute, Type parameterType) { return(rangeAttribute.GetData(null, StubParameterInfo.OfType(parameterType)).Cast <object>().ToArray()); }