Open td0g-Z opened 4 years ago
Hi Tom, thank you for spotting this; unfortunately I have moved to a different role and I am not using this library so it is not under active development.
Throw/ThrowAsync is not currently implemented, but I would be more than happy to review a PR if anyone updated the code to support it.
Hi, thanks for the reply. If I get some free time I'll try to have a look at it 👍
It would be nice if support for this was implemented. Our code has a gap in code coverage because of this. Thanks in advance.
You can cover you code by throwing synchronously Here is the code working for me: On an async method 1- ReturnsAsync 2- Throw
var stub = new Stub();
var expected = stub.dummyRecords;
stub.dbConnection.SetupDapperAsync(x => x.QueryAsync<MyModel>(It.IsAny<string>(), null, null, null, CommandType.StoredProcedure))
.ReturnsAsync(expected);
var result = await stub.repository.GetRecordsById(Guid.NewGuid());
Assert.NotNull(result);
// Catch block
stub.dbConnection.SetupDapperAsync(x => x.QueryAsync<MyModel>(It.IsAny<string>(), null, null, null, CommandType.StoredProcedure))
.Throws(new Exception());
var act = async () => await stub.repository.GetRecordsById(Guid.NewGuid());
_ = Assert.ThrowsAsync<Exception>(act);
Hope it will help
@AliAdravi this is a false positive. When doing this, your code isn't actually throwing the exception.
anything news?
Even I am facing similar problem, the SetupDapperAsync code to throw exception doesn't actually throw exception
//mock
moqSQLDBConnection.SetupDapperAsync(x => x.QueryAsync(It.IsAny
//code var queryResult = await _connection.QueryAsync("dbo.spo.AddBook @name, @purchasedDate, @price, @imageBlobURL, @categoryId", new { name = model.Name, purchasedDate = model.PurchasedDate, price = model.Price, imageBlobURL = model.ImageBlobURL, categoryId = model.CategoryId });
I am trying to mock _connection.QueryAsync to throw exception, but it doesn't throw exception
I am trying to simulate a query throwing an exception. So I can test how my code handles this.
I am doing a setup along the lines of
The code errors whilst performing this setup and throws an exception with the following message:
One or more errors occurred. (error executing db query)
It appears almost as if my dummy exception is being thrown during the setup.
Am I doing something wrong? Or is .ThrowsAsync not supported?
Thanks for making this library it is very useful Tom