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();
        }
Esempio n. 2
0
        public async Task <Nivel> Handle(ObterNivelPorIdQuery request, CancellationToken cancellationToken)
        {
            if (!await request.EhValido())
            {
                return(null);
            }

            return(await _nivelRepository.ObterPorId(request.Id));
        }
        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);
        }