public async void Edit_OnGet_EditBookEntryIfValid() { // Arrange var builder = new DbContextOptionsBuilder<ApplicationDbContext>().UseInMemoryDatabase(databaseName: "InMemoryDb_Edit"); var context = new ApplicationDbContext(builder.Options); Seed(context); // Act var editPage = new EditModel(context); editPage.OnGet(2); editPage.Book.Author = "Test2"; editPage.Book.ISBN = "Test2"; editPage.Book.Name = "Test2"; await editPage.OnPost(); var books = await context.Books.ToListAsync(); // Assert Assert.Equal(editPage.Book, books[1]); Assert.Matches(books[1].Name, "Test2"); Assert.Matches(books[1].ISBN, "Test2"); Assert.Matches(books[1].Author, "Test2"); Assert.Matches(editPage.Message, "Book has been updated successfully"); await Teardown(context); }
public async void Edit_OnGet_DoNotEditBookEntryIfInvalid() { // Arrange var builder = new DbContextOptionsBuilder<ApplicationDbContext>().UseInMemoryDatabase(databaseName: "InMemoryDb_Edit"); var context = new ApplicationDbContext(builder.Options); Seed(context); // Act var editPage = new EditModel(context); editPage.OnGet(2); editPage.Book = new Book() { Id = 2, Author = "moo", ISBN = "baa", Name = null }; editPage.ModelState.AddModelError("", "err"); await editPage.OnPost(); var books = await context.Books.ToListAsync(); Assert.Matches(books[1].Name, "Name2"); Assert.NotNull(books[1].Name); await Teardown(context); }
public void FindsMovieToEdit() { var db = CreateDb(); var movie = new Movie { Id = 99, Name = "Test 1", Year = 2019 }; db.Movies.Add(movie); var page = new EditModel(new SqlMovieData(db)); page.OnGet(99); Assert.Equal(movie.Id, page.Movie.Id); }
public async void Edit_OnGet_SetBookUsingId() { // Arrange var builder = new DbContextOptionsBuilder<ApplicationDbContext>().UseInMemoryDatabase(databaseName: "InMemoryDb_Edit"); builder.EnableSensitiveDataLogging(true); var mockDbContext = new ApplicationDbContext(builder.Options); Seed(mockDbContext); // Act var editPage = new EditModel(mockDbContext); editPage.OnGet(2); // Asssert var assignedBook = Assert.IsAssignableFrom<Book>(editPage.Book); Assert.Matches("moo2", assignedBook.ISBN); Assert.Matches("Author2", assignedBook.Author); Assert.Matches("Name2", assignedBook.Name); Assert.Null(editPage.Message); // Teardown await Teardown(mockDbContext); }