Exemplo n.º 1
0
        public SupportGroupTest()
        {
            _context = GetDbContext();

            _context.Add(new SupportGroup
            {
                Name        = FIND,
                Description = CREATE_DESCRIPTION
            });

            _context.SaveChanges();

            _context.Add(new SupportGroup
            {
                Name = UPDATE
            });

            _context.SaveChanges();

            _context.Add(new SupportGroup
            {
                Name = DELETE
            });

            _context.SaveChanges();
        }
Exemplo n.º 2
0
        public UpdateWorkshopTypeCommandValidator(ParentEspoirDbContext context)
        {
            RuleFor(y => y)
            .Must(n => (context.WorkshopTypes.SingleOrDefault(e => e.Id == n.Id && e.Name == n.Name) != null) ||
                  string.IsNullOrWhiteSpace(n.Name) == false &&
                  context.WorkshopTypes
                  .Where(a => a.IsDelete == false)
                  .Any(w => n.Name.ToUpper().Trim() == w.Name.ToUpper().Trim())
                  == false).WithMessage("Le nom existe déjà").OverridePropertyName("Name");

            RuleFor(a => a.Name)
            .NotEmpty()
            .WithMessage("Le nom est requis");

            RuleFor(a => a.Name)
            .MaximumLength(WorkshopTypeConstant.NAME_MAX_LENGHT)
            .WithMessage($"Le nom doit contenir moins de {WorkshopTypeConstant.NAME_MAX_LENGHT} caractères");

            RuleFor(a => a.Code)
            .NotEmpty()
            .WithMessage("Le code est requis");

            RuleFor(a => a.Code)
            .MaximumLength(WorkshopTypeConstant.CODE_MAX_LENGHT)
            .WithMessage($"Le nom doit contenir moins de {WorkshopTypeConstant.CODE_MAX_LENGHT} caractères");
        }
Exemplo n.º 3
0
        public UpdateSeanceCommandValidator(ParentEspoirDbContext context)
        {
            RuleFor(s => s.WorkshopId)
            .Must(id => context.Workshops.Find(id) != null)
            .WithMessage(ValidationConstants.REQUIRED_FIELD_MESSAGE);

            When(x => (context.Workshops.Find(x.WorkshopId) != null), () =>
            {
                RuleFor(s => s.SeanceName)
                .Must(sn => !string.IsNullOrWhiteSpace(sn))
                .WithMessage(ValidationConstants.REQUIRED_FIELD_MESSAGE);

                RuleFor(s => s.SeanceDate)
                .Must(sd => sd != null)
                .WithMessage(ValidationConstants.REQUIRED_FIELD_MESSAGE);

                RuleFor(s => new { s.SeanceDate, workshop = context.Workshops.Find(s.WorkshopId) })
                .Must(x => x.SeanceDate == null || (x.SeanceDate >= x.workshop.StartDate && x.SeanceDate <= x.workshop.EndDate))
                .WithMessage($@"La date de la séance doit être comprise entre les dates de l'atelier")
                .OverridePropertyName("SeanceDate");

                RuleFor(s => s.SeanceTimeSpan)
                .Must(st => st != null)
                .WithMessage(ValidationConstants.REQUIRED_FIELD_MESSAGE);

                RuleFor(s => s.SeanceDescription)
                .Must(sd => !string.IsNullOrWhiteSpace(sd))
                .WithMessage(ValidationConstants.REQUIRED_FIELD_MESSAGE);
            });
        }
Exemplo n.º 4
0
        public CreateWorkshopTypeCommandValidator(ParentEspoirDbContext context)
        {
            RuleFor(a => a.Name)
            .NotEmpty()
            .WithMessage("Le nom est requis");

            RuleFor(a => a.Name)
            .MaximumLength(WorkshopTypeConstant.NAME_MAX_LENGHT)
            .WithMessage($"Le nom doit contenir moins de {WorkshopTypeConstant.NAME_MAX_LENGHT} caractères");

            RuleFor(a => a.Name)
            .Must(n => string.IsNullOrWhiteSpace(n) == false &&
                  context.WorkshopTypes
                  .Where(c => c.IsDelete == false)
                  .Any(c => n.ToUpper().Trim() == c.Name.ToUpper().Trim())
                  == false).WithMessage("Le nom existe déjà");

            RuleFor(a => a.Code)
            .NotEmpty()
            .WithMessage("Le code est requis");

            RuleFor(a => a.Code)
            .MaximumLength(WorkshopTypeConstant.CODE_MAX_LENGHT)
            .WithMessage($"Le nom doit contenir moins de {WorkshopTypeConstant.CODE_MAX_LENGHT} caractères");
        }
