コード例 #1
0
ファイル: Behavior.cs プロジェクト: BiBongNet/JustMockLite
		private static void DissectBehavior(Behavior behavior, List<object> mixins, List<IBehavior> supplementaryBehaviors, List<IBehavior> fallbackBehaviors, object[] constructorArgs, ref bool? mockConstructorCall)
		{
			mixins.Add(new MockingBehaviorConfiguration { Behavior = behavior });
			
			var eventStubs = new EventStubsBehavior();
			mixins.Add(eventStubs.CreateMixin());

			switch (behavior)
			{
				case Behavior.RecursiveLoose:
				case Behavior.Loose:
					fallbackBehaviors.Add(eventStubs);
					fallbackBehaviors.Add(new PropertyStubsBehavior());
					fallbackBehaviors.Add(new CallOriginalObjectMethodsBehavior());
					fallbackBehaviors.Add(new RecursiveMockingBehavior(behavior == Behavior.RecursiveLoose ? RecursiveMockingBehaviorType.ReturnMock : RecursiveMockingBehaviorType.ReturnDefault));
					fallbackBehaviors.Add(new StaticConstructorMockBehavior());
					fallbackBehaviors.Add(new ExecuteConstructorBehavior());
					break;
				case Behavior.Strict:
					fallbackBehaviors.Add(eventStubs);
					fallbackBehaviors.Add(new RecursiveMockingBehavior(RecursiveMockingBehaviorType.OnlyDuringAnalysis));
					fallbackBehaviors.Add(new StaticConstructorMockBehavior());
					fallbackBehaviors.Add(new ExecuteConstructorBehavior());
					fallbackBehaviors.Add(new StrictBehavior(false));
					supplementaryBehaviors.Add(new StrictBehavior(true));
					break;
				case Behavior.CallOriginal:
					fallbackBehaviors.Add(new CallOriginalBehavior());
					fallbackBehaviors.Add(eventStubs);
					fallbackBehaviors.Add(new RecursiveMockingBehavior(RecursiveMockingBehaviorType.OnlyDuringAnalysis));
					fallbackBehaviors.Add(new StaticConstructorMockBehavior());
					fallbackBehaviors.Add(new ExecuteConstructorBehavior());
					break;
			}

			if (!mockConstructorCall.HasValue)
			{
#if !SILVERLIGHT
				switch (behavior)
				{
					case Behavior.RecursiveLoose:
					case Behavior.Loose:
					case Behavior.Strict:
						mockConstructorCall = constructorArgs == null;
						break;
					case Behavior.CallOriginal:
						mockConstructorCall = false;
						break;
				}
#else
				mockConstructorCall = false;
#endif
			}
		}
コード例 #2
0
ファイル: Behavior.cs プロジェクト: ArthurYiL/JustMockLite
		private static MockCreationSettings DissectBehavior(Behavior behavior, List<object> mixins, List<IBehavior> supplementaryBehaviors, List<IBehavior> fallbackBehaviors, object[] constructorArgs, bool? mockConstructorCall)
		{
			mixins.Add(new MockingBehaviorConfiguration { Behavior = behavior });

			var eventStubs = new EventStubsBehavior();
			mixins.Add(eventStubs.CreateMixin());

			switch (behavior)
			{
				case Behavior.RecursiveLoose:
				case Behavior.Loose:
					fallbackBehaviors.Add(eventStubs);
					fallbackBehaviors.Add(new PropertyStubsBehavior());
					fallbackBehaviors.Add(new CallOriginalObjectMethodsBehavior());
					fallbackBehaviors.Add(new RecursiveMockingBehavior(behavior == Behavior.RecursiveLoose
						? RecursiveMockingBehaviorType.ReturnMock : RecursiveMockingBehaviorType.ReturnDefault));
					fallbackBehaviors.Add(new StaticConstructorMockBehavior());
					fallbackBehaviors.Add(new ExecuteConstructorBehavior());
					break;
				case Behavior.Strict:
					fallbackBehaviors.Add(eventStubs);
					fallbackBehaviors.Add(new RecursiveMockingBehavior(RecursiveMockingBehaviorType.OnlyDuringAnalysis));
					fallbackBehaviors.Add(new StaticConstructorMockBehavior());
					fallbackBehaviors.Add(new ExecuteConstructorBehavior());
					fallbackBehaviors.Add(new StrictBehavior(throwOnlyOnValueReturningMethods: false));
					supplementaryBehaviors.Add(new StrictBehavior(throwOnlyOnValueReturningMethods: true));
					break;
				case Behavior.CallOriginal:
					fallbackBehaviors.Add(new CallOriginalBehavior());
					fallbackBehaviors.Add(eventStubs);
					fallbackBehaviors.Add(new RecursiveMockingBehavior(RecursiveMockingBehaviorType.OnlyDuringAnalysis));
					fallbackBehaviors.Add(new StaticConstructorMockBehavior());
					fallbackBehaviors.Add(new ExecuteConstructorBehavior());
					break;
			}

			if (!mockConstructorCall.HasValue)
			{
				switch (behavior)
				{
					case Behavior.RecursiveLoose:
					case Behavior.Loose:
					case Behavior.Strict:
						mockConstructorCall = constructorArgs == null;
						break;
					case Behavior.CallOriginal:
						mockConstructorCall = false;
						break;
				}
			}

			return new MockCreationSettings
			{
				Args = constructorArgs,
				Mixins = mixins,
				SupplementaryBehaviors = supplementaryBehaviors,
				FallbackBehaviors = fallbackBehaviors,
				MockConstructorCall = mockConstructorCall.Value,
			};
		}