예제 #1
0
        public LohiQuery(
            WaterLevelLocationRepository waterLevelLocationRepository,
            WaterLevelRepository waterLevelRepository,
            WaterMeasurementLocationRepository waterLevelMeasurementRepository,
            WaterMeasurementRepository waterMeasurementRepository,
            WaterMeasurementRawRepository waterMeasurementRawRepository
            )
        {
            Field <WaterLevelLocationType>(
                "WaterLevelLocation",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <int>("id");
                return(waterLevelLocationRepository.GetOneById(id));
            }
                );
            Field <ListGraphType <WaterLevelLocationType> >(
                "WaterLevelLocations",
                resolve: context => waterLevelLocationRepository.GetAll());

            Field <ListGraphType <WaterLevelType> >(
                "WaterLevels",
                resolve: context => waterLevelRepository.GetAll());


            Field <WaterMeasurementLocationType>(
                "WaterMeasurementLocation",
                arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IdGraphType> >
            {
                Name = "id"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <int>("id");
                return(waterLevelMeasurementRepository.GetOneById(id));
            }
                );
            Field <ListGraphType <WaterMeasurementLocationType> >(
                "WaterMeasurementLocations",
                resolve: context => waterLevelMeasurementRepository.GetAll());

            Field <ListGraphType <WaterMeasurementType> >(
                "WaterMeasurements",
                resolve: context => waterMeasurementRepository.GetAll());

            Field <ListGraphType <WaterMeasurementRawType> >(
                "RawWaterMeasurements",
                resolve: context => waterMeasurementRawRepository.GetAll());
        }
        public async void GetAll_ShouldReturnData()
        {
            //Arrange
            var _dbContext = _dbContextFactory.BuildDbContext();
            var sut        = new WaterLevelLocationRepository(_dbContext);

            var expected = _dbContext.WaterLevelLocation;

            //Act
            var actual = await sut.GetAll();

            //Assert
            actual.Should().Equal(expected);
        }
예제 #3
0
        public LohiMutation(WaterMeasurementLocationRepository waterMeasurementLocationRepository, WaterLevelLocationRepository waterLevelLocationRepository)
        {
            FieldAsync <WaterMeasurementLocationType>(
                "CreateWaterMeasurementLocation",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <WaterMeasurementLocationInputType> > {
                Name = "waterMeasurementLocation"
            }),
                resolve: async context =>
            {
                var waterMeasurementLocation = context.GetArgument <WaterMeasurementLocation>("waterMeasurementLocation");
                return(await context.TryAsyncResolve(
                           async c => await waterMeasurementLocationRepository.AddWaterMeasurementLocation(waterMeasurementLocation)));
            });

            FieldAsync <WaterLevelLocationType>(
                "CreateWaterLevelLocation",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <WaterLevelLocationInputType> > {
                Name = "waterLevelLocation"
            }),
                resolve: async context =>
            {
                var waterLevelLocation = context.GetArgument <WaterLevelLocation>("waterLevelLocation");
                return(await context.TryAsyncResolve(
                           async c => await waterLevelLocationRepository.AddWaterLevelLocation(waterLevelLocation)));
            });

            FieldAsync <IntGraphType>(
                "DeleteWaterLevelLocation",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "id"
            }),
                resolve: async context =>
            {
                var id = context.GetArgument <int>("id");
                var waterLevelLocation = await waterLevelLocationRepository.GetOneById(id);
                if (waterLevelLocation == null)
                {
                    context.Errors.Add(new ExecutionError("Id not found"));
                    return(null);
                }
                return(await context.TryAsyncResolve(
                           async c => await waterLevelLocationRepository.DeleteWaterLevelLocation(waterLevelLocation)));
            });
        }