Exemplo n.º 1
0
        public void Update_Option_Success()
        {
            var options = new DbContextOptionsBuilder <BitcoinShowDBContext>()
                          .UseInMemoryDatabase(System.Guid.NewGuid().ToString())
                          .Options;
            var context   = new BitcoinShowDBContext(options);
            var newOption = new Option {
                Text = "New option"
            };

            context.Options.Add(newOption);
            context.SaveChanges();

            OptionRepository repository = new OptionRepository(context);
            Option           expected   = new Option();

            expected.Id   = newOption.Id;
            expected.Text = "Update option";

            Option actual = new Option();

            actual.Id   = newOption.Id;
            actual.Text = "Update option";

            repository.Update(actual);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        public void Update_Option_NonExistent_Error()
        {
            var options = new DbContextOptionsBuilder <BitcoinShowDBContext>()
                          .UseInMemoryDatabase(System.Guid.NewGuid().ToString())
                          .Options;
            var context = new BitcoinShowDBContext(options);

            OptionRepository repository = new OptionRepository(context);

            Option updatedOption = new Option();

            updatedOption.Id   = 1;
            updatedOption.Text = "Update";

            Exception ex = Assert.Throws <DbUpdateException>(() => repository.Update(updatedOption));

            Assert.NotNull(ex);
            Assert.Equal("The current option does not exists.", ex.Message);
        }
Exemplo n.º 3
0
        public void Update_Option_Without_Text_Error()
        {
            var options = new DbContextOptionsBuilder <BitcoinShowDBContext>()
                          .UseInMemoryDatabase(System.Guid.NewGuid().ToString())
                          .Options;
            var context = new BitcoinShowDBContext(options);

            context.Options.Add(new Option {
                Text = "New option"
            });
            context.SaveChanges();

            OptionRepository repository = new OptionRepository(context);

            Option updatedOption = new Option();

            updatedOption.Id = 1;

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => repository.Update(updatedOption));

            Assert.NotNull(ex);
            Assert.Equal(nameof(updatedOption.Text), ex.ParamName);
        }
Exemplo n.º 4
0
        public IActionResult Edit(OptionViewModel vm)
        {
            var result = _optionRepository.Update(vm);

            return(RedirectToAction("Edit", new { id = result.Data }));
        }
 public async Task <Option> Update(Option entity)
 {
     return(await _optionRepository.Update(entity));
 }