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 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 void AddsMovie() { var db = CreateDb(); var page = new EditModel(new SqlMovieData(db)); page.Movie = new Movie() { Id = 0, Name = "TestMovie1", Year = 2000 }; var result = page.OnPost(0) as RedirectToPageResult; }
public void RejectsBadModel() { var db = CreateDb(); var page = new EditModel(new SqlMovieData(db)); page.ModelState.AddModelError("Name", "Name is empty"); page.Movie = new Movie(); var result = page.OnPost(3) as PageResult; Assert.NotNull(result); }