public async Task <IActionResult> Edit(int id, [Bind("Id,Url,Login,Password")] UrlCheckTask urlCheckTask)
        {
            if (id != urlCheckTask.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(urlCheckTask);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UrlCheckTaskExists(urlCheckTask.Id))
                    {
                        return(NotFound());
                    }

                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(urlCheckTask));
        }
Example #2
0
        public void Test_UrlCheckTask_UrlMustBeUnique()
        {
            var options   = new DbContextOptionsBuilder <SiteCheckerDbContext>().UseInMemoryDatabase("Test_UrlCheckTask_UrlMustBeUnique").Options;
            var dataStore = new DbContextDataStore(new SiteCheckerDbContext(options));

            Assert.Equal(0, dataStore.GetAll <UrlCheckTask>().Count());

            var newTask = new UrlCheckTask {
                Url = "123"
            };

            dataStore.Add(newTask);
            dataStore.SaveChanges();

            Assert.Throws <InvalidOperationException>(() =>
            {
                dataStore.Add(new UrlCheckTask {
                    Url = "123"
                });
                dataStore.SaveChanges();
            });

            dataStore.Add(new UrlCheckTask {
                Url = "234"
            });
            dataStore.SaveChanges();
        }
        public async Task <IActionResult> Create([Bind("Url,Login,Password")] UrlCheckTask urlCheckTask)
        {
            if (ModelState.IsValid)
            {
                _context.Add(urlCheckTask);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(urlCheckTask));
        }
Example #4
0
        public void Test_UrlCheckTask_UrlMustNotBeEmpty()
        {
            var options   = new DbContextOptionsBuilder <SiteCheckerDbContext>().UseInMemoryDatabase("Test_UrlCheckTask_UrlMustNotBeEmpty").Options;
            var dataStore = new DbContextDataStore(new SiteCheckerDbContext(options));

            var emptyUrlCheckTask = new UrlCheckTask();

            Assert.Throws <InvalidOperationException>(() =>
            {
                dataStore.Add(emptyUrlCheckTask);
                dataStore.SaveChanges();
            });

            dataStore.Add(new UrlCheckTask {
                Url = "http:/123/"
            });
            dataStore.SaveChanges();
        }