Пример #1
0
    public async Task UpdateAndSaveTest()
    {
        var author1 = new Authors()
        {
            Author_id = "1", Author_name = "test author 1"
        };
        var author2 = new Authors()
        {
            Author_id = "2", Author_name = "test author 2"
        };
        var authors = new List <Authors> {
            author1, author2
        };

        var newAuthor2 = new Authors()
        {
            Author_id = "2", Author_name = "new test author 2"
        };

        var fakeRepositoryMock = new Mock <IAuthorsRepository>();

        fakeRepositoryMock.Setup(x => x.Update(It.IsAny <Authors>())).Callback <Authors>(arg => authors[1] = arg);

        var coachService = new AuthorsService(fakeRepositoryMock.Object);

        await coachService.UpdateAndSave(newAuthor2);

        Assert.Equal("new test author 2", authors[1].Author_name);
    }
Пример #2
0
        public async Task <IActionResult> Update(string id, [Bind("Author_id,Aithor_name")] Authors author)
        {
            if (id != author.Author_id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _context.UpdateAndSave(author);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_context.CoachExists(author.Author_id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }


            return(View(author));
        }