Exemplo n.º 1
0
        public async Task UpdateAsync(ProdutoDomainModel model)
        {
            _produtoContext.Entry(model).State = EntityState.Modified;

            await _produtoContext
            .SaveChangesAsync()
            .ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public async Task CreateAsync(ProdutoDomainModel model)
        {
            await _produtoContext.ProdutoModels.AddAsync(model);

            await _produtoContext.SaveChangesAsync();

            _produtoContext.Entry(model).State = EntityState.Detached; //por conta dos testes de criação e alteração
        }
Exemplo n.º 3
0
        public void ValoresValidos_NaoDeveAddErro()
        {
            // Arrange
            var target = new ProdutoDomainModel("Teste", "1234.12", "~/test.img");

            // Act
            var result = target.IsValid(_validationResult);

            // Assert
            Assert.True(result);
            _validationResult.DidNotReceiveWithAnyArgs().AddError(string.Empty);
        }
Exemplo n.º 4
0
        public void ValorInvalido_DeveAddErro()
        {
            // Arrange
            var target          = new ProdutoDomainModel("Teste", "abcde", "~/test.img");
            var expectedMessage = "Valor é obrigatório";

            _validationResult.Erros.Returns(new[] { expectedMessage });

            // Act
            var result = target.IsValid(_validationResult);

            // Assert
            Assert.False(result);
            _validationResult.Received(1).AddError(expectedMessage);
        }
Exemplo n.º 5
0
        public void ValoresValidos_RealizarManutencao()
        {
            // Arrange
            var target = new ProdutoDomainModel("Teste", "1234.12", "~/test.img");

            // Act
            var result = target.RealizarManutencao(new ProdutoViewModel
            {
                Nome       = "abcd",
                Valor      = 1234.56M,
                ImagemPath = "~/abcd",
            });

            // Assert
            Assert.Equal("abcd", result.Nome);
            Assert.Equal(1234.56M, result.Valor);
            Assert.Equal("~/abcd", result.ImagemPath);
            _validationResult.DidNotReceiveWithAnyArgs().AddError(string.Empty);
        }