/// <summary> /// Creates a new <see cref="ConstraintsExpectation"/> instance. /// </summary> /// <param name="invocation">Invocation for this expectation</param> /// <param name="constraints">Constraints.</param> /// <param name="expectedRange">Number of method calls for this expectations</param> public ConstraintsExpectation(IInvocation invocation,AbstractConstraint[] constraints, Range expectedRange) : base(invocation, expectedRange) { Validate.IsNotNull(()=>constraints); this.constraints = constraints; ConstraintsMatchMethod(); }
public void Should_Be_Possible_To_Search_SubKeys_From_KeyName() { object fakeFoundSubKeys = new string[] { "Graphics", "GData", "XPTO" }; Dictionary<string, object> searchKeysParameters = new Dictionary<string, object>(); searchKeysParameters.Add(registry_object_ItemsChoices.hive.ToString(), eHiveNames.HKEY_LOCAL_MACHINE.ToString()); searchKeysParameters.Add(registry_object_ItemsChoices.key.ToString(), "Microsoft"); AbstractConstraint[] invokeMethodConstraints = new AbstractConstraint[] { new Equal("EnumKey"), new Anything(), new Anything() }; MockRepository mocks = new MockRepository(); WmiDataProvider fakeWmiPrv = mocks.DynamicMock<WmiDataProvider>(); Expect.Call(fakeWmiPrv.InvokeMethod("", null, "")).Constraints(invokeMethodConstraints).Return(fakeFoundSubKeys); mocks.ReplayAll(); RegistryObjectCollector systemDataSource = new RegistryObjectCollector() { WmiDataProvider = fakeWmiPrv }; IList<string> registrySubKeys = systemDataSource.GetValues(searchKeysParameters); mocks.VerifyAll(); Assert.IsNotNull(registrySubKeys); Assert.AreEqual(3, registrySubKeys.Count); Assert.AreEqual("Graphics", registrySubKeys[0]); Assert.AreEqual("GData", registrySubKeys[1]); Assert.AreEqual("XPTO", registrySubKeys[2]); }
/// <summary> /// constructor /// </summary> /// <param name="arg1"></param> public CollectionCount(AbstractConstraint arg1) { if (arg1 == null) throw new ArgumentNullException("arg1"); this.arg1 = arg1; }
/// <summary> /// Creates a new <see cref="ConstraintsExpectation"/> instance. /// </summary> /// <param name="expectation">Expectation.</param> /// <param name="constraints">Constraints.</param> public ConstraintsExpectation(IExpectation expectation, AbstractConstraint[] constraints) : base(expectation) { Validate.IsNotNull(() => constraints); this.constraints = constraints; ConstraintsMatchMethod(); }
/// <summary> /// constructor /// </summary> /// <param name="arg1"></param> public CollectionCount(AbstractConstraint arg1) { if (arg1 == null) { throw new ArgumentNullException("arg1"); } this.arg1 = arg1; }
/// <summary> /// Builds the default expectation. /// </summary> /// <param name="invocation">The invocation.</param> /// <param name="method">The method.</param> /// <param name="args">The args.</param> /// <param name="callCallRangeExpectation">The call call range expectation.</param> /// <returns></returns> public IExpectation BuildDefaultExpectation(IInvocation invocation, MethodInfo method, object[] args, Func<Range> callCallRangeExpectation) { var parameters = method.GetParameters(); if (!Array.Exists(parameters, p => p.IsOut)) { return new ArgsEqualExpectation(invocation, args, callCallRangeExpectation()); } //The value of an incoming out parameter variable is ignored var constraints = new AbstractConstraint[parameters.Length]; for (var i = 0; i < parameters.Length; i++) { constraints[i] = parameters[i].IsOut ? Is.Anything() : Is.Equal(args[i]); } return new ConstraintsExpectation(invocation, constraints, callCallRangeExpectation()); }
/// <summary> /// Creates a new <see cref="T:KeyedListElement"/> instance. /// </summary> /// <param name="key">The key of the list element.</param> /// <param name="constraint">The constraint that should be applied to the list element.</param> public KeyedListElement(T key, AbstractConstraint constraint) { _key = key; _constraint = constraint; }
/// <summary> /// Creates a new <see cref="PropertyConstraint"/> instance. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="constraint">Constraint to place on the property value.</param> public PropertyConstraint(string propertyName, AbstractConstraint constraint) : this(null, propertyName, constraint) { }
/// <summary> /// Creates a new <see cref="CollectionCount"/> instance. /// </summary> /// <param name="constraint">The constraint that should be applied to the collection count.</param> public CollectionCount(AbstractConstraint constraint) { _constraint = constraint; }
/// <summary> /// Constrains the parameter to have a property satisfying a specified constraint. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="propertyConstraint">Constraint for the property.</param> public static AbstractConstraint ValueConstraint(string propertyName, AbstractConstraint propertyConstraint) { return(new PropertyConstraint(propertyName, propertyConstraint)); }
private static IConfirmer CreateMockConfirmerWithExpectation(MockRepository mockRepository, AbstractConstraint messageConstraint, bool confirmReturnValue) { IConfirmer confirmer = mockRepository.StrictMock<IConfirmer>(); Expect.Call(()=>confirmer.Confirm(null, null)) .Constraints(messageConstraint,Is.NotNull()) .Do((Delegates.Action<string, ConfirmationDelegate>)( (message, confirmationDelegate) => confirmationDelegate(confirmReturnValue))); return confirmer; }
public ArgumentInstance(object value) { Constraint = Is.Anything(); Type = ArgumentType.ArgumentOut; ReturnValue = value; }
/// <summary> /// Adds a constraint for a "ref" argument /// </summary> /// <param name="constraint"></param> /// <param name="value"></param> internal static void AddRefArgument(AbstractConstraint constraint, object value) { Initialize(); arguments.Add(new ArgumentInstance(constraint, value)); }
internal static void CheckMethodSignature(MethodInfo method) { InitializeThreadStatic(); ParameterInfo[] parameters = method.GetParameters(); AbstractConstraint[] constraints = new AbstractConstraint[parameters.Length]; if (args.Count < parameters.Length) { throw new InvalidOperationException( string.Format("When using Arg<T>, all arguments must be defined using Arg<T>.Is, Arg<T>.Text, Arg<T>.List, Arg<T>.Ref or Arg<T>.Out. {0} arguments expected, {1} have been defined.", parameters.Length, args.Count)); } if (args.Count > parameters.Length) { throw new InvalidOperationException( string.Format("Use Arg<T> ONLY within a mock method call while recording. {0} arguments expected, {1} have been defined.", parameters.Length, args.Count)); } for (int i = 0; i < parameters.Length; i++) { if (parameters[i].IsOut) { if (args[i].InOutRef != InOutRefArgument.OutArg) { throw new InvalidOperationException( string.Format("Argument {0} must be defined as: out Arg<T>.Out(returnvalue).Dummy", i)); } } else if (parameters[i].ParameterType.IsByRef) { if (args[i].InOutRef != InOutRefArgument.RefArg) { throw new InvalidOperationException( string.Format("Argument {0} must be defined as: ref Arg<T>.Ref(constraint, returnvalue).Dummy", i)); } } else if (args[i].InOutRef != InOutRefArgument.InArg) { throw new InvalidOperationException( string.Format("Argument {0} must be defined using: Arg<T>.Is, Arg<T>.Text or Arg<T>.List", i)); } } }
/// <summary> /// constructor /// </summary> /// <param name="key"></param> /// <param name="arg1"></param> public KeyedListElement(T key, AbstractConstraint arg1) { this.key = key; this.arg1 = arg1; }
internal static void AddInArgument(AbstractConstraint constraint) { InitializeThreadStatic(); args.Add(new ArgumentDefinition(constraint)); }
internal static void AddRefArgument(AbstractConstraint constraint, object returnValue) { InitializeThreadStatic(); args.Add(new ArgumentDefinition(constraint, returnValue)); }
public ArgumentDefinition(object returnValue) { this.InOutRef = InOutRefArgument.OutArg; this.returnValue = returnValue; this.constraint = Is.Anything(); }
public ArgumentDefinition(AbstractConstraint constraint, object returnValue) { this.InOutRef = InOutRefArgument.RefArg; this.constraint = constraint; this.returnValue = returnValue; }
public ArgumentDefinition(AbstractConstraint constraint) { this.InOutRef = InOutRefArgument.InArg; this.constraint = constraint; this.returnValue = null; }
/// <summary> /// constructor /// </summary> /// <param name="index"></param> /// <param name="arg1"></param> public ListElement(int index, AbstractConstraint arg1) { this.index = index; this.arg1 = arg1; }
/// <summary> /// Constrains the parameter to have a public field satisfying a specified constraint. /// </summary> /// <param name="declaringType">The type that declares the public field, used to disambiguate between public fields.</param> /// <param name="publicFieldName">Name of the public field.</param> /// <param name="publicFieldConstraint">Constraint for the public field.</param> public static AbstractConstraint ValueConstraint(Type declaringType, string publicFieldName, AbstractConstraint publicFieldConstraint) { return(new PublicFieldConstraint(declaringType, publicFieldName, publicFieldConstraint)); }
public ArgumentInstance(AbstractConstraint constraint, object value) { Constraint = constraint; Type = ArgumentType.ArgumentRef; ReturnValue = value; }
/// <summary> /// Determines that an element of the parameter collections conforms to another AbstractConstraint. /// </summary> /// <param name="index">The zero-based index of the list element.</param> /// <param name="constraint">The constraint which should be applied to the list element.</param> public static AbstractConstraint Element(int index, AbstractConstraint constraint) { return(new ListElement(index, constraint)); }
/// <summary> /// Adds a constraint for an argument /// </summary> /// <param name="constraint"></param> internal static void AddArgument(AbstractConstraint constraint) { Initialize(); arguments.Add(new ArgumentInstance(constraint)); }
/// <summary> /// Determines that an element of the parameter collections conforms to another AbstractConstraint. /// </summary> /// <param name="key">The key of the element.</param> /// <param name="constraint">The constraint which should be applied to the element.</param> public static AbstractConstraint Element <T>(T key, AbstractConstraint constraint) { return(new KeyedListElement <T>(key, constraint)); }
public void Should_Be_Possible_To_Search_KeyValues_From_KeyName() { object fakeFoundKeyValues = new List<string>(new string[] { "Risk Manager", "PCN", "Workflow Manager", "Dashboard" } ); Dictionary<string, object> searchValuesParameters = new Dictionary<string, object>(); searchValuesParameters.Add(registry_object_ItemsChoices.hive.ToString(), eHiveNames.HKEY_LOCAL_MACHINE.ToString()); searchValuesParameters.Add(registry_object_ItemsChoices.key.ToString(), "SOFTWARE\\Modulo"); searchValuesParameters.Add(registry_object_ItemsChoices.name.ToString(), "^.*"); AbstractConstraint[] invokeMethodConstraints = new AbstractConstraint[] { new Equal("EnumValues"), new Anything(), new Anything() }; MockRepository mocks = new MockRepository(); WmiDataProvider fakeWmiPrv = mocks.DynamicMock<WmiDataProvider>(); Expect.Call(fakeWmiPrv.InvokeMethod("", null, "")).Constraints(invokeMethodConstraints).Return(fakeFoundKeyValues); mocks.ReplayAll(); RegistryObjectCollector systemDataSource = new RegistryObjectCollector() { WmiDataProvider = fakeWmiPrv }; IList<string> registryKeyValues = systemDataSource.GetValues(searchValuesParameters); mocks.VerifyAll(); Assert.IsNotNull(registryKeyValues); Assert.AreEqual(4, registryKeyValues.Count); Assert.IsTrue(registryKeyValues[0].Equals("Risk Manager")); Assert.IsTrue(registryKeyValues[1].Equals("PCN")); Assert.IsTrue(registryKeyValues[2].Equals("Workflow Manager")); Assert.IsTrue(registryKeyValues[3].Equals("Dashboard")); }
/// <summary> /// Determines that the parameter collection has the specified number of elements. /// </summary> /// <param name="constraint">The constraint that should be applied to the collection count.</param> public static AbstractConstraint Count(AbstractConstraint constraint) { return(new CollectionCount(constraint)); }
/// <summary> /// Constrains the parameter to have a property satisfying a specified constraint. /// </summary> /// <param name="declaringType">The type that declares the property, used to disambiguate between properties.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="propertyConstraint">Constraint for the property.</param> public static AbstractConstraint ValueConstraint(Type declaringType, string propertyName, AbstractConstraint propertyConstraint) { return(new PropertyConstraint(declaringType, propertyName, propertyConstraint)); }
/// <summary> /// Creates a new <see cref="And"/> instance. /// </summary> /// <param name="c1">C1.</param> public Not(AbstractConstraint c1) { this.c1 = c1; }
/// <summary> /// Creates a new <see cref="PublicFieldConstraint"/> instance, specifying a disambiguating /// <paramref name="declaringType"/> for the public field. /// </summary> /// <param name="declaringType">The type that declares the public field, used to disambiguate between public fields.</param> /// <param name="publicFieldName">Name of the public field.</param> /// <param name="constraint">Constraint to place on the public field value.</param> public PublicFieldConstraint(Type declaringType, string publicFieldName, AbstractConstraint constraint) { this.declaringType = declaringType; this.publicFieldName = publicFieldName; this.constraint = constraint; }
/// <summary> /// Constrains the parameter to have a public field satisfying a specified constraint. /// </summary> /// <param name="publicFieldName">Name of the public field.</param> /// <param name="publicFieldConstraint">Constraint for the public field.</param> public static AbstractConstraint ValueConstraint(string publicFieldName, AbstractConstraint publicFieldConstraint) { return(new PublicFieldConstraint(publicFieldName, publicFieldConstraint)); }
/// <summary> /// Creates a new <see cref="PropertyConstraint"/> instance, specifying a disambiguating /// <paramref name="declaringType"/> for the property. /// </summary> /// <param name="declaringType">The type that declares the property, used to disambiguate between properties.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="constraint">Constraint to place on the property value.</param> public PropertyConstraint(Type declaringType, string propertyName, AbstractConstraint constraint) { this.declaringType = declaringType; this.propertyName = propertyName; this.constraint = constraint; }
/// <summary> /// Constrains the parameter to have a public field satisfying a specified constraint. /// </summary> /// <param name="publicFieldName">Name of the public field.</param> /// <param name="publicFieldConstraint">Constraint for the public field.</param> public static AbstractConstraint ValueConstraint(string publicFieldName, AbstractConstraint publicFieldConstraint) { return new PublicFieldConstraint(publicFieldName, publicFieldConstraint); }
/// <summary> /// Creates a new <see cref="ListElement"/> instance. /// </summary> /// <param name="index">The zero-based index of the list element.</param> /// <param name="constraint">The constraint that should be applied to the list element.</param> public ListElement(int index, AbstractConstraint constraint) { _index = index; _constraint = constraint; }
/// <summary> /// Determines that an element of the parameter collections conforms to another AbstractConstraint. /// </summary> /// <param name="index">The zero-based index of the list element.</param> /// <param name="constraint">The constraint which should be applied to the list element.</param> public T Element(int index, AbstractConstraint constraint) { ArgManager.AddInArgument(List.Element(index, constraint)); return(default(T)); }
/// <summary> /// Creates a new <see cref="PublicFieldConstraint"/> instance. /// </summary> /// <param name="publicFieldName">Name of the public field.</param> /// <param name="constraint">Constraint to place on the public field value.</param> public PublicFieldConstraint(string publicFieldName, AbstractConstraint constraint) : this(null, publicFieldName, constraint) { }
/// <summary> /// Creates a new <see cref="And"/> instance. /// </summary> /// <param name="c1">C1.</param> /// <param name="c2">C2.</param> public And(AbstractConstraint c1, AbstractConstraint c2) { this.c1 = c1; this.c2 = c2; }
/// <summary> /// Constrains the parameter to have a property satisfying a specified constraint. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="propertyConstraint">Constraint for the property.</param> public static AbstractConstraint ValueConstraint(string propertyName, AbstractConstraint propertyConstraint) { return new PropertyConstraint(propertyName, propertyConstraint); }
/// <summary> /// Constrains the parameter to have a property satisfying a specified constraint. /// </summary> /// <param name="declaringType">The type that declares the property, used to disambiguate between properties.</param> /// <param name="propertyName">Name of the property.</param> /// <param name="propertyConstraint">Constraint for the property.</param> public static AbstractConstraint ValueConstraint(Type declaringType, string propertyName, AbstractConstraint propertyConstraint) { return new PropertyConstraint(declaringType, propertyName, propertyConstraint); }
public ArgumentInstance(AbstractConstraint constraint) { Constraint = constraint; Type = ArgumentType.ArgumentIn; ReturnValue = null; }
/// <summary> /// Constrains the parameter to have a public field satisfying a specified constraint. /// </summary> /// <param name="declaringType">The type that declares the public field, used to disambiguate between public fields.</param> /// <param name="publicFieldName">Name of the public field.</param> /// <param name="publicFieldConstraint">Constraint for the public field.</param> public static AbstractConstraint ValueConstraint(Type declaringType, string publicFieldName, AbstractConstraint publicFieldConstraint) { return new PublicFieldConstraint(declaringType, publicFieldName, publicFieldConstraint); }
/// <summary> /// Determines that the parameter collection has the specified number of elements. /// </summary> /// <param name="constraint">The constraint that should be applied to the collection count.</param> public T Count(AbstractConstraint constraint) { ArgManager.AddInArgument(List.Count(constraint)); return(default(T)); }