Пример #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);
            }
        }
Пример #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
 }
Пример #4
0
        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);
            }
        }
Пример #5
0
 public UsersService(FlowersDbContext context, IOptions <AppSettings> appSettings)
 {
     this.context     = context;
     this.appSettings = appSettings.Value;
 }
Пример #6
0
 public FlowerService(FlowersDbContext context)
 {
     this.context = context;
 }
Пример #7
0
 public FlowersController(FlowersDbContext context)
 {
     _context = context;
 }
Пример #8
0
 protected BaseApiController()
 {
     DbContext = new FlowersDbContext();
 }
Пример #9
0
 public CommentService(FlowersDbContext context)
 {
     this.context = context;
 }