public async Task GetSinglePlantLogType()
        {
            var logType = ValidObjectHelper.ValidPlantLogType();
            var id      = logType.Id;
            var name    = logType.Name;

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

            await context.SaveChangesAsync();

            var querySingle = new GetPlantLogTypeByIdQuery {
                Id = id
            };
            var queryHandler = new GetPlantLogTypeByIdQueryHandler(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 GetPlantLogTypeByIdQuery {
                Id = Guid.NewGuid()
            };
            var resultNonExisting = await queryHandler.Handle(queryNonExisting, CancellationToken.None);

            Assert.False(resultNonExisting.Success);
        }
Пример #2
0
        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)));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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));
        }