コード例 #1
0
        public void AddChild(CallPattern callPattern, IMethodMock methodMock, int id)
        {
            var node = new MethodMockMatcherTreeNode(methodMock, id);

            callPattern.MethodMockNode = node;
            AddChildInternal(callPattern, 0, node);
        }
コード例 #2
0
		public static void Attach(IMethodMock methodMock)
		{
			var behavior = new PreserveRefOutValuesBehavior(methodMock);
			var madeReplacements = ReplaceRefOutArgsWithAnyMatcher(methodMock.CallPattern);
			if (madeReplacements)
				methodMock.Behaviors.Add(behavior);
		}
コード例 #3
0
		public static void Attach(IMethodMock methodMock)
		{
			var behavior = new PreserveRefOutValuesBehavior(methodMock);
			var madeReplacements = ReplaceRefOutArgsWithAnyMatcher(methodMock.CallPattern);
			if (madeReplacements)
				methodMock.Behaviors.Add(behavior);
		}
コード例 #4
0
		public static void Attach(IMethodMock methodMock)
		{
			var callPattern = methodMock.CallPattern;
			if (!(callPattern.Method is ConstructorInfo) || callPattern.Method.IsStatic || !(callPattern.InstanceMatcher is AnyMatcher))
				return;

			methodMock.Behaviors.Add(new ConstructorMockBehavior());
		}           
コード例 #5
0
 public OccurrencesMatcherTreeNode(IMethodMock mock)
     : this()
 {
     if (mock != null)
     {
         Mocks.Add(mock);
     }
 }
コード例 #6
0
		public static void Attach(IMethodMock methodMock)
		{
			var callPattern = methodMock.CallPattern;
			if (!(callPattern.Method is ConstructorInfo)
				|| callPattern.Method.IsStatic
				|| !(callPattern.InstanceMatcher is AnyMatcher)
				|| typeof(string) == callPattern.Method.DeclaringType
#if !COREFX
				|| typeof(ContextBoundObject).IsAssignableFrom(callPattern.Method.DeclaringType)
#endif
				)
				return;

			methodMock.Behaviors.Add(new ConstructorMockBehavior());
		}
コード例 #7
0
        public static void Attach(IMethodMock methodMock)
        {
            var callPattern = methodMock.CallPattern;

            if (!(callPattern.Method is ConstructorInfo) ||
                callPattern.Method.IsStatic ||
                !(callPattern.InstanceMatcher is AnyMatcher) ||
                typeof(string) == callPattern.Method.DeclaringType
#if !COREFX
                || typeof(ContextBoundObject).IsAssignableFrom(callPattern.Method.DeclaringType)
#endif
                )
            {
                return;
            }

            methodMock.Behaviors.Add(new ConstructorMockBehavior());
        }
コード例 #8
0
		public PreserveRefOutValuesBehavior(IMethodMock methodMock)
		{
			var argMatchers = methodMock.CallPattern.ArgumentMatchers;
			var method = methodMock.CallPattern.Method;
			var parameters = GetParameters(method);
			var offsetDueToExtensionMethod = method.IsExtensionMethod() ? 1 : 0;

			for (int i = 0; i < parameters.Length; ++i)
			{
				if (!parameters[i].ParameterType.IsByRef || argMatchers[i].ProtectRefOut)
					continue;

				var matcher = argMatchers[i] as IValueMatcher;
				if (matcher == null)
					continue;

				var value = matcher.Value;
				values.Add(i + offsetDueToExtensionMethod, value);
			}
		}
コード例 #9
0
		public PreserveRefOutValuesBehavior(IMethodMock methodMock)
		{
			var argMatchers = methodMock.CallPattern.ArgumentMatchers;
			var method = methodMock.CallPattern.Method;
			var parameters = GetParameters(method);
			var offsetDueToExtensionMethod = method.IsExtensionMethod() ? 1 : 0;

			for (int i = 0; i < parameters.Length; ++i)
			{
				if (!parameters[i].ParameterType.IsByRef || argMatchers[i].ProtectRefOut)
					continue;

				var matcher = argMatchers[i] as IValueMatcher;
				if (matcher == null)
					continue;

				var value = matcher.Value;
				values.Add(i + offsetDueToExtensionMethod, value);
			}
		}
コード例 #10
0
		public void AddOrUpdateOccurence(CallPattern callPattern, IMethodMock mock)
		{
			AddOrUpdateOccurenceInternal(callPattern, 0, mock);
		}
コード例 #11
0
		public void AddChild(CallPattern callPattern, IMethodMock methodMock,int id)
		{
			var node = new MethodMockMatcherTreeNode(methodMock, id);
			callPattern.MethodMockNode = node;
			AddChildInternal(callPattern, 0, node);
		}
