• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MockFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MockFactory的典型用法代码示例。如果您正苦于以下问题:C# MockFactory类的具体用法?C# MockFactory怎么用?C# MockFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MockFactory类属于命名空间,在下文中一共展示了MockFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ShouldCreateAndEvaluateTest

		public void ShouldCreateAndEvaluateTest()
		{
			TransientFactoryMethodDependencyResolution transientFactoryMethodDependencyResolution;
			IDependencyManager mockDependencyManager;
			Func<object> value;
			object result;
			MockFactory mockFactory;

			mockFactory = new MockFactory();
			mockDependencyManager = mockFactory.CreateInstance<IDependencyManager>();

			value = () => 11;

			transientFactoryMethodDependencyResolution = new TransientFactoryMethodDependencyResolution(value);

			Assert.AreEqual(DependencyLifetime.Transient, transientFactoryMethodDependencyResolution.DependencyLifetime);

			result = transientFactoryMethodDependencyResolution.Resolve(mockDependencyManager, typeof(object), string.Empty);

			Assert.IsNotNull(result);
			Assert.AreEqual(11, result);

			transientFactoryMethodDependencyResolution.Dispose();

			mockFactory.VerifyAllExpectationsHaveBeenMet();
		}
开发者ID:textmetal,项目名称:main,代码行数:26,代码来源:TransientFactoryMethodDependencyResolutionTests.cs


示例2: ShouldCreateAndEvaluateTest

		public void ShouldCreateAndEvaluateTest()
		{
			InstanceDependencyResolution instanceDependencyResolution;
			IDependencyManager mockDependencyManager;
			int value;
			object result;
			MockFactory mockFactory;

			mockFactory = new MockFactory();
			mockDependencyManager = mockFactory.CreateInstance<IDependencyManager>();

			value = 11;

			instanceDependencyResolution = new InstanceDependencyResolution(value);

			Assert.AreEqual(DependencyLifetime.Instance, instanceDependencyResolution.DependencyLifetime);

			result = instanceDependencyResolution.Resolve(mockDependencyManager, typeof(object), string.Empty);

			Assert.IsNotNull(result);
			Assert.AreEqual(11, result);

			instanceDependencyResolution.Dispose();

			mockFactory.VerifyAllExpectationsHaveBeenMet();
		}
开发者ID:textmetal,项目名称:main,代码行数:26,代码来源:InstanceDependencyResolutionTests.cs


示例3: ShouldCreateAndEvaluateTest

		public void ShouldCreateAndEvaluateTest()
		{
			TransientActivatorAutoWiringDependencyResolution<MockDependantObject> transientActivatorAutoWiringDependencyResolution;
			IDependencyManager mockDependencyManager;
			MockDependantObject result;
			MockFactory mockFactory;
			string _unusedString = null;
			bool _unusedBoolean = false;
			Type _unusedType = null;

			mockFactory = new MockFactory();
			mockDependencyManager = mockFactory.CreateInstance<IDependencyManager>();

			Expect.On(mockDependencyManager).One.Method(m => m.ResolveDependency(_unusedType, _unusedString, _unusedBoolean)).With(typeof(MockDependantObject), "named_dep_obj", true).Will(Return.Value(new MockDependantObject("left")));
			Expect.On(mockDependencyManager).One.Method(m => m.ResolveDependency(_unusedType, _unusedString, _unusedBoolean)).With(typeof(MockDependantObject), string.Empty, true).Will(Return.Value(new MockDependantObject("right")));

			transientActivatorAutoWiringDependencyResolution = new TransientActivatorAutoWiringDependencyResolution<MockDependantObject>();

			Assert.AreEqual(DependencyLifetime.Transient, transientActivatorAutoWiringDependencyResolution.DependencyLifetime);

			result = transientActivatorAutoWiringDependencyResolution.Resolve(mockDependencyManager, string.Empty);

			Assert.IsNotNull(result);
			Assert.IsInstanceOf<MockDependantObject>(result);
			Assert.IsNotNull(result.Text);
			Assert.AreEqual(string.Empty, result.Text);
			Assert.IsNotNull(result.Left);
			Assert.IsNotNull(result.Right);
			Assert.AreEqual("left", result.Left.Text);
			Assert.AreEqual("right", result.Right.Text);

			transientActivatorAutoWiringDependencyResolution.Dispose();

			mockFactory.VerifyAllExpectationsHaveBeenMet();
		}
开发者ID:textmetal,项目名称:main,代码行数:35,代码来源:TransientActivatorAutoWiringDependencyResolutionArity1Tests.cs


