本文整理汇总了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);
}
示例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"}
} );
}
示例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);
}
示例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();
}
示例5: InitializeContext
protected void InitializeContext()
{
var contextMappings = new EntityMappingStore();
var rmp = new ReflectionMappingProvider();
rmp.AddMappingsForAssembly(contextMappings, typeof(LinqToSparqlTests).Assembly);
Context = new MockContext(contextMappings);
}
示例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);
}
示例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"));
}
示例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);
}
}
示例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);
}
示例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);
}
示例11: Setup
public void Setup()
{
context = new MockContext();
var contextProvider = MockRepository.GenerateStub<IDataContextProvider>();
contextProvider.Expect(x => x.DataContext).Return(context);
filter = new UnitOfWorkFilter(contextProvider);
}
示例12: InitTestContext
public void InitTestContext()
{
ruleT1 = new TestRuleT1();
ruleDependent = new OtherRuleT1();
transformation = new MockTransformation(ruleT1, ruleDependent);
transformation.Initialize();
context = new MockContext(transformation);
}
示例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);
}
示例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;
}
示例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;
}