Exemplo n.º 5
0
        public DeleteSkillToDevelopCommandValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(s => s.Id)
            .Must(id => !IsLinked(id).Result)
            .WithMessage(DeleteProfilOptionCommand <SkillToDevelop> .IS_LINKED_ERROR_MESSAGE);
        }
Exemplo n.º 6
0
        public DeleteVolonteeringTypeValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(v => v.Id)
            .Must(id => !IsLinked(id).Result)
            .WithMessage(DeleteProfilOptionCommand <VolunteeringType> .IS_LINKED_ERROR_MESSAGE);
        }
Exemplo n.º 7
0
        public DeleteYearlyIncomeValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(y => y.Id)
            .Must(id => !IsLinked(id).Result)
            .WithMessage(DeleteProfilOptionCommand <YearlyIncome> .IS_LINKED_ERROR_MESSAGE);
        }
Exemplo n.º 8
0
 public DeleteWorkshopTypeCommandValidation(ParentEspoirDbContext context)
 {
     RuleFor(d => d.Id)
     .Must(id => context.WorkshopTypes.Find(id) != null &&
           context.WorkshopTypes.Include(w => w.Workshops).Single(w => w.Id == id)
           .Workshops.Where(w => w.IsDelete == false).Any() == false)
     .WithMessage("Impossible de supprimer un volet relier à des ateliers");
 }
        public DeleteIncomeSourceCommandValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(i => i.Id)
            .Must(id => !IsLinked(id).Result)
            .WithMessage(DeleteProfilOptionCommand <IncomeSource> .IS_LINKED_ERROR_MESSAGE);
        }
Exemplo n.º 10
0
        public DeleteAvailabilityValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(d => d.Id)
            .Must(id => !IsLinked(id).Result)
            .WithMessage(DeleteProfilOptionCommand <Availability> .IS_LINKED_ERROR_MESSAGE);
        }
        public DeleteHomeTypeCommandValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(h => h.Id)
            .Must(id => IsLinked(id).Result == false)
            .WithMessage(DeleteProfilOptionCommand <HomeType> .IS_LINKED_ERROR_MESSAGE);
        }
        public DeleteMaritalStatusCommandValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(m => m.Id)
            .Must(id => !IsLinked(id).Result)
            .WithMessage(DeleteProfilOptionCommand <MaritalStatus> .IS_LINKED_ERROR_MESSAGE);
        }
Exemplo n.º 13
0
        public DeleteTransportTypeCommandValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(t => t.Id)
            .Must(id => !IsLinked(id).Result)
            .WithMessage(DeleteProfilOptionCommand <TransportType> .IS_LINKED_ERROR_MESSAGE);
        }
Exemplo n.º 14
0
        public DeleteLegalCustodyValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(l => l.Id)
            .Must(id => !IsLinked(id).Result)
            .WithMessage(DeleteProfilOptionCommand <LegalCustody> .IS_LINKED_ERROR_MESSAGE);
        }
Exemplo n.º 15
0
 public DeleteWorkshopCommandValidator(ParentEspoirDbContext context)
 {
     RuleFor(w => w.WorkshopId)
     .Must(id => context.Workshops.Find(id) != null &&
           context.Workshops.Include(w => w.Seances)
           .Where(w => w.WorkshopId == id).Single()
           .Seances.Where(s => s.IsDelete == false).Any() == false)
     .WithMessage("Impossible de supprimer un atelier possédant des séances");
 }
