Example #1
0
        public void CanResolveOneWayEdgeConnectionBetween2DifferentModelTypes()
        {
            const string srcId   = "model2_1";
            const string destId  = "model3_1";
            int          counter = 0;

            Model2 m2_1 = null;
            Model3 m3_1 = null;

            var model2 = new Model2
            {
                Id     = srcId,
                Field1 = "f1",
                Field2 = 34,
                Edge   = new Model2ConnectionToModel3
                {
                    Field1 = "f12",
                    Id     = destId,
                    Model3 = new Model3
                    {
                        Id     = destId,
                        Field1 = "barr"
                    }
                }
            };

            var edges = _connectionFieldResolver.HandleConnectionEdges(model2, (entity) =>
            {
                if (entity is Model2 em2)
                {
                    if (em2.Id == srcId)
                    {
                        m2_1 = em2;
                    }
                }

                if (entity is Model3 em3)
                {
                    if (em3.Id == destId)
                    {
                        m3_1 = em3;
                    }
                }

                counter++;
            });

            counter.ShouldBe(2);

            edges.ShouldNotBeNull();
            edges.Count.ShouldBe(1);

            m2_1.ShouldNotBeNull();
            m3_1.ShouldNotBeNull();

            AssertEdge(edges[0], srcId, destId);
        }