public void GetAllShouldReturnCorrectNumberOfPages() { var options = new DbContextOptionsBuilder <FlowersDbContext>() .UseInMemoryDatabase(databaseName: nameof(GetAllShouldReturnCorrectNumberOfPages)) .Options; using (var context = new FlowersDbContext(options)) { var commentService = new CommentService(context); var flowerService = new FlowerService(context); var addedFlower = flowerService.Create(new curs_2_webapi.ViewModels.FlowerPostModel { Colors = "fdsfsd", DatePicked = new DateTime(), Comments = new List <Comment>() { new Comment { Important = true, Text = "asd", Owner = null } }, FlowerSize = "large", Name = "fdsfds", IsArtificial = false, SmellLevel = 2 }, null); var allComments = commentService.GetAll(1, string.Empty); Assert.AreEqual(1, allComments.NumberOfPages); } }
// read more: https://www.carlrippon.com/fluentvalidation-in-an-asp-net-core-web-api/ public FlowerValidator(FlowersDbContext context) { RuleFor(x => x.MarketPrice) .InclusiveBetween(5, context.Flowers.Select(f => f.MarketPrice).Max()); RuleFor(x => x.DateAdded) .LessThan(DateTime.Now); RuleFor(x => x.FlowerUpkeepDifficulty) .Equal(FlowerUpkeepDifficulty.Easy) .When(x => x.MarketPrice >= 5 && x.MarketPrice <= 10); }
// read more: https://www.carlrippon.com/fluentvalidation-in-an-asp-net-core-web-api/ public FlowerValidator(FlowersDbContext context) { //RuleFor(x => x.MarketPrice).InclusiveBetween(5, 1000); RuleFor(x => x.MarketPrice).InclusiveBetween(5, context.Flowers.Select(f => f.MarketPrice).Max()); RuleFor(x => x.DateAdded).LessThan(DateTime.Now); RuleFor(x => x.FlowerUpkeepDificulty) .Equal(Models.FlowerUpkeepDifficulty.Easy) .When(x => x.MarketPrice >= 5 && x.MarketPrice <= 10); //RuleFor(x => x.Id).Must(x => //{ // return true; //}); // RuleForEach(); ValidationResult pentru mai multe chestii }
public void ValidRegisterShouldCreateANewUser() { var options = new DbContextOptionsBuilder <FlowersDbContext>() .UseInMemoryDatabase(databaseName: nameof(ValidRegisterShouldCreateANewUser))// "ValidRegisterShouldCreateANewUser") .Options; using (var context = new FlowersDbContext(options)) { var usersService = new UsersService(context, config); var added = new curs_2_webapi.ViewModels.RegisterPostModel { Email = "[email protected]", FirstName = "fdsfsdfs", LastName = "fdsfs", Password = "******", Username = "******" }; var result = usersService.Register(added); Assert.IsNotNull(result); Assert.AreEqual(added.Username, result.Username); } }
public UsersService(FlowersDbContext context, IOptions <AppSettings> appSettings) { this.context = context; this.appSettings = appSettings.Value; }
public FlowerService(FlowersDbContext context) { this.context = context; }
public FlowersController(FlowersDbContext context) { _context = context; }
protected BaseApiController() { DbContext = new FlowersDbContext(); }
public CommentService(FlowersDbContext context) { this.context = context; }