public void SetUp() { _expectedRows = new[] { "row1", "row2" }; _cacheRows = new[] { "cache_row_1", "cache_row_2" }; _cache = new Mock <IDbCache>(); _cache.Setup(x => x.TryGetValue(It.IsAny <string>(), out _cacheRows)) .Returns(false); _connection = new Mock <IDbConnection>(); var sp = new FakeStoredProc(); _connection.SetupDapper( c => c.Query <string>( sp.StoredProcedureName, "foo", null, true, sp.CommandTimeoutSecs, CommandType.StoredProcedure)) .Returns(_expectedRows); _dbResources = new Mock <IDbResourceManager>(); _dbResources.Setup(x => x.ChooseDb(sp.DbName).SelectRandomly()) .Returns("connection_str"); _onErrorEvents = new List <DbErrorEventArgs>(); _onQueryCompleteEvents = new List <QueryCompleteEventArgs>(); _db = new DbRepository( _dbResources.Object, _cache.Object, _ => _connection.Object); _db.OnError += (sender, args) => _onErrorEvents.Add(args); _db.OnQueryComplete += (sender, args) => _onQueryCompleteEvents.Add(args); }
private void SetupAsync() { // We can only call either SetupDapper or SetupDapperAsync once. // Testing async methods helped me to find a bug of Cache.CreateOrGet. // Although it's still stupid copy-paste of code. var sp = new FakeStoredProc(); _connection.SetupDapperAsync( c => c.QueryAsync <string>( sp.StoredProcedureName, "foo", null, sp.CommandTimeoutSecs, CommandType.StoredProcedure)) .ReturnsAsync(_expectedRows); }