Exemplo n.º 16
0
        public DeleteCitizenStatusCommandValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(d => d.Id)
            .Must(id => IsLinked(id).Result == false)
            .WithMessage(DeleteProfilOptionCommand <CitizenStatus> .IS_LINKED_ERROR_MESSAGE)
            .OverridePropertyName("Name");
        }
Exemplo n.º 17
0
        public DeleteChildrenAgeBracketCommandValidator(ParentEspoirDbContext context)
        {
            _context = context;

            RuleFor(c => c.Id)
            .Must(id => !IsLinked(id).Result)
            .WithMessage(DeleteProfilOptionCommand <ChildrenAgeBracket> .IS_LINKED_ERROR_MESSAGE)
            .OverridePropertyName("Name");
        }
        public CreateCustomerModelValidator(ParentEspoirDbContext context)
        {
            RuleFor(c => c.Model.Id).Must(x => x == null);

            RuleFor(c => c.Model.FirstName).NotNull().WithMessage(REQUIRED_ERROR_MESSAGE);
            RuleFor(c => c.Model.LastName).NotNull().WithMessage(REQUIRED_ERROR_MESSAGE);
            RuleFor(c => c.Model.DateOfBirth).NotNull().WithMessage(REQUIRED_ERROR_MESSAGE);
            RuleFor(c => c.Model.CityName).NotNull().WithMessage(REQUIRED_ERROR_MESSAGE);
            RuleFor(c => c.Model.Address).NotNull().WithMessage(REQUIRED_ERROR_MESSAGE);
            RuleFor(c => c.Model.PostalCodeName).NotNull().WithMessage(REQUIRED_ERROR_MESSAGE);
            RuleFor(c => c.Model.ProvinceName).NotNull().WithMessage(REQUIRED_ERROR_MESSAGE);
            RuleFor(c => c.Model.CountryName).NotNull().WithMessage(REQUIRED_ERROR_MESSAGE);
            RuleFor(c => c.Model.Phone).NotNull().WithMessage(REQUIRED_ERROR_MESSAGE);
            RuleFor(c => c.Model.SecondaryPhone).NotNull().WithMessage(REQUIRED_ERROR_MESSAGE);

            RuleFor(c => c.Model.FirstName).Matches(new Regex(NAME_VALIDATION_REGEX)).WithMessage(NAME_ERROR_MESSAGE);

            RuleFor(c => c.Model.FirstName).Must(x => IsNotNullOrWhiteSpace(x) && x.Length <= CustomerConstant.FIRST_NAME_MAX_LENGHT)
            .WithMessage(CustomerConstant.ERROR_MESSAGE_FIRST_NAME);

            RuleFor(c => c.Model.LastName).Matches(new Regex(NAME_VALIDATION_REGEX)).WithMessage(NAME_ERROR_MESSAGE);

            RuleFor(c => c.Model.LastName).Must(x => IsNotNullOrWhiteSpace(x) && x.Length <= CustomerConstant.LAST_NAME_MAX_LENGHT)
            .WithMessage(CustomerConstant.ERROR_MESSAGE_LAST_NAME);

            RuleFor(c => c.Model.DateOfBirth).Must(x => x >= new DateTime(1900, 01, 01))
            .WithMessage(CustomerConstant.ERROR_MESSAGE_DATEOFBIRTH_AFTER_1900);
            RuleFor(c => c.Model.DateOfBirth).Must(x => x <= DateTime.Now)
            .WithMessage(CustomerConstant.ERROR_MESSAGE_DATEOFBIRTH_BEFORE_NOW);

            RuleFor(c => c.Model.Address).Must(x => IsNotNullOrWhiteSpace(x) && x.Length <= CustomerConstant.ADDRESS_MAX_LENGHT)
            .WithMessage(CustomerConstant.ERROR_MESSAGE_ADDRESS);

            RuleFor(c => c.Model.CityName).Must(x => IsNotNullOrWhiteSpace(x) && x.Length <= CustomerConstant.CITY_MAX_LENGHT)
            .WithMessage(CustomerConstant.ERROR_MESSAGE_CITY);

            RuleFor(c => c.Model.PostalCodeName).Must(x => x == null || (IsNotNullOrWhiteSpace(x) && x.Length <= CustomerConstant.POSTAL_CODE_MAX_LENGHT))
            .WithMessage(CustomerConstant.ERROR_MESSAGE_POSTAL_CODE);

            RuleFor(c => c.Model.ProvinceName).Must(x => IsNotNullOrWhiteSpace(x) && x.Length <= CustomerConstant.PROVINCE_MAX_LENGHT)
            .WithMessage(CustomerConstant.ERROR_MESSAGE_PROVINCE);

            RuleFor(c => c.Model.CountryName).Must(x => IsNotNullOrWhiteSpace(x) && x.Length <= CustomerConstant.COUNTRY_MAX_LENGHT)
            .WithMessage(CustomerConstant.ERROR_MESSAGE_COUNTRY);

            RuleFor(c => c.Model.Phone).Must(x => IsNotNullOrWhiteSpace(x) && x.Length <= CustomerConstant.PHONE_MAX_LENGHT)
            .WithMessage(CustomerConstant.ERROR_MESSAGE_PHONE);

            RuleFor(c => c.Model.SecondaryPhone).Must(x => x == null || (IsNotNullOrWhiteSpace(x) && x.Length <= CustomerConstant.SECONDARY_PHONE_MAX_LENGHT))
            .WithMessage(CustomerConstant.ERROR_MESSAGE_SECONDARY_PHONE);

            RuleFor(c => c.Model.SupportGroupId).Must(x => x == null || (context.SupportGroups.Where(sp => sp.SupportGroupId == x && sp.IsDelete == false).Any()));
            RuleFor(c => c.Model.ReferenceById).Must(x => x == null || (context.ReferenceTypes.Where(rt => rt.Id == x && rt.IsDelete == false).Any()));
            RuleFor(c => c.Model.HeardOfUsFromId).Must(x => x == null || (context.HeardOfUsFroms.Where(hf => hf.Id == x && hf.IsDelete == false).Any()));
        }
        public ProfilOptionTestBase()
        {
            _context = GetDbContext();

            _context.Add(InstanciateEntity(FIND));
            _context.Add(InstanciateEntity(UPDATE));
            _context.Add(InstanciateEntity(DELETE));
            _context.Add(InstanciateEntity("Deleted", true));

            _context.SaveChanges();
        }
        public async Task Handle(ParentEspoirDbContext context, CancellationToken cancelationToken)
        {
            var option = await context.Set <TProfilOption>().FindAsync(Id);

            if (option != null)
            {
                option.IsDelete = true;

                await context.SaveChangesAsync(cancelationToken);
            }
        }
