本文整理汇总了C#中NUnit.Mocks.DynamicMock.Expect方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicMock.Expect方法的具体用法?C# DynamicMock.Expect怎么用?C# DynamicMock.Expect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NUnit.Mocks.DynamicMock
的用法示例。
在下文中一共展示了DynamicMock.Expect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanAddEventListener
public void CanAddEventListener()
{
DynamicMock mock = new DynamicMock( typeof(EventListener) );
mock.Expect( "RunStarted" );
mock.Expect( "RunFinished" );
IExtensionPoint ep = host.GetExtensionPoint("EventListeners");
ep.Install( mock.MockInstance );
host.Listeners.RunStarted( "test", 0 );
host.Listeners.RunFinished( new TestSuiteResult(null, "test") );
mock.Verify();
}
示例2: SetUpCurrentVersion
void SetUpCurrentVersion(long version, List<long> appliedVersions, bool assertRollbackIsCalled, bool includeBad)
{
var providerMock = new DynamicMock(typeof (ITransformationProvider));
providerMock.SetReturnValue("get_MaxVersion", version);
providerMock.SetReturnValue("get_AppliedMigrations", appliedVersions);
providerMock.SetReturnValue("get_Logger", new Logger(false));
if (assertRollbackIsCalled)
providerMock.Expect("Rollback");
else
providerMock.ExpectNoCall("Rollback");
_migrator = new Migrator((ITransformationProvider) providerMock.MockInstance, Assembly.GetExecutingAssembly(), false);
// Enlève toutes les migrations trouvée automatiquement
_migrator.MigrationsTypes.Clear();
_upCalled.Clear();
_downCalled.Clear();
_migrator.MigrationsTypes.Add(typeof (FirstMigration));
_migrator.MigrationsTypes.Add(typeof (SecondMigration));
_migrator.MigrationsTypes.Add(typeof (ThirdMigration));
_migrator.MigrationsTypes.Add(typeof (FourthMigration));
_migrator.MigrationsTypes.Add(typeof (SixthMigration));
if (includeBad)
_migrator.MigrationsTypes.Add(typeof (BadMigration));
}
示例3: ShouldUseFindsByNameToLocateElementsByName
public void ShouldUseFindsByNameToLocateElementsByName()
{
DynamicMock driver = new DynamicMock(typeof(IAllDriver));
driver.Expect("FindElementByName", new object[] { "cheese" });
By by = By.Name("cheese");
by.FindElement(driver.MockInstance as IAllDriver);
}
示例4: ShouldUseXPathToFindByNameIfDriverDoesNotImplementFindsByName
// TODO (jimevan): This test is disabled in the Java implementation unit tests.
// Is the functionality not implemented?
public void ShouldUseXPathToFindByNameIfDriverDoesNotImplementFindsByName()
{
DynamicMock driver = new DynamicMock(typeof(IOnlyXPath));
driver.Expect("FindElementByXPath", new object[] { "//*[@name='cheese']" });
By by = By.Name("cheese");
by.FindElement(driver.MockInstance as IOnlyXPath);
}
示例5: IsLoginOK_WhenCalled_WritesToLog
public void IsLoginOK_WhenCalled_WritesToLog()
{
DynamicMock mockLog = new DynamicMock(typeof(ILogger));
mockLog.Expect("Write","login ok: user: u");
var loginManager = new LoginManagerWithMock((ILogger)mockLog.MockInstance);
loginManager.IsLoginOK("", "");
mockLog.Verify();
}
示例6: CanAddDecorator
public void CanAddDecorator()
{
DynamicMock mock = new DynamicMock( typeof(ITestDecorator) );
mock.Expect( "Decorate" );
IExtensionPoint ep = host.GetExtensionPoint("TestDecorators");
ep.Install( mock.MockInstance );
host.TestDecorators.Decorate( null, null );
mock.Verify();
}
示例7: CanAddTestCaseBuilder
public void CanAddTestCaseBuilder()
{
DynamicMock mock = new DynamicMock( typeof(ITestCaseBuilder) );
mock.ExpectAndReturn( "CanBuildFrom", true, null );
mock.Expect( "BuildFrom" );
IExtensionPoint ep = host.GetExtensionPoint("TestCaseBuilders");
ep.Install( mock.MockInstance );
host.TestBuilders.BuildFrom( null );
mock.Verify();
}
示例8: Analyze_TooShortFileName_CallsWebService
public void Analyze_TooShortFileName_CallsWebService()
{
DynamicMock mockController = new DynamicMock(typeof (IWebService));
mockController.Expect("LogError", "Filename too short:abc.ext");
IWebService mockService = mockController.MockInstance as IWebService;
LogAnalyzer log = new LogAnalyzer(mockService);
string tooShortFileName="abc.ext";
log.Analyze(tooShortFileName);
mockController.Verify();
}
示例9: Install_Successful
public void Install_Successful()
{
DynamicMock extensionPointMock = new DynamicMock(typeof(IExtensionPoint));
IExtensionPoint extensionPoint = (IExtensionPoint) extensionPointMock.MockInstance;
extensionHostMock.ExpectAndReturn("GetExtensionPoint", extensionPoint, "ParameterProviders");
extensionPointMock.Expect("Install");
bool installed = addIn.Install(extensionHost);
extensionHostMock.Verify();
extensionPointMock.Verify();
Assert.That(installed, Is.True);
}
示例10: IsLoginOK_LoggerThrowsException_WritesToWebService
public void IsLoginOK_LoggerThrowsException_WritesToWebService()
{
DynamicMock stubLog = new DynamicMock(typeof(ILogger));
DynamicMock mockService = new DynamicMock(typeof(IWebService));
stubLog.ExpectAndThrow("Write",new LoggerException("fake exception"),"yo" );
mockService.Expect("Write","got exception");
var loginManager =
new LoginManagerWithMockAndStub((ILogger)stubLog.MockInstance,
(IWebService) mockService.MockInstance);
loginManager.IsLoginOK("", "");
mockService.Verify();
}
示例11: TestDeleteCity
public void TestDeleteCity()
{
List<City> cities = new List<City>();
City city = new City { Name = "New York", DistrictId = 12 };
DynamicMock dynamicMock = new DynamicMock(typeof(LocationsManager));
dynamicMock.ExpectAndReturn("AddCity", 3,city);
dynamicMock.SetReturnValue("GetCities", cities);
dynamicMock.Expect("DeleteCityById", 2);
LocationsManager mocklocationManager = (LocationsManager)dynamicMock.MockInstance;
LocationServices locationService = new LocationServices(mocklocationManager);
locationService.DeleteCity(2);
Assert.AreEqual(3, locationService.AddCity(city));
Assert.AreEqual(0, locationService.GetCities().Count);
}
示例12: SetUpCurrentVersion
void SetUpCurrentVersion(int version, bool assertRollbackIsCalled)
{
var providerMock = new DynamicMock(typeof (ITransformationProvider));
providerMock.SetReturnValue("get_CurrentVersion", version);
providerMock.SetReturnValue("get_Logger", new Logger(false));
if (assertRollbackIsCalled)
providerMock.Expect("Rollback");
else
providerMock.ExpectNoCall("Rollback");
_migrationLoader = new MigrationLoader((ITransformationProvider) providerMock.MockInstance, Assembly.GetExecutingAssembly(), true);
_migrationLoader.MigrationsTypes.Add(typeof (MigratorTest.FirstMigration));
_migrationLoader.MigrationsTypes.Add(typeof (MigratorTest.SecondMigration));
_migrationLoader.MigrationsTypes.Add(typeof (MigratorTest.ThirdMigration));
_migrationLoader.MigrationsTypes.Add(typeof (MigratorTest.ForthMigration));
_migrationLoader.MigrationsTypes.Add(typeof (MigratorTest.BadMigration));
_migrationLoader.MigrationsTypes.Add(typeof (MigratorTest.SixthMigration));
_migrationLoader.MigrationsTypes.Add(typeof (MigratorTest.NonIgnoredMigration));
}
示例13: TestExport
public void TestExport()
{
m_FileSystem = new DynamicMock(typeof(IFileSystem));
List<Context> selected = new List<Context>();
Context result = new Context();
result.Tokens.Add("a");
result.Tokens.Add("b");
result.Tokens.Add("c");
Context branch = result.Branch("b1");
branch.Tokens.Add("d");
selected.Add(result);
IExporter exporter = new CsvExporter();
m_FileSystem.Expect("WriteAllText", @"c:\abc.csv", string.Format(".Word.;b1{0}abc;abcd{0}", Environment.NewLine));
exporter.Export(selected, @"c:\abc.csv", (IFileSystem)m_FileSystem.MockInstance);
m_FileSystem.Verify();
}
示例14: testCommitTransactionCalled
public void testCommitTransactionCalled()
{
//STOP -- check with instructor before beginning this test~
//now go break your code -- don't call the 'commit transaction' or the 'update account' methods. Does the test above fail?
//use dynamic mocks to verify that these methods are called.
//here's an example of creating the credit card service. You'll need another thing just like this for
//the account update. These mocks will replace the stub code from the happyPathTest
DynamicMock mockCreditCardService = new DynamicMock(typeof (ICreditCardService));
//some expectations
int token = 42;
String ccNum = "4324 3924 4382 3888";
Decimal amount = 199.99M;
mockCreditCardService.ExpectAndReturn("ReserveFunds", token, new Object[2] { ccNum, amount });
mockCreditCardService.Expect("CommitTransaction", new Object[1] { token });
ICreditCardService creditCardServiceInstance = (ICreditCardService) mockCreditCardService.MockInstance;
//calls to the actual class under test goes here
AccountUpdater au = new AccountUpdater(new StubBalanceService(), creditCardServiceInstance);
au.UpdateAccount(ccNum, amount, 3982834);
//this should be the last line.
mockCreditCardService.Verify();
}
示例15: ShouldApplyBackgroundToStoppedStreams
public void ShouldApplyBackgroundToStoppedStreams()
{
const string units = "V";
const MultiClampInterop.OperatingMode vclampMode = MultiClampInterop.OperatingMode.VClamp;
const MultiClampInterop.OperatingMode iclampMode = MultiClampInterop.OperatingMode.IClamp;
var c = new Controller();
var mc = new FakeMulticlampCommander();
var vclampBackground = new Measurement(2, -3, units);
var background = new Dictionary<MultiClampInterop.OperatingMode, IMeasurement>()
{
{ vclampMode, vclampBackground }
};
var dataVClamp = new MultiClampInterop.MulticlampData()
{
OperatingMode = vclampMode,
ExternalCommandSensitivity = 2.5,
ExternalCommandSensitivityUnits = MultiClampInterop.ExternalCommandSensitivityUnits.V_V
};
var daq = new DynamicMock(typeof(IDAQController));
var s = new DAQOutputStream("test", daq.MockInstance as IDAQController);
var mcd = new MultiClampDevice(mc, c, background);
mcd.BindStream(s);
daq.ExpectAndReturn("get_Running", false);
daq.Expect("ApplyStreamBackground", new object[] {s});
mc.FireParametersChanged(DateTimeOffset.Now, dataVClamp);
daq.Verify();
}