public async Task GetSimpleRoles_GivenDataIsFound_ExpectMaybeWithMappedData() { var dto = new SimpleRoleDto { Id = TestVariables.RoleId, Name = "Name", }; var connection = new Mock <IDbConnection>(); connection.SetupDapperAsync(c => c.QueryAsync <SimpleRoleDto>( It.IsAny <string>(), It.IsAny <DynamicParameters>(), null, null, It.IsAny <CommandType>())) .ReturnsAsync(() => new List <SimpleRoleDto> { dto, }); var dbConnectionProvider = new Mock <IConnectionProvider>(); dbConnectionProvider.Setup(x => x.GetConnection()) .Returns(() => connection.Object); var roleQueries = new RoleQueries(dbConnectionProvider.Object); var result = await roleQueries.GetSimpleRoles(); Assert.True(result.HasValue); Assert.Single(result.Value); Assert.Equal(dto.Name, result.Value.First().Name); Assert.Equal(dto.Id, result.Value.First().Id); }
public async Task GetSimpleRoles_GivenNoDataIsFound_ExpectMaybeWithNothing() { var connection = new Mock <IDbConnection>(); connection.SetupDapperAsync(c => c.QueryAsync <SimpleRoleDto>( It.IsAny <string>(), It.IsAny <DynamicParameters>(), null, null, It.IsAny <CommandType>())) .ReturnsAsync(() => new List <SimpleRoleDto>()); var dbConnectionProvider = new Mock <IConnectionProvider>(); dbConnectionProvider.Setup(x => x.GetConnection()) .Returns(() => connection.Object); var roleQueries = new RoleQueries(dbConnectionProvider.Object); var result = await roleQueries.GetSimpleRoles(); Assert.True(result.HasNoValue); }