コード例 #1
0
        public void expands_the_partial()
        {
            var model = new ModelMap("case", "case");

            model.AddInstruction(new BeginProperty {
                Key = new PassThruValue("caseId")
            });
            model.AddInstruction(new EndProperty());
            model.AddInstruction(new BeginRelation());
            model.AddInstruction(new IncludePartial
            {
                Name       = "sitePartial",
                Attributes = new Dictionary <string, IDynamicValue>
                {
                    { "propertyName", new PassThruValue("siteId") }
                }
            });
            model.AddInstruction(new IncludePartial
            {
                Name       = "reusablePartial",
                Attributes = new Dictionary <string, IDynamicValue>
                {
                    { "propertyName", new PassThruValue("myProperty") }
                }
            });
            model.AddInstruction(new EndRelation());
            model.AddInstruction(new BeginRelation());
            model.AddInstruction(new IncludePartial {
                Name = "addressPartial"
            });
            model.AddInstruction(new EndRelation());

            var p1 = new ModelMap("reusablePartial", null);

            p1.AddInstruction(new BeginProperty {
                Key = new PassThruValue("${propertyName}")
            });
            p1.AddInstruction(new EndProperty());

            var p2 = new ModelMap("sitePartial", null);

            p2.AddInstruction(new BeginProperty {
                Key = new PassThruValue("${propertyName}")
            });
            p2.AddInstruction(new EndProperty());
            p2.AddInstruction(new IncludePartial
            {
                Name       = "reusablePartial",
                Attributes = new Dictionary <string, IDynamicValue>
                {
                    { "propertyName", new PassThruValue("myOtherProperty") }
                }
            });

            var p3 = new ModelMap("addressPartial", null);

            p3.AddInstruction(new BeginProperty {
                Key = new PassThruValue("addressId")
            });
            p3.AddInstruction(new EndProperty());

            var cache = new StubModelMapCache();

            cache.ThePartials.Add(p1);
            cache.ThePartials.Add(p2);
            cache.ThePartials.Add(p3);

            model.As <IExpandableMap>().Expand(cache);

            var instructions = new List <IModelMapInstruction>();
            var visitor      = new RecordingVisitor(instructions);

            model.Accept(visitor);

            VerifyInstructions.Assert(instructions, _ =>
            {
                _.Verify <BeginProperty>(__ => __.Key.ToString().ShouldEqual("caseId"));
                _.Is <EndProperty>();

                _.Is <BeginRelation>();

                // sitePartial
                _.Verify <PushVariableContext>(__ => __.Attributes["propertyName"].ToString().ShouldEqual("siteId"));

                _.Verify <BeginProperty>(__ => __.Key.ToString().ShouldEqual("${propertyName}"));
                _.Is <EndProperty>();

                // sitePartial => reusablePartial
                _.Verify <PushVariableContext>(__ => __.Attributes["propertyName"].ToString().ShouldEqual("myOtherProperty"));
                _.Verify <BeginProperty>(__ => __.Key.ToString().ShouldEqual("${propertyName}"));
                _.Is <EndProperty>();
                _.Is <PopVariableContext>();

                _.Is <PopVariableContext>();                //end sitePartial

                // reusablePartial
                _.Verify <PushVariableContext>(__ => __.Attributes["propertyName"].ToString().ShouldEqual("myProperty"));
                _.Verify <BeginProperty>(__ => __.Key.ToString().ShouldEqual("${propertyName}"));
                _.Is <EndProperty>();
                _.Is <PopVariableContext>();                //end reusablePartial

                _.Is <EndRelation>();
                _.Is <BeginRelation>();

                // addressPartial
                _.Is <PushVariableContext>();
                _.Verify <BeginProperty>(__ => __.Key.ToString().ShouldEqual("addressId"));
                _.Is <EndProperty>();
                _.Is <PopVariableContext>();                //end addressPartial

                _.Is <EndRelation>();
            });
        }