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)); }
public async Task Basic() { var model = new TestModel1(); var result = await _fixture.AugmentAsync(model) as AObject; ((string)result["Bar"]).Should().Be($"({model.Id})"); result.Should().NotContainKey(nameof(TestModel1.Some)); }
public async Task Remove_WithIgnore_IgnoresAugment() { var model = new TestModel1(); var result = await _fixture.AugmentAsync(model, c => { c.Remove(nameof(TestModel1.Foo), (_, __) => AugmentationValue.Ignore); }) as AObject; result[nameof(TestModel1.Foo)].Cast <string>().Should().Be("foo"); }
public async Task Add_WithIgnore_IgnoresAugment() { var model = new TestModel1(); var result = await _fixture.AugmentAsync(model, c => { c.Add("Some", (_, __) => AugmentationValue.Ignore); }) as AObject; result.Should().NotContainKey("Some"); }
public async Task WithLocal() { var model = new TestModel1(); var result = await _fixture.AugmentAsync(model, c => { c.Add("Baz", (_, __) => 2); }) as AObject; result["Bar"].Cast <string>().Should().Be($"({model.Id})"); result["Baz"].Cast <int>().Should().Be(2); result.Should().NotContainKey(nameof(TestModel1.Some)); }
public void AddIf_False() { var tc = new TypeConfiguration <TestModel1>(); tc.AddIf("Foo", "IsAdmin", (x, s) => x.Id); var model = new TestModel1(); var state = new State(); state["IsAdmin"] = Boxed.False; var result = tc.Augments.First().ValueFunc(model, state); result.Should().Be(AugmentationValue.Ignore); }
public void ExposeIf_True() { var tc = new TypeConfiguration <TestModel1>(); tc.ExposeIf("Foo", "IsAdmin"); var model = new TestModel1(); var state = new State(); state["IsAdmin"] = Boxed.True; var result = tc.Augments.First().ValueFunc(model, state); result.Should().Be(AugmentationValue.Ignore); }
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 async Task Locally() { var model = new TestModel1(); var result = await _fixture.AugmentAsync(model, c => { c.Add("Bar", (x, state) => { return(state["key"]); }); }, state => { state.Add("key", "bar"); }) as AObject; result["Bar"].Cast <string>().Should().Be("bar"); }
public async Task PicksUpWrapperState() { var fixture = MocksHelper.AugmenterBase(CreateCommonConfiguration()); var model = new TestModel1(); var wrapper = new AugmenterWrapper <TestModel1>(model); wrapper.SetAddState((x, s) => { s["Baz"] = x.Id; }); await fixture.AugmentAsync(wrapper); fixture.Contexts.Should().HaveCount(1); var context = fixture.Contexts.First(); context.State["Baz"].Cast <int>().Should().Be(model.Id); }
public async Task PicksUpWrapperConfiguration() { var fixture = MocksHelper.AugmenterBase(CreateCommonConfiguration()); var model = new TestModel1(); var wrapper = new AugmenterWrapper <TestModel1>(model); wrapper.SetTypeConfiguration(c => { c.Add("Baz", (x, state) => x.Id); }); await fixture.AugmentAsync(wrapper); fixture.Contexts.Should().HaveCount(1); var context = fixture.Contexts.First(); context.Type.Should().Be(typeof(TestModel1)); context.TypeConfiguration.Type.Should().Be(typeof(TestModel1)); context.EphemeralTypeConfiguration.Type.Should().Be(typeof(TestModel1)); context.EphemeralTypeConfiguration.Augments.Should().HaveCount(1); }
public async Task WithIgnore() { var model = new TestModel1(); var result = await _fixture.AugmentAsync(model, config => { config.Add("Bar", (x, state) => { if ((bool)state["key"]) { return("YES"); } return(AugmentationValue.Ignore); }); }, state => { state.Add("key", false); }) as AObject; result.Should().NotContainKey("Bar"); }
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"); }