public async Task WhenGetMultiResultReadersAsync_IsCalled__ItShouldCallSqlExecutorGetMultiResultReaderAsync()
        {
            List <Employee>   returnList = new List <Employee>();
            MultiResultReader reader     = new MultiResultReader(new CustomDbReader());

#if ADVANCE_ASYNC
            _executor.Setup(x => x.GetMultiResultReaderAsync(realQuery.QueryText, realQuery.QueryType, realQuery.Parameters, realQuery.CommandTimeout, realQuery.ShouldBePrepared, CancellationToken.None)).ReturnsAsync(reader).Verifiable();
#else
            _executor.Setup(x => x.GetMultiResultReaderAsync(realQuery.QueryText, realQuery.QueryType, realQuery.Parameters, realQuery.CommandTimeout, CancellationToken.None)).ReturnsAsync(reader).Verifiable();
#endif

            //Make the call
            IMultiResultReader returnedValue = await new DbClient(_executor.Object).GetMultiResultReaderAsync(realQuery, CancellationToken.None);

            Assert.IsNotNull(returnedValue);

#if ADVANCE_ASYNC
            //Verify the executor was called
            _executor.Verify(x => x.GetMultiResultReaderAsync(realQuery.QueryText, realQuery.QueryType, realQuery.Parameters, realQuery.CommandTimeout, realQuery.ShouldBePrepared, CancellationToken.None), Times.Once);
#else
            //Verify the executor was called
            _executor.Verify(x => x.GetMultiResultReaderAsync(realQuery.QueryText, realQuery.QueryType, realQuery.Parameters, realQuery.CommandTimeout, CancellationToken.None), Times.Once);
#endif

            _executor.VerifyNoOtherCalls();
        }
        public void WhenReadObject_IsCalled_ShouldCall_ReaderReadFalse()
        {
            DateTime    dateBirth     = _faker.Person.DateOfBirth;
            string      firstName     = _faker.Person.FirstName;
            string      lastName      = _faker.Person.LastName;
            PersonModel expectedModel = new PersonModel()
            {
                FirstName   = firstName,
                LastName    = lastName,
                DateOfBirth = dateBirth
            };

            _mockReader.Setup(x => x.Read()).Returns(false);
            _mockMapper.Setup(x => x.MapRecord <PersonModel>(_mockReader.Object)).Returns(expectedModel);

            MultiResultReader reader        = new MultiResultReader(_mockReader.Object, _mockMapper.Object);
            PersonModel       returnedModel = reader.ReadObject <PersonModel>();

            Assert.AreEqual(returnedModel, default(PersonModel));

            _mockReader.Verify(x => x.Read(), Times.Once);
            _mockReader.VerifyNoOtherCalls();
            _mockMapper.Verify(x => x.MapRecord <PersonModel>(_mockReader.Object), Times.Never);
            _mockMapper.VerifyNoOtherCalls();
        }
        public async Task WhenReadObject_IsCalled_ShouldCall_ReaderReadAsyncTrue()
        {
            DateTime    dateBirth     = _faker.Person.DateOfBirth;
            string      firstName     = _faker.Person.FirstName;
            string      lastName      = _faker.Person.LastName;
            PersonModel expectedModel = new PersonModel()
            {
                FirstName   = firstName,
                LastName    = lastName,
                DateOfBirth = dateBirth
            };

            _mockMapper.Setup(x => x.MapRecord <PersonModel>(It.IsAny <IDataRecord>())).Returns(expectedModel);
            _mockReader.Setup(x => x.ReadAsync(It.IsAny <CancellationToken>())).ReturnsAsync(true);

            MultiResultReader multiReader   = new MultiResultReader(_mockReader.Object, _mockMapper.Object);
            PersonModel       returnedModel = await multiReader.ReadObjectAsync <PersonModel>(CancellationToken.None);

            Assert.IsNotNull(returnedModel);
            Assert.AreEqual(returnedModel.DateOfBirth, expectedModel.DateOfBirth);
            Assert.AreEqual(returnedModel.FirstName, expectedModel.FirstName);
            Assert.AreEqual(returnedModel.LastName, expectedModel.LastName);

            //Verify the readers read method was called
            _mockMapper.Verify(x => x.MapRecord <PersonModel>(_mockReader.Object), Times.Once);
            _mockMapper.VerifyNoOtherCalls();
            _mockReader.Verify(x => x.ReadAsync(CancellationToken.None), Times.Once);
            _mockReader.VerifyNoOtherCalls();
        }
        public void WhenDispose_IsCalled_ShouldCall_ReaderClose()
        {
            _mockReader.Setup(x => x.Close());

            MultiResultReader reader = new MultiResultReader(_mockReader.Object, _mockMapper.Object);

            reader.Dispose();

            _mockReader.Verify(x => x.Close(), Times.Once);
        }
        public async Task WhenCloseAsync_IsCalled_ShouldCall_ReaderCloseAsync()
        {
            _mockReader.Setup(x => x.CloseAsync());

            MultiResultReader reader = new MultiResultReader(_mockReader.Object, _mockMapper.Object);

            await reader.CloseAsync();

            _mockReader.Verify(x => x.CloseAsync(), Times.Once);
            _mockReader.VerifyNoOtherCalls();
        }
        public void WhenNextResult_IsCalled_ShouldCall_ReaderNextResult()
        {
            bool expected = _faker.Random.Bool();

            _mockReader.Setup(x => x.NextResult()).Returns(expected);

            MultiResultReader reader = new MultiResultReader(_mockReader.Object, _mockMapper.Object);

            bool returned = reader.MoveToNextResult();

            Assert.AreEqual(expected, returned);

            _mockReader.Verify(x => x.NextResult(), Times.Once);
            _mockReader.VerifyNoOtherCalls();
        }
        public async Task WhenNextResultAsync_IsCalled_ShouldCall_ReaderNextResultAsync()
        {
            int  delay    = _faker.Random.Int(0, 1000);
            bool expected = _faker.Random.Bool();

            _mockReader.Setup(x => x.NextResultAsync(It.IsAny <CancellationToken>())).ReturnsAsync(expected);

            MultiResultReader multiReader = new MultiResultReader(_mockReader.Object, _mockMapper.Object);

            bool returned = await multiReader.MoveToNextResultAsync(CancellationToken.None).ConfigureAwait(false);

            Assert.IsTrue(expected == returned);

            //Verify the readers read method was called
            _mockReader.Verify(x => x.NextResultAsync(CancellationToken.None), Times.Once);
            _mockReader.VerifyNoOtherCalls();
        }