Exemplo n.º 21
0
        public DeleteSessionValidator(ParentEspoirDbContext context)
        {
            RuleFor(s => s.SessionId)
            .Must(id => context.Sessions.Find(id) != null)
            .WithMessage("La session n'existe pas");

            RuleFor(s => s.SessionId)
            .Must(id => context.Workshops
                  .Any(w => w.SessionId == id && w.IsDelete == false) == false)
            .WithMessage("La session possède des ateliers et ne peut pas être supprimée");
        }
        public CreateCitizenStatusCommandValidator(ParentEspoirDbContext context)
        {
            RuleFor(c => c.Name)
            .NotEmpty()
            .WithMessage("Le nom ne peut pas être vide");

            RuleFor(c => c.Name)
            .Must(n => string.IsNullOrWhiteSpace(n) == false &&
                  context.Set <CitizenStatus>().Where(vt => vt.IsDelete == false)
                  .Any(c => StringNormalizer.Normalize(c.Name) == StringNormalizer.Normalize(n)) == false)
            .WithMessage("Cette option existe déjà");
        }
        public CreateDocumentTypeCommandValidator(ParentEspoirDbContext context)
        {
            RuleFor(c => c.Name)
            .NotEmpty()
            .WithMessage("Le nom ne peut pas être vide");

            RuleFor(d => d.Name)
            .Must(n => string.IsNullOrWhiteSpace(n) == false &&
                  context.DocumentTypes.Where(dt => dt.IsDelete == false)
                  .Any(d => StringNormalizer.Normalize(d.Name) == StringNormalizer.Normalize(n)) == false)
            .WithMessage("Cette option existe déjà");
        }
