Ejemplo n.º 1
0
        public void DeleteMutationTest1()
        {
            Organism organism = new Organism();

            organism.Chromosomes.Add(new Chromosome(1, "1"));

            IRandom        rand    = new Deterministic(0);
            DeleteMutation mutator = new DeleteMutation(rand);

            mutator.Mutate(organism);

            Assert.AreEqual("", organism.Chromosomes[0].ToString());
        }
Ejemplo n.º 2
0
        public void DeleteMutationTest2()
        {
            Organism organism = new Organism();

            organism.Chromosomes.Add(new Chromosome(1, "10101"));

            IRandom        rand    = new Deterministic(1);
            DeleteMutation mutator = new DeleteMutation(rand);

            mutator.Mutate(organism);

            string answer = organism.Chromosomes[0].ToString();

            Assert.AreEqual("1101", answer);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds the required mutation fields to the GraphQL schema for create, update and delete
        /// </summary>
        /// <typeparam name="TModelCreateInputType">The GraphQL input type used for the create functions</typeparam>
        /// <typeparam name="TModelUpdateInputType">The GraphQL Input Type used for the update functions</typeparam>
        /// <typeparam name="TModelType">The GraphQL model type used for returning data</typeparam>
        /// <typeparam name="TModel">The EF model type for saving to the DB</typeparam>
        /// <param name="name">The name of the entity</param>
        /// <param name="createMutation">An override for the create mutation</param>
        /// <param name="updateMutation">An override for the update mutation</param>
        /// <param name="deleteMutation">An override for the delete mutation</param>
        /// <param name="conditionalUpdateMutation">An override for the conditional update mutation</param>
        /// <param name="conditionalDeleteMutation">An override for the conditional delete mutation</param>
        public void AddMutationField <TModelCreateInputType, TModelUpdateInputType, TModelType, TModel>(
            string name,
            Func <ResolveFieldContext <object>, Task <object> > createMutation            = null,
            Func <ResolveFieldContext <object>, Task <object> > updateMutation            = null,
            Func <ResolveFieldContext <object>, Task <object> > deleteMutation            = null,
            Func <ResolveFieldContext <object>, Task <object> > conditionalUpdateMutation = null,
            Func <ResolveFieldContext <object>, Task <object> > conditionalDeleteMutation = null)
            where TModelCreateInputType : InputObjectGraphType <TModel>
            where TModelUpdateInputType : InputObjectGraphType <TModel>
            where TModelType : ObjectGraphType <TModel>
            where TModel : class, IOwnerAbstractModel, new()
        {
            FieldAsync <ListGraphType <TModelType> >(
                $"create{name}",
                arguments: new QueryArguments(
                    new QueryArgument <ListGraphType <TModelCreateInputType> > {
                Name = name + "s"
            },
                    new QueryArgument <ListGraphType <StringGraphType> > {
                Name = "MergeReferences"
            }
                    ),
                resolve: createMutation ?? CreateMutation.CreateCreateMutation <TModel>(name)
                );

            FieldAsync <ListGraphType <TModelType> >(
                $"update{name}",
                arguments: new QueryArguments(
                    new QueryArgument <ListGraphType <TModelUpdateInputType> > {
                Name = name + "s"
            },
                    new QueryArgument <ListGraphType <StringGraphType> > {
                Name = "MergeReferences"
            }
                    ),
                resolve: updateMutation ?? UpdateMutation.CreateUpdateMutation <TModel>(name)
                );

            FieldAsync <ListGraphType <IdObjectType> >(
                $"delete{name}",
                arguments: new QueryArguments(
                    new QueryArgument <ListGraphType <IdGraphType> > {
                Name = $"{name}Ids"
            }
                    ),
                resolve: deleteMutation ?? DeleteMutation.CreateDeleteMutation <TModel>(name)
                );

            FieldAsync <BooleanObjectType>(
                $"update{name}sConditional",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <ListGraphType <IdGraphType> > {
                Name = "ids"
            },
                    new QueryArgument <ListGraphType <ListGraphType <WhereExpressionGraph> > >
            {
                Name        = "conditions",
                Description = ConditionalWhereDesc
            },
                    new QueryArgument <TModelUpdateInputType> {
                Name = "valuesToUpdate"
            },
                    new QueryArgument <ListGraphType <StringGraphType> > {
                Name = "fieldsToUpdate"
            }
                    ),
                resolve: conditionalUpdateMutation ?? UpdateMutation.CreateConditionalUpdateMutation <TModel>(name)
                );

            FieldAsync <BooleanObjectType>(
                $"delete{name}sConditional",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <ListGraphType <IdGraphType> > {
                Name = "ids"
            },
                    new QueryArgument <ListGraphType <ListGraphType <WhereExpressionGraph> > >
            {
                Name        = "conditions",
                Description = ConditionalWhereDesc
            }
                    ),
                resolve: conditionalDeleteMutation ?? DeleteMutation.CreateConditionalDeleteMutation <TModel>(name)
                );
        }
Ejemplo n.º 4
0
 public string Visit(DeleteMutation <char> mutation)
 => $"[d:{mutation.ActualItem}]";