/// <summary> /// Includes the <paramref name="methodName"/> for checks for <see cref="ArgumentNullException"/>. /// Overrides any method rules that may exclude the <paramref name="methodName"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="methodName">The method name.</param> /// <param name="type">The type.</param> /// <returns>The <paramref name="fixture"/>.</returns> public static IArgumentNullExceptionFixture IncludeMethod( this IArgumentNullExceptionFixture fixture, string methodName, Type type) { return(fixture.IncludeMethod(methodName, type != null ? type.FullName : null)); }
private void InitializeWithInjectedFixture( [Frozen] IArgumentNullExceptionFixture fixture, CustomAttribute sut) { // Assert Assert.Same(fixture, sut.Fixture); }
/// <summary> /// Customizes the specified fixture. /// </summary> /// <param name="fixture">The fixture to customize.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is <see langword="null"/>.</exception> public void Customize(IArgumentNullExceptionFixture fixture) { if (fixture == null) throw new ArgumentNullException("fixture"); _customizations.ForEach(customization => customization.Customize(fixture)); }
/// <summary> /// Customizes the specified <paramref name="fixture"/> by excluding private members. /// </summary> /// <param name="fixture">The fixture to customize.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> public virtual void Customize(IArgumentNullExceptionFixture fixture) { if (fixture == null) throw new ArgumentNullException("fixture"); fixture.ExcludePrivate(); }
/// <summary> /// Customizes the specified <paramref name="fixture"/> by substituting the <see cref="OriginalType"/> with the /// <see cref="NewType"/>. /// </summary> /// <param name="fixture">The fixture to customize.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> public void Customize(IArgumentNullExceptionFixture fixture) { if (fixture == null) throw new ArgumentNullException("fixture"); fixture.SubstituteType(OriginalType, NewType); }
/// <summary> /// Initializes a new instance of the <see cref="RequiresArgumentNullExceptionAttribute"/> class. /// </summary> /// <param name="fixture">The fixture.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> protected RequiresArgumentNullExceptionAttribute( IArgumentNullExceptionFixture fixture) { if (fixture == null) throw new ArgumentNullException("fixture"); _fixture = fixture; }
/// <summary> /// Includes the <paramref name="parameterName"/> for checks for <see cref="ArgumentNullException"/>. Overrides any parameter rules that may exclude the <paramref name="parameterName"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="parameterName">The parameter name.</param> /// <param name="type">The type.</param> /// <param name="methodName">The method name.</param> /// <returns>The <paramref name="fixture"/>.</returns> public static IArgumentNullExceptionFixture IncludeParameter( this IArgumentNullExceptionFixture fixture, string parameterName, Type type, string methodName = null) { return(fixture.IncludeParameter(parameterName, type != null ? type.FullName : null, methodName)); }
/// <summary> /// Includes the <paramref name="type"/> for checks for <see cref="ArgumentNullException"/>. /// Overrides any type rules that may exclude the <paramref name="type"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="type">The type.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> or <paramref name="type"/> /// parameters are <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture IncludeType(this IArgumentNullExceptionFixture fixture, Type type) { if (type == null) { throw new ArgumentNullException(nameof(type)); } return(fixture.IncludeType(type.FullName)); }
/// <summary> /// Customizes the specified <paramref name="fixture"/> by excluding private members. /// </summary> /// <param name="fixture">The fixture to customize.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> public virtual void Customize(IArgumentNullExceptionFixture fixture) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } fixture.ExcludePrivate(); }
/// <summary> /// Customizes the specified fixture. /// </summary> /// <param name="fixture">The fixture to customize.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is <see langword="null"/>.</exception> public void Customize(IArgumentNullExceptionFixture fixture) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } _customizations.ForEach(customization => customization.Customize(fixture)); }
/// <summary> /// Customizes the specified <paramref name="fixture"/> by substituting the <see cref="OriginalType"/> with the /// <see cref="NewType"/>. /// </summary> /// <param name="fixture">The fixture to customize.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> public void Customize(IArgumentNullExceptionFixture fixture) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } fixture.SubstituteType(OriginalType, NewType); }
/// <summary> /// Initializes a new instance of the <see cref="RequiresArgumentNullExceptionAttribute"/> class. /// </summary> /// <param name="fixture">The fixture.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> protected RequiresArgumentNullExceptionAttribute( IArgumentNullExceptionFixture fixture) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } Fixture = fixture; }
/// <summary> /// Excludes all private members. /// </summary> /// <param name="fixture">The fixture.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture ExcludePrivate(this IArgumentNullExceptionFixture fixture) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } fixture.BindingFlags &= ~BindingFlags.NonPublic; return(fixture); }
/// <summary> /// Sets the <paramref name="mask"/> of <see cref="BindingFlags"/> on the <paramref name="fixture"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="mask">The mask of <see cref="BindingFlags"/>.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture SetBindingFlags(this IArgumentNullExceptionFixture fixture, BindingFlags mask) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } fixture.BindingFlags = fixture.BindingFlags | mask; return(fixture); }
/// <summary> /// Excludes all types, methods and parameters. /// </summary> /// <param name="fixture">The fixture.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture ExcludeAll(this IArgumentNullExceptionFixture fixture) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } IRegexFilter regexFilter = fixture.GetRegexFilter(); regexFilter.ExcludeAll(); return(fixture); }
/// <summary> /// Customizes the specified <paramref name="fixture"/> by including only specified /// <see cref="IncludeAttribute.Type"/>, <see cref="IncludeAttribute.Method"/> and/or /// <see cref="IncludeAttribute.Parameter"/>. /// </summary> /// <param name="fixture">The fixture to customize.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> public override void Customize(IArgumentNullExceptionFixture fixture) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } if (Type != null && !string.IsNullOrWhiteSpace(TypeFullName)) { throw new InvalidOperationException("Type and TypeFullName cannot both be specified."); } base.Customize(fixture); if (!string.IsNullOrWhiteSpace(Parameter)) { if (!string.IsNullOrWhiteSpace(TypeFullName)) { fixture.IncludeParameter(Parameter, TypeFullName, Method); return; } fixture.IncludeParameter(Parameter, Type, Method); return; } if (!string.IsNullOrWhiteSpace(Method)) { if (!string.IsNullOrWhiteSpace(TypeFullName)) { fixture.IncludeMethod(Method, TypeFullName); return; } fixture.IncludeMethod(Method, Type); return; } if (!string.IsNullOrWhiteSpace(TypeFullName)) { fixture.IncludeType(TypeFullName); return; } if (Type == null) { throw new InvalidOperationException("Either the Type, Method or Parameter must be specified."); } fixture.IncludeType(Type); }
/// <summary> /// Customizes the specified <paramref name="fixture"/> by excluding all types. /// </summary> /// <param name="fixture">The fixture to customize.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> public virtual void Customize(IArgumentNullExceptionFixture fixture) { if (fixture == null) throw new ArgumentNullException("fixture"); if (ExclusionType.HasFlag(ExclusionType.Types)) fixture.ExcludeAllTypes(); if (ExclusionType.HasFlag(ExclusionType.Methods)) fixture.ExcludeAllMethods(); if (ExclusionType.HasFlag(ExclusionType.Parameters)) fixture.ExcludeAllParameters(); }
/// <summary> /// Applies the <paramref name="customization"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="customization">The customization to apply.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> or <paramref name="customization"/> /// parameters are <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture Customize(this IArgumentNullExceptionFixture fixture, IArgNullExCustomization customization) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } if (customization == null) { throw new ArgumentNullException(nameof(customization)); } customization.Customize(fixture); return(fixture); }
/// <summary> /// Removes all the filters that are instances of the <paramref name="filterType"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="filterType">The type of filter.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> or <paramref name="filterType"/> /// parameters are <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture RemoveFilters(this IArgumentNullExceptionFixture fixture, Type filterType) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } if (filterType == null) { throw new ArgumentNullException(nameof(filterType)); } fixture.Filters.RemoveAll(filterType.GetTypeInfo().IsInstanceOfType); return(fixture); }
internal void ApplyAllCustomizations( IArgumentNullExceptionFixture fixture, List<Mock<IArgNullExCustomization>> customizations) { // Arrange customizations.ForEach(mock => mock.Setup(c => c.Customize(fixture)).Verifiable()); var sut = new ArgNullExCompositeCustomization(customizations.Select(mock => mock.Object)); // Act ((IArgNullExCustomization)sut).Customize(fixture); // Assert Assert.NotEmpty(sut.Customizations); Assert.Equal(customizations.Count, sut.Customizations.Count()); customizations.ForEach(mock => mock.Verify()); }
internal void ApplyAllCustomizations( IArgumentNullExceptionFixture fixture, List <Mock <IArgNullExCustomization> > customizations) { // Arrange customizations.ForEach(mock => mock.Setup(c => c.Customize(fixture)).Verifiable()); var sut = new ArgNullExCompositeCustomization(customizations.Select(mock => mock.Object)); // Act ((IArgNullExCustomization)sut).Customize(fixture); // Assert Assert.NotEmpty(sut.Customizations); Assert.Equal(customizations.Count, sut.Customizations.Count()); customizations.ForEach(mock => mock.Verify()); }
/// <summary> /// Customizes the specified <paramref name="fixture"/> by including only specified /// <see cref="IncludeAttribute.Type"/>, <see cref="IncludeAttribute.Method"/> and/or /// <see cref="IncludeAttribute.Parameter"/>. /// </summary> /// <param name="fixture">The fixture to customize.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> public override void Customize(IArgumentNullExceptionFixture fixture) { if (fixture == null) throw new ArgumentNullException("fixture"); if (Type != null && !string.IsNullOrWhiteSpace(TypeFullName)) { throw new InvalidOperationException("Type and TypeFullName cannot both be specified."); } base.Customize(fixture); if (!string.IsNullOrWhiteSpace(Parameter)) { if (!string.IsNullOrWhiteSpace(TypeFullName)) { fixture.IncludeParameter(Parameter, TypeFullName, Method); return; } fixture.IncludeParameter(Parameter, Type, Method); return; } if (!string.IsNullOrWhiteSpace(Method)) { if (!string.IsNullOrWhiteSpace(TypeFullName)) { fixture.IncludeMethod(Method, TypeFullName); return; } fixture.IncludeMethod(Method, Type); return; } if (!string.IsNullOrWhiteSpace(TypeFullName)) { fixture.IncludeType(TypeFullName); return; } if (Type == null) throw new InvalidOperationException("Either the Type, Method or Parameter must be specified."); fixture.IncludeType(Type); }
/// <summary> /// Includes the <paramref name="typeFullName"/> for checks for <see cref="ArgumentNullException"/>. /// Overrides any type rules that may exclude the <paramref name="typeFullName"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="typeFullName">The <see cref="Type.FullName"/> of the <see cref="Type"/>.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> or <paramref name="typeFullName"/> /// parameters are <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture IncludeType(this IArgumentNullExceptionFixture fixture, string typeFullName) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } if (string.IsNullOrWhiteSpace(typeFullName)) { throw new ArgumentNullException(nameof(typeFullName)); } IRegexFilter regexFilter = fixture.GetRegexFilter(); regexFilter.IncludeType(typeFullName); return(fixture); }
/// <summary> /// Adds the mapping to substitute the <paramref name="originalType"/> with the <paramref name="newType"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="originalType">The original <see cref="Type"/>.</param> /// <param name="newType">The new <see cref="Type"/>.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/>, <paramref name="originalType"/>, or /// <paramref name="newType"/> parameters are <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture SubstituteType( this IArgumentNullExceptionFixture fixture, Type originalType, Type newType) { if (originalType == null) { throw new ArgumentNullException(nameof(originalType)); } if (newType == null) { throw new ArgumentNullException(nameof(newType)); } fixture.GetSubstituteTypeMapping().Substitute(originalType, newType); return(fixture); }
/// <summary> /// Adds the <paramref name="filters"/> to the <paramref name="fixture"/> collection of <see cref="IArgumentNullExceptionFixture.Filters"/> if they are not already in he collection. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="filters">The filters to add.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> or <paramref name="filters"/> /// parameters are <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture AddFilters(this IArgumentNullExceptionFixture fixture, IEnumerable <IFilter> filters) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } if (filters == null) { throw new ArgumentNullException(nameof(filters)); } foreach (IFilter filter in filters.Where(filter => !fixture.Filters.Contains(filter))) { fixture.Filters.Add(filter); } return(fixture); }
/// <summary> /// Removes all the supplied <paramref name="filtersToRemove"/> from the <paramref name="fixture"/> collection of <see cref="IArgumentNullExceptionFixture.Filters"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="filtersToRemove">The filters to remove.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> or <paramref name="filtersToRemove"/> /// parameters are <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture RemoveFilters(this IArgumentNullExceptionFixture fixture, IEnumerable <IFilter> filtersToRemove) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } if (filtersToRemove == null) { throw new ArgumentNullException(nameof(filtersToRemove)); } foreach (IFilter filter in filtersToRemove) { fixture.Filters.Remove(filter); } return(fixture); }
/// <summary> /// Gets the single <see cref="SubstituteType"/> from the <see cref="IArgumentNullExceptionFixture.Mappings"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <returns>The single <see cref="SubstituteType"/> from the /// <see cref="IArgumentNullExceptionFixture.Mappings"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> /// <exception cref="InvalidOperationException">There are zero of more than one <see cref="SubstituteType"/> /// objects in the <see cref="IArgumentNullExceptionFixture.Filters"/>.</exception> private static SubstituteType GetSubstituteTypeMapping(this IArgumentNullExceptionFixture fixture) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } SubstituteType substituteType = fixture.Mappings .OfType <SubstituteType>() .SingleOrDefault(); if (substituteType == null) { throw new InvalidOperationException("There is no SubstituteType in the mappings."); } return(substituteType); }
/// <summary> /// Gets the single <see cref="IRegexFilter"/> from the <see cref="IArgumentNullExceptionFixture.Filters"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <returns>The single <see cref="IRegexFilter"/> from the <see cref="IArgumentNullExceptionFixture.Filters"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is <see langword="null"/>.</exception> /// <exception cref="InvalidOperationException">There are zero of more than one <see cref="IRegexFilter"/> objects in the <see cref="IArgumentNullExceptionFixture.Filters"/>.</exception> private static IRegexFilter GetRegexFilter(this IArgumentNullExceptionFixture fixture) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } IRegexFilter regexFilter = fixture.Filters .OfType <IRegexFilter>() .SingleOrDefault(); if (regexFilter == null) { throw new InvalidOperationException("There is no IRegexFilter in the filters."); } return(regexFilter); }
/// <summary> /// Customizes the <see cref="Fixture"/> with any <see cref="CustomizeAttribute"/>. /// </summary> /// <param name="method">The method that may have been customized.</param> /// <param name="fixture">The fixture.</param> /// <exception cref="ArgumentNullException">The <paramref name="method"/> or <paramref name="fixture"/> /// parameters is <see langword="null"/>.</exception> private static void CustomizeFixture(MethodInfo method, IArgumentNullExceptionFixture fixture) { if (method == null) { throw new ArgumentNullException(nameof(method)); } if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } IEnumerable <CustomizeAttribute> customizeAttributes = method.GetCustomAttributes(typeof(CustomizeAttribute), inherit: false) .Cast <CustomizeAttribute>(); foreach (CustomizeAttribute customizeAttribute in customizeAttributes) { fixture.Customize(customizeAttribute.GetCustomization(method)); } }
/// <summary> /// Excludes the <paramref name="methodName"/> from checks for <see cref="ArgumentNullException"/>. /// </summary> /// <param name="fixture">The fixture.</param> /// <param name="methodName">The method name.</param> /// <param name="typeFullName">The <see cref="Type.FullName"/> of the <see cref="Type"/>.</param> /// <returns>The <paramref name="fixture"/>.</returns> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> or <paramref name="methodName"/> /// parameters are <see langword="null"/>.</exception> public static IArgumentNullExceptionFixture ExcludeMethod( this IArgumentNullExceptionFixture fixture, string methodName, string typeFullName = null) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } if (string.IsNullOrWhiteSpace(methodName)) { throw new ArgumentNullException(nameof(methodName)); } IRegexFilter regexFilter = fixture.GetRegexFilter(); regexFilter.ExcludeMethod(methodName, typeFullName); return(fixture); }
/// <summary> /// Customizes the specified <paramref name="fixture"/> by excluding all types. /// </summary> /// <param name="fixture">The fixture to customize.</param> /// <exception cref="ArgumentNullException">The <paramref name="fixture"/> parameter is /// <see langword="null"/>.</exception> public virtual void Customize(IArgumentNullExceptionFixture fixture) { if (fixture == null) { throw new ArgumentNullException(nameof(fixture)); } if (ExclusionType.HasFlag(ExclusionType.Types)) { fixture.ExcludeAllTypes(); } if (ExclusionType.HasFlag(ExclusionType.Methods)) { fixture.ExcludeAllMethods(); } if (ExclusionType.HasFlag(ExclusionType.Parameters)) { fixture.ExcludeAllParameters(); } }
public CustomAttribute(IArgumentNullExceptionFixture fixture) : base(fixture) { }
public CustomAttribute(IArgumentNullExceptionFixture fixture) : base(fixture) { }
/// <summary> /// Customizes the <see cref="Fixture"/> with any <see cref="CustomizeAttribute"/>. /// </summary> /// <param name="method">The method that may have been customized.</param> /// <param name="fixture">The fixture.</param> /// <exception cref="ArgumentNullException">The <paramref name="method"/> or <paramref name="fixture"/> /// parameters is <see langword="null"/>.</exception> private static void CustomizeFixture(MethodInfo method, IArgumentNullExceptionFixture fixture) { if (method == null) throw new ArgumentNullException("method"); if (fixture == null) throw new ArgumentNullException("fixture"); IEnumerable<CustomizeAttribute> customizeAttributes = method.GetCustomAttributes(typeof(CustomizeAttribute), inherit: false) .Cast<CustomizeAttribute>(); foreach (CustomizeAttribute customizeAttribute in customizeAttributes) { fixture.Customize(customizeAttribute.GetCustomization(method)); } }
public void ApplyACustomization( IArgumentNullExceptionFixture fixture, Mock<IArgNullExCustomization> customizationMock) { // Arrange customizationMock.Setup(c => c.Customize(fixture)).Verifiable(); // Act IArgumentNullExceptionFixture actual = fixture.Customize(customizationMock.Object); // Assert Assert.Same(fixture, actual); customizationMock.Verify(); }