示例4: SetUp

        public void SetUp()
        {
            _factory = new MockFactory();

            List<CommonEvent> mockResult;

            var mock1 = _factory.CreateMock<BaseEventCollector>();
            mockResult = new List<CommonEvent>();
            mockResult.AddRange(new[]
                      {
                          new CommonEvent(0, "100", "Mock1Event1", new DateTime(2013,10,15), null, "", "", "", "", "", ""),
                          new CommonEvent(0, "100", "Mock1Event2", new DateTime(2013,10,1), null, "", "", "", "", "", ""),
                      });
            mock1.Expects.One.MethodWith(x => x.GetEvents(201307, "松山")).WillReturn(mockResult);

            var mock2 = _factory.CreateMock<BaseEventCollector>();
            mockResult = new List<CommonEvent>();
            mockResult.AddRange(new[]
                      {
                          new CommonEvent(0, "100", "Mock2Event1", new DateTime(2013,10,8), null, "", "", "", "", "", ""),
                          new CommonEvent(0, "100", "Mock2Event2", new DateTime(2013,10,30), null, "", "", "", "", "", ""),
                          new CommonEvent(0, "100", "Mock2Event3", new DateTime(2013,10,25), null, "", "", "", "", "", ""),
                      });
            mock2.Expects.One.MethodWith(x => x.GetEvents(201307, "松山")).WillReturn(mockResult);

            sut = new AllEventCollector(new[] { mock1.MockObject, mock2.MockObject });
        }
开发者ID:nakaji,项目名称:EventSearch,代码行数:27,代码来源:AllEventCollectorTest.cs


示例5: DoNotIssueMoveIntoWater

        public void DoNotIssueMoveIntoWater()
        {
            var mock = new MockFactory();
            var outputAdapterMock = mock.CreateMock<IGameOutputAdapter>();

            using (mock.Ordered)
            {
                outputAdapterMock.Expects.One.MethodWith(adapter => adapter.NotifyEndOfTurn());
            }

            var trackerManager = new OwnAntTrackingManager(outputAdapterMock.MockObject);

            MapTile origin = GameContext.Map.At(3, 4);
            MapTile destination = origin.North;
            var ant = new Ant(origin);

            destination.State = TileState.Water;
            origin.CurrentAnt = ant;

            trackerManager.HasProcessedAllInputMoves();
            trackerManager.EnrollToMove(ant, destination);
            trackerManager.FinalizeAllMoves();

            Assert.IsNotNull(origin.CurrentAnt);
            Assert.AreEqual(ant, origin.CurrentAnt);

            mock.VerifyAllExpectationsHaveBeenMet();
        }
开发者ID:justin-lovell,项目名称:AiChallenge,代码行数:28,代码来源:OwnAntTrackingManagerFixture.cs


示例6: CreateMock

		public override object CreateMock(MockFactory mockFactory, CompositeType typesToMock, string name, MockStyle mockStyle, object[] constructorArgs)
		{
			if (typesToMock == null)
				throw new ArgumentNullException("typesToMock");

			Type primaryType = typesToMock.PrimaryType;
			Type[] additionalInterfaces = BuildAdditionalTypeArrayForProxyType(typesToMock);
			IInterceptor mockInterceptor = new MockObjectInterceptor(mockFactory, typesToMock, name, mockStyle);
			object result;

			/* ^ */ var _typeInfo = primaryType.GetTypeInfo(); /* [email protected] ^ */

			if (/* ^ */ _typeInfo.IsInterface /* [email protected] ^ */)
			{
				result = generator.CreateInterfaceProxyWithoutTarget(primaryType, additionalInterfaces, new ProxyGenerationOptions {BaseTypeForInterfaceProxy = typeof (InterfaceMockBase)}, mockInterceptor);
				((InterfaceMockBase) result).Name = name;
			}
			else
			{
				result = generator.CreateClassProxy(primaryType, additionalInterfaces, ProxyGenerationOptions.Default, constructorArgs, mockInterceptor);
				//return generator.CreateClassProxy(primaryType, new []{typeof(IMockObject)}, mockInterceptor);
			}

			return result;
		}
开发者ID:textmetal,项目名称:main,代码行数:25,代码来源:DynamicProxyMockObjectFactory.cs


