I have a test case to test my EF repository getallasync call as follows:
// Arrange
var systemsData = new List<SystemEntity>
{
new SystemEntity { SystemId = 1, Full_Year_Standings = true, Season_StartDate = DateTime.Now, Season_EndDate = DateTime.Now },
new SystemEntity { SystemId = 2, Full_Year_Standings = false, Season_StartDate = DateTime.Now, Season_EndDate = DateTime.Now },
new SystemEntity { SystemId = 3, Full_Year_Standings = true, Season_StartDate = DateTime.Now, Season_EndDate = DateTime.Now }
};
var mockContext = Mock.Create<BetCenterContext>(Behavior.Loose);
Mock.Arrange(() => mockContext.Set<SystemEntity>()).ReturnsCollection(systemsData);
var systemRepository = new SystemRepository(mockContext);
// Act
var result = await systemRepository.GetAllAsync();
Calling the following method:
public async Task<List<SystemEntity>> GetAllAsync()
{
var collToReturn = await _context.Set<SystemEntity>().ToListAsync();
return collToReturn;
}
The arranged mock returns a null result and throws InvalidOperationException - The source 'IQueryable' doesn't IAsyncEnumerable...'
How do I arrange the mock to return the correct value?
Hi,
I'm interested in Telerik JustMock, so I'm installing and testing a trial version of JustMock.I want the Mock to return the SQL statement and Not execute the statement. This is what i have done but it keeps running the "connection.execution(SQL)".
string SQL = "";
Mock.Arrange(() => connection.Execute(Arg.AnyString, null, null, null, null)).DoInstead((string arg1) => { SQL = arg1; }).IgnoreInstance().Returns(1);
WebApiProject.Controllers.DeleteController dc = new WebApiProject.Controllers.DeleteController();
dc.Post(mockedDeleteObject);
Assert.IsTrue(SQL == $"DELETE FROM TEST WHERE 1=1");
Post{
string SQL;
SQL = $"delete from {TableName} where {WhereClause} ";
con.Execute(SQL,parameters );}
But it keeps running the sql executable statement
Hi.
My configuration is: Visual Studio 2015 preview + JustMock Q2 2015 (2015.2.512.4)
Apparently static mocks don't work for me when i execute them from Windows Universal unit test project. It seems like the mock is not applied at all and the actual code is executed. For example here exception is not thrown:
Mock.SetupStatic(
typeof
(Assert), Behavior.Strict);
Mock.Arrange(() => Assert.IsTrue(Arg.AnyBool)).Throws(
new
ArgumentException());
Assert.IsTrue(
true
);
The same code though executes correctly and exception is thrown when i execute it from the regular unit test project.
Thank you.