public CreatePlantCommandValidator(PlantLogBookContext dbContext) { RuleFor(p => p.Id).NotEmpty(); RuleFor(p => p.PlantSpeciesId) .Must(plantSpeciesId => dbContext.PlantSpecies.Any(ps => ps.Id.Equals(plantSpeciesId))) .WithMessage("Plant species does not exist"); RuleFor(p => p.Name).NotEmpty(); }
public DeletePlantLogForPlantCommandValidator(PlantLogBookContext context) { RuleFor(x => x.Id) .Must(id => context.PlantLogs.Any(pl => pl.Id.Equals(id))) .WithMessage("Plant Log does not exist"); RuleFor(x => x.PlantId) .Must((log, plantId) => context.PlantLogs.Any(pl => pl.Id.Equals(log.Id) && pl.PlantId.Equals(plantId))) .WithMessage("Plant Log does not exist"); }
public CreatePlantLogForPlantCommandValidator(PlantLogBookContext context) { RuleFor(x => x.Id).NotEmpty(); RuleFor(x => x.PlantLogTypeId) .Must(logTypeId => context.PlantLogTypes.Any(lt => lt.Id.Equals(logTypeId))) .WithMessage("Plant log type does not exist"); RuleFor(x => x.PlantId) .Must(plantId => context.Plants.Any(p => p.Id.Equals(plantId))) .WithMessage("Plant does not exist"); }
public UpdatePlantLogCommandValidator(PlantLogBookContext context) { RuleFor(x => x.Id) .Must(id => context.PlantLogs.Any(pl => pl.Id.Equals(id))); RuleFor(x => x.PlantId) .Must(plantId => context.Plants.Any(p => p.Id.Equals(plantId))) .WithMessage("Plant does not exist"); RuleFor(x => x.PlantLogTypeId) .Must(logTypeId => context.PlantLogTypes.Any(lt => lt.Id.Equals(logTypeId))) .WithMessage("Plant log type does not exist"); }
public PlantLogQueryTestsFixture() { context = DatabaseHelper.CreateInMemoryDatabaseContext(nameof(PlantLogQueryTests)); logType1 = ValidObjectHelper.ValidPlantLogType(); logType2 = ValidObjectHelper.ValidPlantLogType(); plantSpecies = ValidObjectHelper.ValidPlantSpecies(); plant1 = ValidObjectHelper.ValidPlant(plantSpecies); plant2 = ValidObjectHelper.ValidPlant(plantSpecies); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var id3 = Guid.NewGuid(); var id4 = Guid.NewGuid(); var id5 = Guid.NewGuid(); var log1 = "Hello"; var log2 = "World"; var log3 = "ab"; var log4 = "world Hello abcdefgh"; var log5 = "Töster"; var dt1 = new DateTime(2020, 01, 01, 00, 00, 00); var dt2 = new DateTime(2020, 01, 01, 18, 00, 00); var dt3 = new DateTime(2020, 01, 02, 12, 00, 00); var dt4 = new DateTime(2020, 02, 01, 12, 00, 00); var dt5 = new DateTime(2019, 01, 01, 12, 00, 00); plantLog1 = new PlantLog { Id = id1, DateTime = dt1, Log = log1, Plant = plant1, PlantLogType = logType1 }; plantLog2 = new PlantLog { Id = id2, DateTime = dt2, Log = log2, Plant = plant1, PlantLogType = logType1 }; plantLog3 = new PlantLog { Id = id3, DateTime = dt3, Log = log3, Plant = plant2, PlantLogType = logType2 }; plantLog4 = new PlantLog { Id = id4, DateTime = dt4, Log = log4, Plant = plant2, PlantLogType = logType2 }; plantLog5 = new PlantLog { Id = id5, DateTime = dt5, Log = log5, Plant = plant2, PlantLogType = logType1 }; context.AddRange(logType1, logType2, plantSpecies, plant1, plant2, plantLog1, plantLog2, plantLog3, plantLog4, plantLog5); context.SaveChanges(); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, PlantLogBookContext dbContext) { dbContext.Database.Migrate(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); SwaggerSetup.ConfigureApplication(app); app.UseCors("AllowAll"); } app.UseHttpsRedirection(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public GetAllPlantLogTypesQueryHandler(PlantLogBookContext dbContext) { this.dbContext = dbContext; }
public UpdatePlantCommandHandler(PlantLogBookContext dbContext) { this.dbContext = dbContext; }
public DeletePlantLogTypeCommandHandler(PlantLogBookContext dbContext) { this.dbContext = dbContext; }
public GetPlantLogTypeByIdQueryHandler(PlantLogBookContext dbContext) { this.dbContext = dbContext; }
public GetPlantLogForPlantByIdQueryHandler(PlantLogBookContext context) { this.context = context; }
public CreatePlantSpeciesCommandHandler(PlantLogBookContext dbContext) { this.dbContext = dbContext; }
public DeletePlantLogCommandValidator(PlantLogBookContext context) { RuleFor(x => x.Id) .Must(id => context.PlantLogs.Any(pl => pl.Id.Equals(id))); }
public CreatePlantLogForPlantCommandHandler(PlantLogBookContext context) { this.context = context; }