示例7: shouldAddIngredientToCurrentUser

        public void shouldAddIngredientToCurrentUser()
        {
            var mockFactory = new MockFactory(MockBehavior.Loose);
            var userContextMock = GetSetuppedUserContextMock(mockFactory);

            var userIngredientBusinessLogicMock = mockFactory.Create<IUserIngredientBusinessLogic>();
            var userIngredient = new UserIngredient {
                User = new User {Username = "myUser"},
                Ingredient = new Ingredient {Name = "Pannbiff"},
                Measure = 100
            };

            userIngredientBusinessLogicMock.Setup(x => x.GetUserIngredients(It.IsAny<User>(), It.IsAny<DateTime>())).Returns(new[] {userIngredient});
            userIngredientBusinessLogicMock.Setup(x => x.AddUserIngredient(It.Is<User>(u => u.Username == "myUser"), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<DateTime>())).Returns(userIngredient);

            var inputFoodModel = new InputFoodModel {Ingredient = "Pannbiff", Measure = 100, Date = DateTime.Now};
            var model = testController(x => x.Input(inputFoodModel), userIngredientBusinessLogicMock, userContextMock);

            Assert.That(model, Is.Not.Null);
            Assert.That(model.UserIngredients, Is.Not.Null);
            Assert.That(model.UserIngredients.Any(x => x.Ingredient.Name == "Pannbiff"));
            Assert.That(model.UserIngredients.Any(x => x.Measure == 100));

            userIngredientBusinessLogicMock.VerifyAll();
        }
开发者ID:yodiz,项目名称:CarbonFitness,代码行数:25,代码来源:InputTest.cs


示例8: UnexpectedInvocationException

		/// <summary>
		/// Constructs a <see cref="UnexpectedInvocationException"/> with the given parameters.
		/// </summary>
		/// <param name="factory">The MockFactory that threw this exception</param>
		/// <param name="invocation">The unexpected invocation</param>
		/// <param name="expectations">The expectations collection to describe</param>
		/// <param name="message">A message to help the user understand what was unexpected</param>
		internal UnexpectedInvocationException(MockFactory factory, Invocation invocation, IExpectationList expectations, string message)
		{
			if (factory == null)
				throw new ArgumentNullException("factory");
			if (invocation == null)
				throw new ArgumentNullException("invocation");
			if (expectations == null) 
				throw new ArgumentNullException("expectations");

			Factory = factory;

			var writer = new DescriptionWriter();
			writer.WriteLine();
			if (invocation.IsPropertySetAccessor)
				writer.WriteLine(UNEXPECTED_PROPERTY_SETTER_PREFIX);
			else if (invocation.IsPropertyGetAccessor)
				writer.WriteLine(UNEXPECTED_PROPERTY_GETTER_PREFIX);
			else
				writer.WriteLine(MESSAGE_PREFIX);
			writer.Write("  ");
			((ISelfDescribing)invocation).DescribeTo(writer);
			writer.Write(message);
			//expectations.DescribeActiveExpectationsTo(writer);
			//expectations.DescribeUnmetExpectationsTo(writer);
			expectations.DescribeTo(writer);

			_message = writer.ToString();
		}
开发者ID:textmetal,项目名称:main,代码行数:35,代码来源:Exceptions.cs


示例9: TestInitialize

        public void TestInitialize()
        {
            if (MockFactory != null)
            return;

              MockFactory = new MockFactory();
        }
开发者ID:AlexeyVoronin,项目名称:PreRetroVoting,代码行数:7,代码来源:TestWithMocks.cs


示例10: TestPersist

        public void TestPersist()
        {
            MockFactory factory = new MockFactory();

            //Create mocks
            Mock<IUserGateway> mockGateway = factory.CreateMock<IUserGateway>();
            Mock<IUserValidator> mockValidator = factory.CreateMock<IUserValidator>();

            //Create user
            User user = new User();

            //Expectations
            using(factory.Ordered)
            {
                mockValidator.Expects.One.MethodWith(m => m.Validate(user)).WillReturn(true);
                mockGateway.Expects.One.MethodWith(m => m.Persist(user)).WillReturn(true);
            }

            //Assign gateway
            user.Gateway = mockGateway.MockObject;

            //Test method
            Assert.AreEqual(true, user.Persist(mockValidator.MockObject));

            factory.VerifyAllExpectationsHaveBeenMet();
        }
开发者ID:pweibel,项目名称:DotNetMockingFrameworksDemo,代码行数:26,代码来源:NMock3Test.cs


示例11: MockObject

		/// <summary>
		/// Initializes a new instance of the <see cref="MockObject"/> class.
		/// </summary>
		/// <param name="mockFactory">The mockFactory.</param>
		/// <param name="mockedType">Type of the mocked.</param>
		/// <param name="name">The name.</param>
		/// <param name="mockStyle">The mock style.</param>
		protected MockObject(MockFactory mockFactory, CompositeType mockedType, string name, MockStyle mockStyle)
		{
			MockFactory = mockFactory;
			MockStyle = mockStyle;
			MockName = name;
			eventHandlers = new Dictionary<string, List<Delegate>>();
			MockedTypes = mockedType;
		}
