public async Task ObterPorId_DeveRetornarNullQuandoNaoForEncontradoNoBanco() { var query = new ObterNivelPorIdQuery(Guid.NewGuid()); var queryHandler = new NivelQueryHandler(_nivelRepository); var nivelBanco = await queryHandler.Handle(query, CancellationToken.None); nivelBanco.Should().BeNull(); }
public async Task ObterPorId_DeveInvalidarQueryQuandoIdForVazio() { var query = new ObterNivelPorIdQuery(Guid.Empty); var queryHandler = new NivelQueryHandler(_nivelRepository); await queryHandler.Handle(query, CancellationToken.None); (await query.EhValido()).Should().Be(false); query.ValidationResult.Errors .Should() .Contain(error => error.ErrorMessage == "Id deve possuir conteúdo"); }
public async Task ObterPorId_DeveRetornarNivelQuandoForEncontradoNoBanco() { var nivel = NivelFactory.GerarNivel(); await _context.Niveis.AddAsync(nivel); await _context.SaveChangesAsync(); var query = new ObterNivelPorIdQuery(nivel.Id); var queryHandler = new NivelQueryHandler(_nivelRepository); var nivelBanco = await queryHandler.Handle(query, CancellationToken.None); nivelBanco.Should().BeEquivalentTo(nivel); }
public async Task HandlerObterTodos_DeveRetornarTodosOsNivelsSalvosNoBanco() { var nivel1 = NivelFactory.GerarNivel(); var nivel2 = NivelFactory.GerarNivel(); await _context.Niveis.AddRangeAsync(nivel1, nivel2); await _context.SaveChangesAsync(); var query = new ObterTodosOsNiveisQuery(1, 20); var queryHandler = new NivelQueryHandler(_nivelRepository); var niveis = await queryHandler.Handle(query, CancellationToken.None); niveis.Should().HaveCount(2); }