コード例 #12
0
ファイル: MockBuilder.cs プロジェクト: ShaneGH/Dynamox
        void MockMethod(string name, IMethodMock method)
        {
            MethodGroup existingMock = null;
            if (Values.ContainsKey(name))
            {
                existingMock = Values[name] as MethodGroup;
                if (existingMock == null)
                    throw new InvalidMockException("The member \"" + name + "\" has already been set as a parameter and cannot be mocked now as a method");    //TODM
            }

            if (existingMock == null)
            {
                existingMock = new MethodGroup(method);
                SetMember(name, existingMock);
            }
            else
            {
                //TODM: if a method is mocked twice, the second mock will take precedence
                existingMock.Insert(0, method);
            }
        }
コード例 #13
0
 public void AddOrUpdateOccurence(CallPattern callPattern, IMethodMock mock)
 {
     AddOrUpdateOccurenceInternal(callPattern, 0, mock);
 }
コード例 #14
0
		protected void AddOrUpdateOccurenceInternal(CallPattern callPattern, int depth, IMethodMock mock)
		{
			if (depth == callPattern.ArgumentMatchers.Count+1)
			{
				var resultNode = this.Children.FirstOrDefault() as OccurrencesMatcherTreeNode;
				if(mock != null)
					resultNode.Mocks.Add(mock);
				resultNode.Calls++;
				return;
			}

			var matcher = depth == 0 ? callPattern.InstanceMatcher : callPattern.ArgumentMatchers[depth - 1];
			var child = this.GetMatchingChild(matcher, MatchingOptions.Exact, depth);

			if (child != null)
			{
				child.AddOrUpdateOccurenceInternal(callPattern, depth + 1, mock);
			}
			else
			{
				this.AddChildInternal(callPattern, depth, new OccurrencesMatcherTreeNode(mock));
			}
		}
コード例 #15
0
 public MethodMockMatcherTreeNode(IMethodMock methodMock = null, int id = 0)
     : base(null)
 {
     MethodMock = methodMock;
     Id         = id;
 }
コード例 #16
0
 public ActivatorCreateInstanceTBehavior(IMethodMock delegatedMock)
 {
     this.delegatedMock = delegatedMock;
 }
コード例 #17
0
 public InvocationOccurrenceBehavior(IMethodMock methodMock)
 {
     this.methodMock = methodMock;
 }
コード例 #18
0
        public static void Attach(IMethodMock newExprMethodMock, IMethodMock createInstanceMethodMock)
        {
            var activatorBehavior = new ActivatorCreateInstanceTBehavior(newExprMethodMock);

            createInstanceMethodMock.Behaviors.Add(activatorBehavior);
        }
コード例 #19
0
		public static void Attach(IMethodMock newExprMethodMock, IMethodMock createInstanceMethodMock)
		{
			var activatorBehavior = new ActivatorCreateInstanceTBehavior(newExprMethodMock);
			createInstanceMethodMock.Behaviors.Add(activatorBehavior);
		}
コード例 #20
0
		public InvocationOccurrenceBehavior(IMethodMock methodMock)
		{
			this.methodMock = methodMock;
		}
コード例 #21
0
		public MethodMockMatcherTreeNode(IMethodMock methodMock = null, int id = 0)
			:base(null)
		{
			MethodMock = methodMock;
			Id = id;
		}
コード例 #22
0
        protected void AddOrUpdateOccurenceInternal(CallPattern callPattern, int depth, IMethodMock mock)
        {
            if (depth == callPattern.ArgumentMatchers.Count + 1)
            {
                var resultNode = this.Children.FirstOrDefault() as OccurrencesMatcherTreeNode;
                if (mock != null)
                {
                    resultNode.Mocks.Add(mock);
                }
                resultNode.Calls++;
                return;
            }

            var matcher = depth == 0 ? callPattern.InstanceMatcher : callPattern.ArgumentMatchers[depth - 1];
            var child   = this.GetMatchingChild(matcher, MatchingOptions.Exact, depth);

            if (child != null)
            {
                child.AddOrUpdateOccurenceInternal(callPattern, depth + 1, mock);
            }
            else
            {
                this.AddChildInternal(callPattern, depth, new OccurrencesMatcherTreeNode(mock));
            }
        }
コード例 #23
0
		public OccurrencesMatcherTreeNode(IMethodMock mock)
			: this()
		{
			if (mock != null)
				Mocks.Add(mock);
		}
コード例 #24
0
		public ActivatorCreateInstanceTBehavior(IMethodMock delegatedMock)
		{
			this.delegatedMock = delegatedMock;
		}