Exemple #1
0
        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);
            }
        }
Exemple #2
0
 // 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;
 }
Exemple #6
0
 public FlowerService(FlowersDbContext context)
 {
     this.context = context;
 }
Exemple #7
0
 public FlowersController(FlowersDbContext context)
 {
     _context = context;
 }
 protected BaseApiController()
 {
     DbContext = new FlowersDbContext();
 }
Exemple #9
0
 public CommentService(FlowersDbContext context)
 {
     this.context = context;
 }