/// <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());
        }
示例#7
0
 /// <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;
 }
示例#8
0
 /// <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)
 {
 }
示例#9
0
 /// <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;
 }
示例#10
0
 /// <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;
 }
示例#12
0
 public ArgumentInstance(object value)
 {
     Constraint = Is.Anything();
     Type = ArgumentType.ArgumentOut;
     ReturnValue = value;
 }
示例#13
0
 /// <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));
 }
示例#14
0
        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;
 }
示例#16
0
 internal static void AddInArgument(AbstractConstraint constraint)
 {
     InitializeThreadStatic();
     args.Add(new ArgumentDefinition(constraint));
 }
示例#17
0
 internal static void AddRefArgument(AbstractConstraint constraint, object returnValue)
 {
     InitializeThreadStatic();
     args.Add(new ArgumentDefinition(constraint, returnValue));
 }
示例#18
0
 public ArgumentDefinition(object returnValue)
 {
     this.InOutRef = InOutRefArgument.OutArg;
     this.returnValue = returnValue;
     this.constraint = Is.Anything();
 }
示例#19
0
 public ArgumentDefinition(AbstractConstraint constraint, object returnValue)
 {
     this.InOutRef = InOutRefArgument.RefArg;
     this.constraint = constraint;
     this.returnValue = returnValue;
 }
示例#20
0
 public ArgumentDefinition(AbstractConstraint constraint)
 {
     this.InOutRef = InOutRefArgument.InArg;
     this.constraint = constraint;
     this.returnValue = null;
 }
示例#21
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="index"></param>
 /// <param name="arg1"></param>
 public ListElement(int index, AbstractConstraint arg1)
 {
     this.index = index;
     this.arg1 = arg1;
 }
示例#22
0
 /// <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));
 }
示例#23
0
 public ArgumentInstance(AbstractConstraint constraint, object value)
 {
     Constraint = constraint;
     Type = ArgumentType.ArgumentRef;
     ReturnValue = value;
 }
示例#24
0
 /// <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));
 }
示例#25
0
 /// <summary>
 /// Adds a constraint for an argument
 /// </summary>
 /// <param name="constraint"></param>
 internal static void AddArgument(AbstractConstraint constraint)
 {
     Initialize();
     arguments.Add(new ArgumentInstance(constraint));
 }
示例#26
0
 /// <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"));
        }
示例#28
0
 /// <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));
 }
示例#29
0
 /// <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));
 }
示例#30
0
 /// <summary>
 /// Creates a new <see cref="And"/> instance.
 /// </summary>
 /// <param name="c1">C1.</param>
 public Not(AbstractConstraint c1)
 {
     this.c1 = c1;
 }
示例#31
0
 /// <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;
 }
示例#32
0
 /// <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));
 }
示例#33
0
 /// <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;
 }
示例#34
0
 /// <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);
 }
示例#35
0
 /// <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;
 }
示例#36
0
 /// <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));
 }
示例#37
0
 /// <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)
 {
 }
示例#38
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="index"></param>
 /// <param name="arg1"></param>
 public ListElement(int index, AbstractConstraint arg1)
 {
     this.index = index;
     this.arg1  = arg1;
 }
示例#39
0
 /// <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;
 }
示例#40
0
 /// <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);
 }
示例#41
0
 /// <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);
 }
示例#42
0
 public ArgumentInstance(AbstractConstraint constraint)
 {
     Constraint = constraint;
     Type = ArgumentType.ArgumentIn;
     ReturnValue = null;
 }
示例#43
0
 /// <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);
 }
示例#44
0
 /// <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));
 }