public void ComposeMessageFromParameters( Type classUnderTest, MethodBase methodUnderTest, string nullParameter, Exception innerException) { // Act var sut = new CompositionException(classUnderTest, methodUnderTest, nullParameter, innerException); // Assert Assert.Contains(classUnderTest.Name, sut.Message); Assert.Contains(methodUnderTest.Name, sut.Message); Assert.Contains(nullParameter, sut.Message); Assert.Contains(innerException.ToString(), sut.Message); }
public void ComposeMessageFromParameters( Type classUnderTest, Mock<MethodBase> methodUnderTestMock, string nullParameter, Exception innerException) { // Arrange methodUnderTestMock.SetupGet(m => m.Name).Returns("Name" + Guid.NewGuid()); // Act var sut = new CompositionException(classUnderTest, methodUnderTestMock.Object, nullParameter, innerException); // Assert Assert.Contains(classUnderTest.Name, sut.Message); Assert.Contains(methodUnderTestMock.Object.Name, sut.Message); Assert.Contains(nullParameter, sut.Message); Assert.Contains(innerException.ToString(), sut.Message); }
public void RetainInnerException( [Frozen] Exception expected, CompositionException sut) { Assert.Same(expected, sut.InnerException); }
public void RetainInnerException( [Frozen]Exception expected, CompositionException sut) { Assert.Same(expected, sut.InnerException); }
/// <summary> /// Sets up the parameter data for the <paramref name="method"/> on the <paramref name="type"/>. /// </summary> /// <param name="type">The <see cref="Type"/> the method belongs to.</param> /// <param name="method">The method.</param> /// <returns>The parameter data for the <paramref name="method"/> on the <paramref name="type"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type"/> or <paramref name="method"/> parameters /// are <see langword="null"/>.</exception> private IEnumerable<MethodData> SetupParameterData(Type type, MethodBase method) { if (type == null) throw new ArgumentNullException("type"); if (method == null) throw new ArgumentNullException("method"); ParameterInfo[] parameterInfos = method.GetParameters(); var data = new List<MethodData>(parameterInfos.Length); for (int parameterIndex = 0; parameterIndex < parameterInfos.Length; ++parameterIndex) { ParameterInfo parameterInfo = parameterInfos[parameterIndex]; // Apply the filters against the parameter. if (ParameterFilters.Any(filter => filter.ApplyFilter(type, method, parameterInfo))) continue; try { object[] parameters = _specimenProvider.GetParameterSpecimens(parameterInfos, parameterIndex); object instanceUnderTest = null; if (!method.IsStatic) { instanceUnderTest = _specimenProvider.CreateInstance(type); } data.Add( new MethodData( classUnderTest: type, instanceUnderTest: instanceUnderTest, methodUnderTest: method, parameters: parameters, nullParameter: parameterInfo.Name, nullIndex: parameterIndex, executionSetup: new DefaultExecutionSetup())); } catch (Exception ex) { var compositionEx = new CompositionException(type, method, parameterInfo.Name, ex); data.Add( new MethodData( classUnderTest: type, instanceUnderTest: null, methodUnderTest: method, parameters: new object[] { }, nullParameter: parameterInfo.Name, nullIndex: parameterIndex, executionSetup: new ErroredExecutionSetup(compositionEx))); } } return data; }
/// <summary> /// Sets up the parameter data for the <paramref name="method"/> on the <paramref name="type"/>. /// </summary> /// <param name="type">The <see cref="Type"/> the method belongs to.</param> /// <param name="method">The method.</param> /// <returns>The parameter data for the <paramref name="method"/> on the <paramref name="type"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="type"/> or <paramref name="method"/> parameters /// are <see langword="null"/>.</exception> private IEnumerable <MethodData> SetupParameterData(Type type, MethodBase method) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (method == null) { throw new ArgumentNullException(nameof(method)); } ParameterInfo[] parameterInfos = method.GetParameters(); var data = new List <MethodData>(parameterInfos.Length); for (int parameterIndex = 0; parameterIndex < parameterInfos.Length; ++parameterIndex) { ParameterInfo parameterInfo = parameterInfos[parameterIndex]; // Apply the filters against the parameter. if (ParameterFilters.Any(filter => filter.ApplyFilter(type, method, parameterInfo))) { continue; } try { object[] parameters = SpecimenProvider.GetParameterSpecimens(parameterInfos, parameterIndex); object instanceUnderTest = null; if (!method.IsStatic) { instanceUnderTest = SpecimenProvider.CreateInstance(type); } data.Add( new MethodData( classUnderTest: type, instanceUnderTest: instanceUnderTest, methodUnderTest: method, parameters: parameters, nullParameter: parameterInfo.Name, nullIndex: parameterIndex, executionSetup: new DefaultExecutionSetup())); } catch (Exception ex) { var compositionEx = new CompositionException(type, method, parameterInfo.Name, ex); data.Add( new MethodData( classUnderTest: type, instanceUnderTest: null, methodUnderTest: method, parameters: new object[] { }, nullParameter: parameterInfo.Name, nullIndex: parameterIndex, executionSetup: new ErroredExecutionSetup(compositionEx))); } } return(data); }