当前位置: 首页>>代码示例>>C#>>正文


C# MockContext类代码示例

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


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

示例1: Assert_WithValidMatchPredicate_IsVerified

 public void Assert_WithValidMatchPredicate_IsVerified()
 {
     var mockContext = new MockContext<IFoo>();
     var fooMock = new FooMock(mockContext);
     fooMock.Execute("SomeValue");
     mockContext.Assert(f => f.Execute(The<string>.Is(s => s.StartsWith("Some"))), Invoked.Once);
 }
开发者ID:gazzyt,项目名称:LightMock,代码行数:7,代码来源:MockContextTests.cs

示例2: _BeforeTest

        public void _BeforeTest()
        {
            MockContext = new MockContext();

            Settings =
            SettingKeys.DefaultValues.ToDictionary( kvp => kvp.Key, kvp => new Config { Id = kvp.Key, Value = kvp.Value } );

            MockContext.SettingsRepoMock.Setup( x => x.Set( It.IsAny<string>(), It.IsAny<string>() ) ).Callback<string, string>( ( key, value ) =>
            {
                Settings[key] = new Config { Id = key, Value = value };
            } );
            MockContext.SettingsRepoMock.Setup( x => x.GetById( It.IsAny<string>() ) ).Returns<string>( cfg => Settings[cfg] );

            MockContext.AppThemesMock.SetupGet( x => x.Accents ).Returns( new[]
            {
                new ColorItem {Name = "Red"},
                new ColorItem {Name = "Blue"},
                new ColorItem {Name = "Green"}
            } );
            MockContext.AppThemesMock.SetupGet( x => x.Themes ).Returns( new[]
            {
                new ColorItem {Name = "BaseDark"},
                new ColorItem {Name = "None"},
                new ColorItem {Name = "BaseLight"}
            } );
        }
开发者ID:TheSylence,项目名称:GSD,代码行数:26,代码来源:SettingsViewModelTests.cs

示例3: Assert_NeverWhenInvoked_ThrowsException

 public void Assert_NeverWhenInvoked_ThrowsException()
 {
     var mockContext = new MockContext<IFoo>();
     var fooMock = new FooMock(mockContext);
     fooMock.Execute("SomeValue");
     mockContext.Assert(f => f.Execute("SomeValue"), Invoked.Never);
 }
开发者ID:gazzyt,项目名称:LightMock,代码行数:7,代码来源:MockContextTests.cs

示例4: CurrentProjectIsFirstIfNotSetInSettings

        public void CurrentProjectIsFirstIfNotSetInSettings()
        {
            // Arrange
            var context = new MockContext();
            context.SettingsRepoMock.Setup( s => s.GetById( SettingKeys.LastProject ) ).Returns( new Config { Value = "-1" } );

            var projects = new[]
            {
                new Project {Name = "One", Id = 1},
                new Project {Name = "Two", Id = 2},
                new Project {Name = "Three", Id = 3}
            };

            context.ProjectRepoMock.Setup( p => p.GetAll() ).Returns( projects );

            // Act
            var vm = new ProjectListViewModel( context.ViewServiceRepo, context.SettingsRepo, context.ProjectRepo );

            // Assert
            Assert.IsNotNull( vm.CurrentProject );
            Assert.AreSame( projects[0], vm.CurrentProject.Model );

            context.SettingsRepoMock.VerifyAll();
            context.ProjectRepoMock.VerifyAll();
        }
开发者ID:TheSylence,项目名称:GSD,代码行数:25,代码来源:ProjectListViewModelTests.cs

示例5: InitializeContext

 protected void InitializeContext()
 {
     var contextMappings = new EntityMappingStore();
     var rmp = new ReflectionMappingProvider();
     rmp.AddMappingsForAssembly(contextMappings, typeof(LinqToSparqlTests).Assembly);
     Context = new MockContext(contextMappings);
 }
开发者ID:rharrisxtheta,项目名称:BrightstarDB,代码行数:7,代码来源:LinqToSparqlTestBase.cs

示例6: ResolverReturnsProperNamedObject

        public void ResolverReturnsProperNamedObject()
        {
            string expected = "We want this one";
            string notExpected = "Not this one";

            var expectedKey = NamedTypeBuildKey.Make<string>("expected");
            var notExpectedKey = NamedTypeBuildKey.Make<string>();

            var mainContext = new MockContext();
            mainContext.NewBuildupCallback = (k) =>
            {
                if (k == expectedKey)
                {
                    return expected;
                }
                if (k == notExpectedKey)
                {
                    return notExpected;
                }
                return null;
            };

            var resolver = new OptionalDependencyResolverPolicy(typeof(string), "expected");

            object result = resolver.Resolve(mainContext);

            Assert.Same(expected, result);
        }
开发者ID:CFMITL,项目名称:unity,代码行数:28,代码来源:OptionalDependencyResolverPolicyFixture.cs

示例7: Assert_Once_IsVerified

 public void Assert_Once_IsVerified()
 {
     var mockContext = new MockContext<IFoo>();
     var fooMock = new FooMock(mockContext);
     fooMock.Execute("SomeValue");
     mockContext.Assert(f => f.Execute("SomeValue"));
 }
开发者ID:gazzyt,项目名称:LightMock,代码行数:7,代码来源:MockContextTests.cs