开发者ID:textmetal,项目名称:main,代码行数:15,代码来源:MockObject.cs


示例12: shouldThrowIngredientInsertionExceptionWhenInsertingFails

        public void shouldThrowIngredientInsertionExceptionWhenInsertingFails()
        {
            var factory = new MockFactory(MockBehavior.Strict);
            var ingredientRepositoryMock = factory.Create<IIngredientRepository>();
            ingredientRepositoryMock.Setup(x => x.SaveOrUpdate(It.IsAny<Ingredient>())).Throws(new Exception());

            Assert.Throws<IngredientInsertionException>(() => new IngredientImporter(null, null, ingredientRepositoryMock.Object).SaveIngredient(new Ingredient()));
        }
开发者ID:yodiz,项目名称:CarbonFitness,代码行数:8,代码来源:IngredientImporterTest.cs


示例13: Setup

        public void Setup()
        {
            _factory = new MockFactory(MockBehavior.Strict);
            _parserMock = _factory.Create<IConfigurationParser>();
            _proxyMock = _factory.Create<IConfigurationProxyProvider>();

            _sage = new Sage(_parserMock.Object, _proxyMock.Object);
        }
开发者ID:MACSkeptic,项目名称:ExpLorer,代码行数:8,代码来源:SageTest.cs


示例14: ShouldBeAbleToCreateAProxyForAnEnum

        public void ShouldBeAbleToCreateAProxyForAnEnum()
        {
            var factory = new MockFactory(MockBehavior.Strict);

            var @enum = factory.Create<Fixtures.Language>(MockBehavior.Strict, null, null);
            @enum.Setup(e => e.IetfTag).Returns("CZ");

            Assert.AreEqual("CZ", @enum.Object.IetfTag);
        }
开发者ID:dnfeitosa,项目名称:Dnfeitosa.Enums,代码行数:9,代码来源:MockableTest.cs


示例15: SetUp

        public void SetUp()
        {
            factory = new MockFactory();
            camera = factory.CreateMock<Camera>();
            sensor = factory.CreateMock<AbstractTouchSensor>();

            sprite1 = factory.CreateMock<Sprite>();
            sprite2 = factory.CreateMock<Sprite>();
            sprites = new[] { sprite1.MockObject, sprite2.MockObject };
        }
开发者ID:absurdhero,项目名称:tmotmo-full,代码行数:10,代码来源:TestSpriteCollection.cs


示例16: shouldGetUserFromUsername

        public void shouldGetUserFromUsername()
        {
            var mockFactory = new MockFactory(MockBehavior.Strict);
            var userRepositoryMock = mockFactory.Create<IUserRepository>();
            userRepositoryMock.Setup(x => x.Get(It.IsAny<string>())).Returns(new User());

            var userBusinessLogic = new UserBusinessLogic(userRepositoryMock.Object, null);
            userBusinessLogic.Get("myUser");
            userRepositoryMock.VerifyAll();
        }
开发者ID:yodiz,项目名称:CarbonFitness,代码行数:10,代码来源:UserBusinessLogicTest.cs


示例17: IsLoginOK_WhenCalled_WritesToLog

        public void IsLoginOK_WhenCalled_WritesToLog()
        {
            var factory = new MockFactory();
            Mock<ILogger> logger = factory.CreateMock<ILogger>();
            logger.Expects.One.Method(_ => _.Write(null)).WithAnyArguments();

            var lm = new LoginManagerWithMock(logger.MockObject);
            lm.IsLoginOK("a", "b");

            logger.VerifyAllExpectations();
        }
开发者ID:royosherove,项目名称:dotnetmocks2demo,代码行数:11,代码来源:7_LoginManagerTestsNMock3.cs


示例18: GetFieldByNameNoHeaderExceptionTest

        public void GetFieldByNameNoHeaderExceptionTest()
        {
            var data = new [] { "1", "2" };
            var mockFactory = new MockFactory( MockBehavior.Default );
            var parserMock = mockFactory.Create<ICsvParser>();
            parserMock.Setup( m => m.Read() ).Returns( () => data );

            var reader = new CsvReader( parserMock.Object, new CsvReaderOptions{ HasHeaderRecord = false } );
            reader.Read();

            Assert.AreEqual( Convert.ToInt32( data[0] ), reader.GetField<int>( "One" ) );
        }
开发者ID:heinrichbreedt,项目名称:CsvHelper,代码行数:12,代码来源:CsvReaderTests.cs


