Example #1
0
            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));
            }
Example #2
0
            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);
            }
Example #3
0
            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");
            }
Example #4
0
            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");
            }
Example #5
0
            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);
            }
Example #6
0
 public StateTest()
 {
     _configuration = CreateBuiltConfiguration();
     _fixture       = MocksHelper.Augmenter(_configuration);
 }
Example #7
0
 public AugmenterTest()
 {
     _configuration = CreateCommonConfiguration();
     _fixture       = MocksHelper.Augmenter(_configuration);
 }