示例8: ListChangedEventIsAlwaysOnTheThreadThatCreatedTheList

        public void ListChangedEventIsAlwaysOnTheThreadThatCreatedTheList()
        {
            try
            {
                //convince the threadsafebindinglist we are using a synchronization context  
                //by providing a synchronization context
                var context = new MockContext();
                SynchronizationContext.SetSynchronizationContext(context);

                var list = new ThreadsafeBindingList<int>(context);

                //create a new thread adding something to the list
                //use an anonymous lambda expression delegate :)
                var addFiveThread = new Thread(() =>
                {
                    list.Add(5);
                });
                //action! run the thread adding 5
                addFiveThread.Start();
                //wait for the other thread to finish
                while (addFiveThread.IsAlive)
                    Thread.Sleep(10);

                //assert the list used the context.
                Assert.AreEqual(1, context.SendWasCalled, "The list did not use the send method the current context!");

            }
            finally
            {
                //always reset the synchronizationcontext
                SynchronizationContext.SetSynchronizationContext(null);
            }
            
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:34,代码来源:ThreadsafeBindingListTest.cs

示例9: Arrange_CallBackFourArguments_InvokesCallback

        public void Arrange_CallBackFourArguments_InvokesCallback()
        {
            var mockContext = new MockContext<IFoo>();
            var fooMock = new FooMock(mockContext);
            int firstResult = 0;
            int secondResult = 0;
            int thirdResult = 0;
            int fourthResult = 0;
            mockContext.Arrange(
                f => f.Execute(The<int>.IsAnyValue, The<int>.IsAnyValue, The<int>.IsAnyValue, The<int>.IsAnyValue))
                .Callback<int, int, int, int>(
                    (i1, i2, i3, i4) =>
                    {
                        firstResult = i1;
                        secondResult = i2;
                        thirdResult = i3;
                        fourthResult = i4;
                    });

            fooMock.Execute(1, 2, 3, 4);

            Assert.AreEqual(1, firstResult);
            Assert.AreEqual(2, secondResult);
            Assert.AreEqual(3, thirdResult);
            Assert.AreEqual(4, fourthResult);
        }
开发者ID:gazzyt,项目名称:LightMock,代码行数:26,代码来源:ArrangementTests.cs

示例10: Assert_InvokedOnceExpectedOnce_IsVerified

 public void Assert_InvokedOnceExpectedOnce_IsVerified()
 {
     var mockContext = new MockContext<IFoo>();
     var fooMock = new FooMock(mockContext);
     fooMock.Execute("SomeValue");
     mockContext.Assert(f => f.Execute("SomeValue"), Invoked.Once);
 }
开发者ID:gazzyt,项目名称:LightMock,代码行数:7,代码来源:MockContextTests.cs

示例11: Setup

		public void Setup()
		{
			context = new MockContext();
			var contextProvider = MockRepository.GenerateStub<IDataContextProvider>();
			contextProvider.Expect(x => x.DataContext).Return(context);
			filter = new UnitOfWorkFilter(contextProvider);
		}
开发者ID:bertusmagnus,项目名称:Sutekishop,代码行数:7,代码来源:UnitOfWorkFilterTester.cs

示例12: InitTestContext

 public void InitTestContext()
 {
     ruleT1 = new TestRuleT1();
     ruleDependent = new OtherRuleT1();
     transformation = new MockTransformation(ruleT1, ruleDependent);
     transformation.Initialize();
     context = new MockContext(transformation);
 }
开发者ID:FrederikP,项目名称:NMF,代码行数:8,代码来源:GeneralTransformationRuleTest.cs

示例13: Assert_InvokedTwiceWithExpectedOnce_ThrowsException

 public void Assert_InvokedTwiceWithExpectedOnce_ThrowsException()
 {
     var mockContext = new MockContext<IFoo>();
     var fooMock = new FooMock(mockContext);
     fooMock.Execute("SomeValue");
     fooMock.Execute("SomeValue");
     mockContext.Assert(f => f.Execute("SomeValue"), Invoked.Once);
 }
开发者ID:gazzyt,项目名称:LightMock,代码行数:8,代码来源:MockContextTests.cs

示例14: GetContainerMock

 private MockContext<IServiceContainer> GetContainerMock(Func<ILifetime> lifetimeFactory, Func<Type, Type, bool> shouldRegister)
 {
     var mockContext = new MockContext<IServiceContainer>();
     var containerMock = new ContainerMock(mockContext);            
     var assemblyScanner = new AssemblyScanner(new ConcreteTypeExtractor(), new CompositionRootTypeExtractor(), new CompositionRootExecutor(containerMock));
     assemblyScanner.Scan(typeof(IFoo).Assembly, containerMock, lifetimeFactory, shouldRegister);
     return mockContext;
 }
开发者ID:vitamink,项目名称:LightInject,代码行数:8,代码来源:AssemblyScannerTests.cs

示例15: CreateService

        /// <summary>
        /// Create a Splunk <see cref="Service" /> and login using the settings
        /// provided in .splunkrc.
        /// </summary>
        /// <param name="ns">
        /// </param>
        /// <returns>
        /// The service created.
        /// </returns>
        public static async Task<Service> CreateService(Namespace ns = null)
        {
            var context = new MockContext(Splunk.Scheme, Splunk.Host, Splunk.Port);
            var service = new Service(context, ns);
            
            await service.LogOnAsync(Splunk.Username, Splunk.Password);

            return service;
        }
开发者ID:nagyist,项目名称:splunk-sdk-csharp-pcl,代码行数:18,代码来源:SdkHelper.cs


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