示例19: ShouldExecuteReaderCloseConnectionSprocWithParametersTest

		public void ShouldExecuteReaderCloseConnectionSprocWithParametersTest()
		{
			IAdoNetYieldingFascade adoNetYieldingFascade;
			MockFactory mockFactory;
			DbConnection mockDbConnection;
			DbCommand mockDbCommand;
			DbParameterCollection mockDbParameterCollection;
			DbParameter[] mockDbParameters;
			DbParameter mockDbParameter0;
			DbParameter mockDbParameter1;
			DbDataReader mockDbDataReader;
			IReflectionFascade mockReflectionFascade;

			DbDataReader dbDataReader;

			CommandBehavior _unusedCommandBehavior = CommandBehavior.Default;
			DbParameter _unusedDbParameter = null;

			mockFactory = new MockFactory();
			mockDbConnection = mockFactory.CreateInstance<DbConnection>();
			mockDbCommand = mockFactory.CreateInstance<DbCommand>();
			mockDbParameterCollection = mockFactory.CreateInstance<DbParameterCollection>();
			mockDbParameter0 = mockFactory.CreateInstance<DbParameter>();
			mockDbParameter1 = mockFactory.CreateInstance<DbParameter>();
			mockDbParameters = new DbParameter[] { mockDbParameter0, mockDbParameter1 };
			mockDbDataReader = mockFactory.CreateInstance<DbDataReader>();
			mockReflectionFascade = mockFactory.CreateInstance<IReflectionFascade>();

			Expect.On(mockDbConnection).One.Method(x => x.CreateCommand()).Will(Return.Value(mockDbCommand));
			Expect.On(mockDbCommand).Exactly(2).GetProperty(x => x.Parameters).Will(Return.Value(mockDbParameterCollection));
			Expect.On(mockDbCommand).One.Method(x => x.Dispose());
			Expect.On(mockDbCommand).One.SetProperty(x => x.CommandType).To(CommandType.StoredProcedure);
			Expect.On(mockDbCommand).One.SetProperty(x => x.CommandText).To("blah blah blah");
			Expect.On(mockDbCommand).One.SetProperty(x => x.Transaction).To(null);
			Expect.On(mockDbCommand).One.Method(x => x.ExecuteReader(_unusedCommandBehavior)).With(CommandBehavior.CloseConnection).Will(Return.Value(mockDbDataReader));
			Expect.On(mockDbParameter0).One.GetProperty(x => x.Value).Will(Return.Value(1));
			Expect.On(mockDbParameter1).One.GetProperty(x => x.Value).Will(Return.Value(null));
			Expect.On(mockDbParameter1).One.SetProperty(x => x.Value).To(DBNull.Value);
			Expect.On(mockDbParameterCollection).One.Method(x => x.Add(_unusedDbParameter)).With(mockDbParameter0).Will(Return.Value(0));
			Expect.On(mockDbParameterCollection).One.Method(x => x.Add(_unusedDbParameter)).With(mockDbParameter1).Will(Return.Value(0));
			Expect.On(mockDbDataReader).One.Method(x => x.Dispose());

			adoNetYieldingFascade = new AdoNetYieldingFascade(mockReflectionFascade);

			dbDataReader = adoNetYieldingFascade.ExecuteReader(mockDbConnection, null, CommandType.StoredProcedure, "blah blah blah", mockDbParameters, CommandBehavior.CloseConnection, null, false);

			Assert.IsNotNull(dbDataReader);

			dbDataReader.Dispose();

			mockFactory.VerifyAllExpectationsHaveBeenMet();
		}
开发者ID:textmetal,项目名称:main,代码行数:52,代码来源:AdoNetYieldingFascadeTests.cs


示例20: ShouldFailOnDataTypeFascadeCreateTest

		public void ShouldFailOnDataTypeFascadeCreateTest()
		{
			AppConfigFascade appConfigFascade;
			IConfigurationRoot mockConfigurationRoot;
			IDataTypeFascade mockDataTypeFascade;
			MockFactory mockFactory;

			mockFactory = new MockFactory();
			mockConfigurationRoot = mockFactory.CreateInstance<IConfigurationRoot>();
			mockDataTypeFascade = null;

			appConfigFascade = new AppConfigFascade(mockConfigurationRoot, mockDataTypeFascade);
		}
开发者ID:textmetal,项目名称:main,代码行数:13,代码来源:AppConfigFascadeTests.cs



注:本文中的MockFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MockFile类代码示例发布时间:2022-05-24
下一篇:
C# MockErrorReporter类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap