public async Task AddAndSaveTest() { 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 author3 = new Authors() { Author_id = "3", Author_name = "test author 3" }; var fakeRepositoryMock = new Mock <IAuthorsRepository>(); fakeRepositoryMock.Setup(x => x.Add(It.IsAny <Authors>())).Callback <Authors>(arg => authors.Add(arg)); var coachService = new AuthorsService(fakeRepositoryMock.Object); await coachService.AddAndSave(author3); Assert.Equal(3, authors.Count); }
public async Task <IActionResult> Create([Bind("Author_id,Author_name")] Authors author) { if (ModelState.IsValid) { await _context.AddAndSave(author); return(RedirectToAction(nameof(Index))); } return(View(author)); }