public void TestThatExceptionIsThrownWhenStubIsNotSetup() { var stub = new StubIPhoneBook(); IPhoneBook phoneBook = stub; phoneBook.GetContactPhoneNumber("John", "Smith"); }
public void TestMethod_WithReturnType_WithParameters_DefaultBehavior_Loose() { var stub = new StubIPhoneBook(MockBehavior.Loose); IPhoneBook phoneBook = stub; Assert.AreEqual(0, phoneBook.GetContactPhoneNumber("John", "Smith")); }
public async Task TestMethod_WithReturnType_WithParameters_DefaultBehavior_Strict_Async() { var stub = new StubIPhoneBook(MockBehavior.Strict); IPhoneBook phoneBook = stub; Assert.AreEqual(0, await phoneBook.GetContactPhoneNumberAsync("John", "Smith")); }
public void TestThatDefaultBehaviorIsUsedWhenStubIsNotSetup() { var stub = new StubIPhoneBook(); IPhoneBook phoneBook = stub; var result = phoneBook.GetContactPhoneNumber("John", "Smith"); Assert.AreEqual(0, result); }
public void TestThatExceptionIsThrownWhenMethodIsCalledMoreThanExpected() { var stub = new StubIPhoneBook().GetContactPhoneNumber((p1, p2) => 12345678, Times.Once); IPhoneBook phoneBook = stub; phoneBook.GetContactPhoneNumber("John", "Smith"); phoneBook.GetContactPhoneNumber("John", "Smith"); }
public async Task TestThatDefaultBehaviorIsUsedWhenStubIsNotSetup_Async() { var stub = new StubIPhoneBook(); IPhoneBook phoneBook = stub; var result = await phoneBook.GetContactPhoneNumberAsync("John", "Smith"); Assert.AreEqual(0, result); }
public void TestPropertyStubWithGetterOnly() { int contactsCount = 55; var stub = new StubIPhoneBook().ContactsCount_Get(() => contactsCount); IPhoneBook phoneBook = stub; Assert.AreEqual(contactsCount, phoneBook.ContactsCount); }
public void TestThatLooseMockBehaviorsAreAlwaysOverwritten() { var stub = new StubIPhoneBook(MockBehavior.Loose) .GetContactPhoneNumber((p1, p2) => 12345678); IPhoneBook phoneBook = stub; Assert.AreEqual(12345678, phoneBook.GetContactPhoneNumber("John", "Smith")); }
public async Task TestThatExceptionIsThrownWhenMethodIsCalledMoreThanExpected_Async() { var stub = new StubIPhoneBook() .GetContactPhoneNumberAsync(async(p1, p2) => await Task.FromResult(12345678), Times.Once); IPhoneBook phoneBook = stub; await phoneBook.GetContactPhoneNumberAsync("John", "Smith"); await phoneBook.GetContactPhoneNumberAsync("John", "Smith"); }
public async Task TestThatLooseMockBehaviorsAreAlwaysOverridden_Async() { var stub = new StubIPhoneBook(MockBehavior.Loose) .GetContactPhoneNumberAsync(async(p1, p2) => await Task.FromResult(12345678)); IPhoneBook phoneBook = stub; Assert.AreEqual(12345678, await phoneBook.GetContactPhoneNumberAsync("John", "Smith")); }
public void TestThatMethodStubCanBeOverwritten() { var stub = new StubIPhoneBook().GetContactPhoneNumber((p1, p2) => 12345678); stub.GetContactPhoneNumber((p1, p2) => 11122233, overwrite: true); IPhoneBook phoneBook = stub; Assert.AreEqual(11122233, phoneBook.GetContactPhoneNumber("John", "Smith")); }
public async Task TestThatMethodStubCanBeOverwritten_Async() { var stub = new StubIPhoneBook(). GetContactPhoneNumberAsync(async(p1, p2) => await Task.FromResult(12345678)); stub.GetContactPhoneNumberAsync(async(p1, p2) => await Task.FromResult(11122233), overwrite: true); IPhoneBook phoneBook = stub; Assert.AreEqual(11122233, await phoneBook.GetContactPhoneNumberAsync("John", "Smith")); }
public void TestPropertyStubWithGetterAndSetter() { long myNumber = 6041234567; long newNumber = 0; var stub = new StubIPhoneBook() .MyNumber_Get(() => myNumber) .MyNumber_Set(value => newNumber = value); IPhoneBook phoneBook = stub; Assert.AreEqual(myNumber, phoneBook.MyNumber); phoneBook.MyNumber = 13; Assert.AreEqual(13, newNumber); }
public void TestEventStub() { object sender = null; long newNumber = 0; var stub = new StubIPhoneBook(); stub.PhoneNumberChanged += (s, num) => { sender = s; newNumber = num; } ; stub.PhoneNumberChanged_Raise(this, 55); Assert.AreEqual(55, newNumber); Assert.AreEqual(this, sender); }
public async Task TestCallSequence_Async() { var stub = new StubIPhoneBook() .GetContactPhoneNumberAsync(async(p1, p2) => await Task.FromResult(12345678), Times.Once) // first call .GetContactPhoneNumberAsync(async(p1, p2) => await Task.FromResult(11122233), Times.Twice) // next two calls .GetContactPhoneNumberAsync(async(p1, p2) => await Task.FromResult(22233556), Times.Forever); // rest of the calls IPhoneBook phoneBook = stub; Assert.AreEqual(12345678, await phoneBook.GetContactPhoneNumberAsync("John", "Smith")); Assert.AreEqual(11122233, await phoneBook.GetContactPhoneNumberAsync("John", "Smith")); Assert.AreEqual(11122233, await phoneBook.GetContactPhoneNumberAsync("John", "Smith")); Assert.AreEqual(22233556, await phoneBook.GetContactPhoneNumberAsync("John", "Smith")); Assert.AreEqual(22233556, await phoneBook.GetContactPhoneNumberAsync("John", "Smith")); Assert.AreEqual(22233556, await phoneBook.GetContactPhoneNumberAsync("John", "Smith")); }
public void TestCallSequence() { var stub = new StubIPhoneBook() .GetContactPhoneNumber((p1, p2) => 12345678, Times.Once) // first call .GetContactPhoneNumber((p1, p2) => 11122233, Times.Twice) // next two calls .GetContactPhoneNumber((p1, p2) => 22233556, Times.Forever); // rest of the calls IPhoneBook phoneBook = stub; Assert.AreEqual(12345678, phoneBook.GetContactPhoneNumber("John", "Smith")); Assert.AreEqual(11122233, phoneBook.GetContactPhoneNumber("John", "Smith")); Assert.AreEqual(11122233, phoneBook.GetContactPhoneNumber("John", "Smith")); Assert.AreEqual(22233556, phoneBook.GetContactPhoneNumber("John", "Smith")); Assert.AreEqual(22233556, phoneBook.GetContactPhoneNumber("John", "Smith")); Assert.AreEqual(22233556, phoneBook.GetContactPhoneNumber("John", "Smith")); }
public async Task TestMethod_WithReturnType_WithParameters_Async() { long number = 6041234567; string firstName = null; string lastName = null; var stub = new StubIPhoneBook(); stub.GetContactPhoneNumberAsync(async(fn, ln) => { firstName = fn; lastName = ln; return(await Task.FromResult(number)); }); IPhoneBook phoneBook = stub; long actualNumber = await phoneBook.GetContactPhoneNumberAsync("John", "Smith"); Assert.AreEqual(number, actualNumber); Assert.AreEqual("John", firstName); Assert.AreEqual("Smith", lastName); }
public void TestMethod_WithReturnType_WithParameters() { long number = 6041234567; string firstName = null; string lastName = null; var stub = new StubIPhoneBook(); stub.GetContactPhoneNumber((fn, ln) => { firstName = fn; lastName = ln; return(number); }); IPhoneBook phoneBook = stub; long actualNumber = phoneBook.GetContactPhoneNumber("John", "Smith"); Assert.AreEqual(number, actualNumber); Assert.AreEqual("John", firstName); Assert.AreEqual("Smith", lastName); }