public static MutatorsConfigurator <TRoot, TChild, TValue> SetIf <TRoot, TChild, TValue>( this MutatorsConfigurator <TRoot, TChild, TValue> configurator, Expression <Func <TChild, bool?> > condition, Expression <Func <TChild, TValue> > value) { configurator.SetMutator(EqualsToIfConfiguration.Create(configurator.Root.ConfiguratorType, typeof(TChild), condition, value, null)); return(configurator); }
public void TestWithConditionBeforeTarget() { configurator.If(s => s.A.S == "zzz").Target(d => d.RootS).Set(s => s.RootS); var equalsToIfConfiguration = EqualsToIfConfiguration.Create <DestRoot>((Expression <Func <SourceRoot, bool?> >)(s => s.A.S == "zzz"), (Expression <Func <SourceRoot, string> >)(s => s.RootS), null); AssertEquivalentConfigurations(equalsToIfConfiguration); AssertEquivalentPaths(d => d.RootS); }
public void TestBatchSetWithCondition() { configurator.If(s => s.RootS == "zzz").GoTo(d => d.A).BatchSet((d, s) => new Batch { { d.S, s.RootS } }); AssertEquivalentConfigurations( EqualsToIfConfiguration.Create <DestRoot>((Expression <Func <SourceRoot, bool?> >)(s => s.RootS == "zzz"), (Expression <Func <SourceRoot, string> >)(s => s.RootS), null)); AssertEquivalentPathBodies(d => d.A.S); }
public void TestReplaceEachToCurrentOnlyInGotoPath() { var subConfigurator = configurator.GoTo(d => d.As.Each(), s => s.As.Each()); subConfigurator.Target(d => d.Bs.Each().S).If((s, d) => s.S.Length % 2 == 0 && d.S.Length % 2 == 1).Set(s => s.Bs.Each().S); var equalsToConfiguration = EqualsToIfConfiguration.Create <DestRoot>((Expression <Func <SourceRoot, DestRoot, bool?> >)((s, d) => s.As.Current().S.Length % 2 == 0 && d.As.Current().S.Length % 2 == 1), (Expression <Func <SourceRoot, string> >)(s => s.As.Current().Bs.Each().S), null); AssertEquivalentConfigurations(equalsToConfiguration); AssertEquivalentPaths(d => d.As.Each().Bs.Each().S); }
public void TestGotoWithCondition() { var subConfigurator = configurator.GoTo(d => d.As.Each(), s => s.As.Current()); subConfigurator.Target(d => d.S).If(s => s.S.Length % 2 == 0).Set(s => s.S); var equalsToConfiguration = EqualsToIfConfiguration.Create <DestRoot>((Expression <Func <SourceRoot, bool?> >)(s => s.As.Current().S.Length % 2 == 0), (Expression <Func <SourceRoot, string> >)(s => s.As.Current().S), null); AssertEquivalentConfigurations(equalsToConfiguration); AssertEquivalentPaths(d => d.As.Each().S); }
public void TestConditionWithDest() { configurator.Target(d => d.A.S) .If((s, d) => s.As.Any(x => x.S == "zzz") && d.RootS == "Dest") .Set(s => s.A.S); var equalsToIfConfiguration = EqualsToIfConfiguration.Create <DestRoot>((Expression <Func <SourceRoot, DestRoot, bool?> >)((s, d) => s.As.Any(x => x.S == "zzz") && d.RootS == "Dest"), (Expression <Func <SourceRoot, string> >)(s => s.A.S), null); AssertEquivalentConfigurations(equalsToIfConfiguration); AssertEquivalentPaths(d => d.A.S); }
public void TestConditionWithEach() { configurator.Target(d => d.As.Each().S) .If(s => s.As.Each().S.Length == 5) .Set(s => s.As.Current().S); var equalsToIfConfiguration = EqualsToIfConfiguration.Create <DestRoot>((Expression <Func <SourceRoot, bool?> >)(s => s.As.Current().S.Length == 5), (Expression <Func <SourceRoot, string> >)(s => s.As.Current().S), null); AssertEquivalentConfigurations(equalsToIfConfiguration); AssertEquivalentPaths(d => d.As.Each().S); }
public void TestWithTwoConditions() { Expression <Func <SourceRoot, bool?> > firstCondition = s => s.A.S == "zzz"; Expression <Func <SourceRoot, bool?> > secondCondition = s => s.RootS.Length == 3; configurator.Target(d => d.RootS).If(firstCondition).If(secondCondition).Set(s => s.RootS); var equalsToIfConfiguration = EqualsToIfConfiguration.Create <DestRoot>(firstCondition.AndAlso(secondCondition), (Expression <Func <SourceRoot, string> >)(s => s.RootS), null); AssertEquivalentConfigurations(equalsToIfConfiguration); AssertEquivalentPaths(d => d.RootS); }