Exemplo n.º 24
0
 public RequestLogBehaviour(
     ParentEspoirDbContext context,
     UserManager <AppUser> userManager,
     IHttpContextAccessor httpContext,
     IMemoryCache memoryCache)
 {
     _timer       = new Stopwatch();
     _context     = context;
     _userManager = userManager;
     _httpContext = httpContext;
     _cache       = memoryCache;
 }
Exemplo n.º 25
0
        public UpdateVolunteeringTypeCommandValidator(ParentEspoirDbContext context)
        {
            RuleFor(a => a.Name)
            .NotEmpty()
            .WithMessage("Le nom ne peut pas être vide");

            RuleFor(v => v)
            .Must(v => Normalize(context.VolunteeringTypes.Find(v.Id).Name) == Normalize(v.Name) ||
                  context.VolunteeringTypes.Where(vt => vt.IsDelete == false)
                  .Any(vv => Normalize(vv.Name) == Normalize(v.Name)) == false)
            .WithMessage("Cette option existe déjà").OverridePropertyName("Name");;
        }
Exemplo n.º 26
0
        public UpdateSessionCommandValidator(ParentEspoirDbContext context)
        {
            RuleFor(s => s.SessionId).Must(i => context.Sessions.Find(i) != null);

            RuleFor(s => s.Season).NotNull().WithMessage("Le champs est requis");
            RuleFor(s => s.Year).NotNull().WithMessage("Le champs est requis");

            RuleFor(s => s).Must(s => context.Sessions
                                 .Any(dbsession => dbsession.IsDelete == false && s.Season == dbsession.Season && s.Year == dbsession.Year && dbsession.SessionId != s.SessionId) == false);

            RuleFor(s => s.Season).Must(s => s.HasValue);
            RuleFor(s => s.Year).Must(s => s.HasValue);
        }
Exemplo n.º 27
0
        public DeleteSeanceCommandValidator(ParentEspoirDbContext context)
        {
            RuleFor(w => w.WorkshopId)
            .Must(id => context.Workshops.Find(id) != null)
            .WithMessage("L'atelier sélectionné est invalide.");

            RuleFor(s => s.SeanceId)
            .Must(id => context.Seances.Find(id) != null &&
                  context.Participants
                  .Where(p => p.SeanceId == id && p.IsDelete == false)
                  .Any() == false)
            .WithMessage("Impossible de supprimer une séance possédant des participants");
        }
Exemplo n.º 28
0
        public CreateTransportTypeCommandValidator(ParentEspoirDbContext context)
        {
            RuleFor(c => c.Name)
            .NotEmpty()
            .WithMessage("Le nom ne peut pas être vide");

            RuleFor(a => a.Name)
            .Must(n => string.IsNullOrWhiteSpace(n) == false &&
                  context.TransportTypes
                  .Where(a => a.IsDelete == false)
                  .Any(acontext => n.ToUpper().Trim() == acontext.Name.ToUpper().Trim())
                  == false).WithMessage("Cette option existe déjà");
        }
Exemplo n.º 29
0
        public YearlyIncomeTest() : base()
        {
            _context = GetDbContext();

            var customer = _context.Add(new Customer
            {
                CustomerDescription = new CustomerDescription()
            }).Entity;

            customer.CustomerActivations.Add(new CustomerActivation());

            _context.SaveChanges();
        }
        public async Task <List <TProfilOption> > Handle(IMemoryCache memory, ParentEspoirDbContext context)
        {
            string optionName = $"{typeof(TProfilOption).Name}List";

            if (!memory.TryGetValue($"{optionName}", out List <TProfilOption> options))
            {
                options = await context.Set <TProfilOption>().Where(t => t.IsDelete == false).ToListAsync();

                memory.CreateEntry(optionName);
                memory.Set(optionName, options);
            }

            return(options);
        }