public static PlantLog ValidPlantLog(Plant plant, PlantLogType plantLogType) { var log = $"{NameList.FirstNames[rnd.Next(NameList.FirstNames.Length)]}: {LoremIpsum.Words(25)}"; return(new PlantLog { Id = Guid.NewGuid(), PlantId = plant.Id, DateTime = DateTime.Now, Log = log, PlantLogTypeId = plantLogType.Id }); }
public async Task <ActionResult <PlantLogType> > Get(Guid plantLogTypeId) { var query = new GetPlantLogTypeByIdQuery { Id = plantLogTypeId }; var response = await mediator.Send(query); if (!response.Success) { return(BadRequest(response.ErrorMessages)); } return(Ok(PlantLogType.FromCore(response.Data))); }
public PlantLogQueryTests(PlantLogQueryTestsFixture fixture) { logType1 = fixture.logType1; logType2 = fixture.logType2; plantSpecies = fixture.plantSpecies; plant1 = fixture.plant1; plant2 = fixture.plant2; plantLog1 = fixture.plantLog1; plantLog2 = fixture.plantLog2; plantLog3 = fixture.plantLog3; plantLog4 = fixture.plantLog4; plantLog5 = fixture.plantLog5; queryHandler = new GetAllPlantLogsQueryHandler(fixture.context); }
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 async Task <ActionResult <PlantLogType> > Update(Guid plantLogTypeId, UpdatePlantLogTypeRequest request) { var command = new UpdatePlantLogTypeCommand { Id = plantLogTypeId, Name = request.Name }; var response = await mediator.Send(command); if (!response.Success) { return(BadRequest(response.ErrorMessages)); } var updatedQuery = new GetPlantLogTypeByIdQuery { Id = command.Id }; var updatedResult = await mediator.Send(updatedQuery); var updatedObj = PlantLogType.FromCore(updatedResult.Data); return(Ok(updatedObj)); }
public async Task <ActionResult <PlantLogType> > Create(CreatePlantLogTypeRequest request) { var command = new CreatePlantLogTypeCommand { Id = Guid.NewGuid(), Name = request.Name }; var response = await mediator.Send(command); if (!response.Success) { return(BadRequest(response.ErrorMessages)); } var createdQuery = new GetPlantLogTypeByIdQuery { Id = command.Id }; var createdResult = await mediator.Send(createdQuery); var createdObj = PlantLogType.FromCore(createdResult.Data); return(CreatedAtRoute(nameof(PlantLogTypeController) + "/" + nameof(Get), new { plantLogTypeId = command.Id }, createdObj)); }
public async Task QueryAllPlantLogType() { await using var context = DatabaseHelper.CreateInMemoryDatabaseContext(nameof(QueryAllPlantLogType)); var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var id3 = Guid.NewGuid(); var id4 = Guid.NewGuid(); var id5 = Guid.NewGuid(); var name1 = "Hello"; var name2 = "World"; var name3 = "ab"; var name4 = "world Hello abcdefgh"; var name5 = "Töster"; var plantLogType1 = new PlantLogType { Id = id1, Name = name1 }; var plantLogType2 = new PlantLogType { Id = id2, Name = name2 }; var plantLogType3 = new PlantLogType { Id = id3, Name = name3 }; var plantLogType4 = new PlantLogType { Id = id4, Name = name4 }; var plantLogType5 = new PlantLogType { Id = id5, Name = name5 }; await context.PlantLogTypes.AddRangeAsync(plantLogType1, plantLogType2, plantLogType3, plantLogType4, plantLogType5); await context.SaveChangesAsync(); var queryAll = new GetAllPlantLogTypesQuery(); var queryHandler = new GetAllPlantLogTypesQueryHandler(context); var result = await queryHandler.Handle(queryAll, CancellationToken.None); Assert.True(result.Success); Assert.Equal(5, result.Data.Count()); Assert.Contains(result.Data, dto => dto.Id.Equals(id1) && dto.Name.Equals(name1)); Assert.Contains(result.Data, dto => dto.Id.Equals(id2) && dto.Name.Equals(name2)); Assert.Contains(result.Data, dto => dto.Id.Equals(id3) && dto.Name.Equals(name3)); Assert.Contains(result.Data, dto => dto.Id.Equals(id4) && dto.Name.Equals(name4)); Assert.Contains(result.Data, dto => dto.Id.Equals(id5) && dto.Name.Equals(name5)); var queryAllHello = new GetAllPlantLogTypesQuery { NameFilter = "Hello" }; var resultAllHello = await queryHandler.Handle(queryAllHello, CancellationToken.None); Assert.True(resultAllHello.Success); Assert.Equal(2, resultAllHello.Data.Count()); Assert.Contains(resultAllHello.Data, dto => dto.Id.Equals(id1) && dto.Name.Equals(name1)); Assert.Contains(resultAllHello.Data, dto => dto.Id.Equals(id4) && dto.Name.Equals(name4)); var queryAllWorld = new GetAllPlantLogTypesQuery { NameFilter = "World" }; var resultAllWorld = await queryHandler.Handle(queryAllWorld, CancellationToken.None); Assert.True(resultAllWorld.Success); Assert.Single(resultAllWorld.Data); Assert.Contains(resultAllWorld.Data, dto => dto.Id.Equals(id2) && dto.Name.Equals(name2)); var queryAllHelloLc = new GetAllPlantLogTypesQuery { NameFilter = "hello" }; var resultAllHelloLc = await queryHandler.Handle(queryAllHelloLc, CancellationToken.None); Assert.True(resultAllHelloLc.Success); Assert.Empty(resultAllHelloLc.Data); var querySpecialChar = new GetAllPlantLogTypesQuery { NameFilter = "ö" }; var resultSpecialChar = await queryHandler.Handle(querySpecialChar, CancellationToken.None); Assert.True(resultSpecialChar.Success); Assert.Single(resultSpecialChar.Data); Assert.Contains(resultSpecialChar.Data, dto => dto.Id.Equals(id5) && dto.Name.Equals(name5)); }
internal static PlantLogTypeDto FromDao(PlantLogType plantLogType) { return(new PlantLogTypeDto(plantLogType.Id, plantLogType.Name)); }