public async Task GetSinglePlantSpecies()
        {
            var species = ValidObjectHelper.ValidPlantSpecies();
            var id      = species.Id;
            var name    = species.Name;

            await using var context = DatabaseHelper.CreateInMemoryDatabaseContext(nameof(GetSinglePlantSpecies));
            await context.PlantSpecies.AddAsync(new PlantSpecies { Id = id, Name = name });

            await context.SaveChangesAsync();

            var querySingle = new GetPlantSpeciesByIdQuery {
                Id = id
            };
            var queryHandler = new GetPlantSpeciesByIdQueryHandler(context);
            var result       = await queryHandler.Handle(querySingle, CancellationToken.None);

            Assert.True(result.Success);
            Assert.Equal(id, result.Data.Id);
            Assert.Equal(name, result.Data.Name);

            var queryNonExisting = new GetPlantSpeciesByIdQuery {
                Id = Guid.NewGuid()
            };
            var resultNonExisting = await queryHandler.Handle(queryNonExisting, CancellationToken.None);

            Assert.False(resultNonExisting.Success);
        }
        public async Task <ActionResult <PlantSpecies> > Get(Guid speciesId)
        {
            var query = new GetPlantSpeciesByIdQuery {
                Id = speciesId
            };
            var response = await mediator.Send(query);

            if (!response.Success)
            {
                return(BadRequest(response.ErrorMessages));
            }

            return(Ok(PlantSpecies.FromCore(response.Data)));
        }
        public async Task <ActionResult <PlantSpecies> > Update(Guid speciesId, UpdatePlantSpeciesRequest request)
        {
            var command = new UpdatePlantSpeciesCommand {
                Id = speciesId, Name = request.Name
            };
            var response = await mediator.Send(command);

            if (!response.Success)
            {
                return(BadRequest(response.ErrorMessages));
            }

            var updatedQuery = new GetPlantSpeciesByIdQuery {
                Id = command.Id
            };
            var updatedResult = await mediator.Send(updatedQuery);

            var updatedObj = PlantSpecies.FromCore(updatedResult.Data);

            return(Ok(updatedObj));
        }
        public async Task <ActionResult <PlantSpecies> > Create(CreatePlantSpeciesRequest request)
        {
            var command = new CreatePlantSpeciesCommand {
                Id = Guid.NewGuid(), Name = request.Name
            };
            var response = await mediator.Send(command);

            if (!response.Success)
            {
                return(BadRequest(response.ErrorMessages));
            }

            var createdQuery = new GetPlantSpeciesByIdQuery {
                Id = command.Id
            };
            var createdResult = await mediator.Send(createdQuery);

            var createdObj = PlantSpecies.FromCore(createdResult.Data);

            return(CreatedAtRoute(nameof(PlantSpeciesController) + "/" + nameof(Get), new { speciesId = command.Id }, createdObj));
        }