public void ValidateOk() { //SETUP var userId = Guid.NewGuid(); var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using var context = new EfCoreContext(options, new FakeUserIdService(userId)); context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); context.ChangeTracker.Clear(); //ATTEMPT var order = new Order { CustomerId = userId, LineItems = new List <LineItem> { new LineItem { BookId = context.Books.First().BookId, LineNum = 1, BookPrice = 123, NumBooks = 1 } } }; context.Orders.Add(order); var errors = context.SaveChangesWithValidation(); //VERIFY errors.Any().ShouldBeFalse(); context.Orders.Count().ShouldEqual(1); }
public void ValidateLineNumNotSetBad() { //SETUP var userId = Guid.NewGuid(); var options = SqliteInMemory.CreateOptions <EfCoreContext>(); using var context = new EfCoreContext(options, new FakeUserIdService(userId)); context.Database.EnsureCreated(); context.SeedDatabaseFourBooks(); //ATTEMPT var order = new Order { CustomerId = userId, LineItems = new List <LineItem> { new LineItem { BookId = context.Books.First().BookId, LineNum = 20, BookPrice = 123, NumBooks = 1 } } }; context.Orders.Add(order); var errors = context.SaveChangesWithValidation(); //VERIFY errors.Count.ShouldEqual(1); errors.First().ErrorMessage.ShouldEqual("This order is over the limit of 5 books."); context.Orders.Count().ShouldEqual(0); }
public bool HasErrors => Errors.Any(); //#A public TOut RunAction(TIn dataIn) //#C { var result = _actionClass.Action(dataIn); //#D Errors = _actionClass.Errors; //#E if (!HasErrors) //#F { Errors = //#G _context.SaveChangesWithValidation() //#G .ToImmutableList(); //#G } return(result); //#H }