public async Task Custom() { var configuration = new AugmenterConfiguration(); configuration.Configure <TestModel1>(c => { c.Custom((x, d) => { d["Opt1"] = Boxed.True; d["Opt2"] = Boxed.False; d["Opt3"] = "something"; d.Remove(nameof(TestModel1.Foo)); }); }); configuration.Build(); var augmenter = MocksHelper.Augmenter(configuration); var model = new TestModel1(); var result = (await augmenter.AugmentAsync(model)).Cast <AObject>(); result["Opt1"].Should().Be(Boxed.True); result["Opt2"].Should().Be(Boxed.False); result["Opt3"].Should().Be("something"); result.Should().NotContainKey(nameof(TestModel1.Foo)); }
protected AugmenterConfiguration CreateCommonConfiguration(bool build = true) { var configuration = new AugmenterConfiguration(); configuration.Configure <TestModel1>(c => { c.Add("Bar", (x, _) => $"({x.Id})"); c.Remove(nameof(TestModel1.Some)); }); configuration.Configure <TestModelA>(c => { c.Add("Id2", (x, _) => $"{x.Id}2"); }); configuration.Configure <TestModelB>(c => { c.Remove(nameof(TestModelB.Foo)); }); configuration.Configure <TestModelC>(c => { c.Add("Bar2", (x, _) => $"{x.Id}-{x.Foo}"); c.Remove(nameof(TestModel1.Some)); }); if (build) { configuration.Build(); } return(configuration); }
protected AugmenterConfiguration CreateBuiltConfiguration() { var configuration = new AugmenterConfiguration(); configuration.Configure <TestModel1>(c => { }); configuration.Build(); return(configuration); }
public async Task AlwaysAugmentsIfUsingAWrapper() { var configuration = new AugmenterConfiguration(); configuration.Build(); var fixture = MocksHelper.AugmenterBase(configuration); var model = new TestModel1(); var wrapper = new AugmenterWrapper <TestModel1>(model); var result = await fixture.AugmentAsync(wrapper); fixture.Contexts.Should().HaveCount(1); fixture.Contexts.First().TypeConfiguration.Augments.Should().HaveCount(0); fixture.Contexts.First().TypeConfiguration.Properties.Should().HaveCount(3); }
public async Task AlwaysAugmentsIfConfigureIsProvided() { var configuration = new AugmenterConfiguration(); configuration.Build(); var fixture = MocksHelper.AugmenterBase(configuration); var model = new TestModel1(); var result = await fixture.AugmentAsync(model, c => { c.Add("Bar", (x, state) => "bar"); }); fixture.Contexts.Should().HaveCount(1); fixture.Contexts.First().EphemeralTypeConfiguration.Augments.Should().HaveCount(1); fixture.Contexts.First().TypeConfiguration.Properties.Should().HaveCount(3); }
public NestedTest() { _configuration = new AugmenterConfiguration(); _configuration.Configure <TestModel1>(c => { }); _configuration.Configure <TestModelWithNested>(c => { c.Add("Foo", (_, __) => "42"); }); _configuration.Configure <TestModelNested>(c => { c.Add("Foo", (_, __) => "43"); }); _configuration.Configure <TestModelNestedNested>(c => { c.Add("Foo", (_, __) => "44"); }); _configuration.Build(); _fixture = MocksHelper.Augmenter(_configuration); }
protected AugmenterConfiguration CreateCommonConfiguration(bool build = true) { var configuration = new AugmenterConfiguration(); configuration.Configure <TestModel1>(c => { c.Add("Bar", (x, _) => $"({x.Id})"); c.Remove(nameof(TestModel1.Some)); }); configuration.Configure <TestModelA>(c => { c.Add("Id2", (x, _) => $"{x.Id}2"); }); configuration.Configure <TestModelB>(c => { c.Remove(nameof(TestModelB.Foo)); }); configuration.Configure <TestModelC>(c => { c.Add("Bar2", (x, _) => $"{x.Id}-{x.Foo}"); c.Remove(nameof(TestModel1.Some)); }); configuration.Configure <ITestModelD>(c => { c.Add("Name", (x, state) => { var names = x.GetType().GetProperty("Names").GetValue(x) as IList; var name = names.Count > 0 ? names[0] : null; return(name); }); c.Remove("Names"); }); if (build) { configuration.Build(); } return(configuration); }
public async Task Nested() { var model = new TestModelWithNested(); _configuration = new AugmenterConfiguration(); _configuration.Configure <TestModelNested>(c => { c.Add("Foo", (x, state) => { return(state["key"]); }); }); _configuration.Build(); _fixture = MocksHelper.Augmenter(_configuration); var result = await _fixture.AugmentAsync(model, addState : state => { state.Add("key", "foo"); }) as AObject; result["Nested"].Cast <AObject>()["Foo"].Cast <string>().Should().Be("foo"); }
public async Task Globally() { var model = new TestModel1(); _configuration = new AugmenterConfiguration(); _configuration.Configure <TestModel1>(c => { c.Add("Bar", (x, state) => { return(state["key"]); }); }); _configuration.Build(); _fixture = MocksHelper.Augmenter(_configuration); var result = await _fixture.AugmentAsync(model, addState : state => { state.Add("key", "bar"); }) as AObject; result["Bar"].Cast <string>().Should().Be("bar"); }
public NestedConfigureTest() { var configuration = new AugmenterConfiguration(); configuration.Configure <NestedConfigureModels.Model1>(c => { c.Add("Bar", (x, _) => $"({x.Id})"); c.Remove(nameof(NestedConfigureModels.Model1.Ex)); c.ConfigureNested(x => x.Nested1, nc => { nc.SetAddState((m, s1, s2) => { s2["ParentId"] = m.Id; }); nc.SetTypeConfiguration(ntc => { ntc.Add("Some", (x, state) => "some"); }); }); }); configuration.Configure <NestedConfigureModels.Model2>(c => { }); configuration.Configure <NestedConfigureModels.Model3>(c => { c.ConfigureNestedArray(x => x.Nested, nc => { nc.SetAddState((m, s1, s2) => { s2["ParentId"] = m.Id; }); nc.SetTypeConfiguration(ntc => { ntc.Add("Some", (x, state) => "some"); }); }); }); configuration.Configure <NestedConfigureModels.Model4>(c => { c.ConfigureNestedArray(x => x.Nested, nc => { nc.SetAddState((m, s1, s2) => { s2["ParentId"] = m.Id; }); nc.SetTypeConfiguration(ntc => { ntc.Add("Some", (x, state) => "some"); }); }); }); configuration.Configure <NestedConfigureModels.ModelNested>(c => { c.AddIf("ParentId", "ParentId", (m, s) => s["ParentId"]); }); configuration.Build(); _configuration = configuration; _fixture = MocksHelper.Augmenter(_configuration); }