Example #1
0
            public void Should_FillPaths_And_NotModifyOnLeave()
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                context.EnterPath("base");
                context.EnterPath("path");
                context.EnterPath("nested");

                StateCheck(context);

                context.LeavePath();

                StateCheck(context);

                context.LeavePath();

                StateCheck(context);

                context.LeavePath();

                StateCheck(context);

                void StateCheck(DiscoveryContext ctx)
                {
                    ctx.Paths.Keys.Should().HaveCount(3);
                    ctx.Paths.Keys.Should().Contain("");
                    ctx.Paths.Keys.Should().Contain("base");
                    ctx.Paths.Keys.Should().Contain("base.path");

                    ctx.Paths[""].Keys.Should().ContainSingle("base");
                    ctx.Paths[""]["base"].Should().Be("base");

                    ctx.Paths["base"].Keys.Should().ContainSingle("path");
                    ctx.Paths["base"]["path"].Should().Be("base.path");

                    ctx.Paths["base.path"].Keys.Should().ContainSingle("nested");
                    ctx.Paths["base.path"]["nested"].Should().Be("base.path.nested");
                }
            }
Example #2
0
            public void EnterCollectionItemPath_Should_LeavePathWithCollectionIndexPrefix()
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                context.EnterPath("path");
                context.EnterCollectionItemPath();

                context.LeavePath();

                context.AddError(321);

                context.Errors.Keys.Should().ContainSingle("path");
                context.Errors.Should().HaveCount(1);
                context.Errors["path"].Should().HaveCount(1);
                context.Errors["path"].ElementAt(0).Should().Be(321);
            }
Example #3
0
            public void AddErrors_Should_AddToPreviousPathAfterStepOut(string basePath, string newSegment, string expectedPath)
            {
                _ = expectedPath;

                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                context.EnterPath(basePath);
                context.EnterPath(newSegment);
                context.LeavePath();

                context.AddError(123);

                context.Errors.Keys.Should().ContainSingle(basePath);
                context.Errors.Should().HaveCount(1);
                context.Errors[basePath].Should().HaveCount(1);
                context.Errors[basePath].ElementAt(0).Should().Be(123);
            }