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 TestMethod_WithReturnType_WithParameters_DefaultBehavior_Loose_Async()
        {
            var        stub      = new StubIPhoneBook(MockBehavior.Loose);
            IPhoneBook phoneBook = stub;

            Assert.AreEqual(0, await phoneBook.GetContactPhoneNumberAsync("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 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 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 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 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"));
        }