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

                var context = new DiscoveryContext(actions, 0);

                context.EnterPath(name);

                context.AddError(123, true);
                context.AddError(123, true);
                context.AddError(123, true);

                context.Errors.Should().HaveCount(1);
                context.Errors[name].Should().HaveCount(1);
                context.Errors[name].ElementAt(0).Should().Be(123);
            }
Example #2
0
            public void Should_AddErrors_To_DefaultPath()
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                context.AddError(123);
                context.AddError(1234);
                context.AddError(12345);

                context.Errors.Should().HaveCount(1);
                context.Errors[string.Empty].Should().HaveCount(3);
                context.Errors[string.Empty].ElementAt(0).Should().Be(123);
                context.Errors[string.Empty].ElementAt(1).Should().Be(1234);
                context.Errors[string.Empty].ElementAt(2).Should().Be(12345);
            }
Example #3
0
            public void Should_AddErrors(string name)
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                context.EnterPath(name);

                context.AddError(123);
                context.AddError(1234);
                context.AddError(12345);

                context.Errors.Should().HaveCount(1);
                context.Errors[name].Should().HaveCount(3);
                context.Errors[name].ElementAt(0).Should().Be(123);
                context.Errors[name].ElementAt(1).Should().Be(1234);
                context.Errors[name].ElementAt(2).Should().Be(12345);
            }
Example #4
0
            public void AddErrors_Should_AddToEnteredPath_And_ToPreviousPathAfterStepOut(string basePath, string newSegment, string expectedPath)
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

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

                context.AddError(123);

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

                context.LeavePath();

                context.AddError(321);

                if (basePath == expectedPath)
                {
                    context.Errors.Keys.Should().HaveCount(1);
                    context.Errors.Keys.Should().Contain(basePath);
                    context.Errors[basePath].Should().HaveCount(2);
                    context.Errors[basePath].ElementAt(0).Should().Be(123);
                    context.Errors[basePath].ElementAt(1).Should().Be(321);
                }
                else
                {
                    context.Errors.Keys.Should().HaveCount(2);
                    context.Errors.Keys.Should().Contain(basePath);
                    context.Errors.Keys.Should().Contain(expectedPath);
                    context.Errors[expectedPath].Should().HaveCount(1);
                    context.Errors[expectedPath].ElementAt(0).Should().Be(123);
                    context.Errors[basePath].Should().HaveCount(1);
                    context.Errors[basePath].ElementAt(0).Should().Be(321);
                }
            }
Example #5
0
            public void EnterCollectionItemPath_Should_EnterToCollectionIndexPrefix(string basePath, string expectedPath)
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                context.EnterPath(basePath);
                context.EnterCollectionItemPath();

                context.AddError(123);

                context.Errors.Should().HaveCount(1);
                context.Errors.Keys.Should().Contain(expectedPath);
                context.Errors[expectedPath].Should().HaveCount(1);
                context.Errors[expectedPath].ElementAt(0).Should().Be(123);
            }
Example #6
0
            public void AddErrors_Should_AddToEnteredPath_AfterStepIntoNextPath(string basePath, string newSegment, string expectedPath)
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

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

                context.AddError(123);

                context.Errors.Keys.Should().ContainSingle(expectedPath);
                context.Errors.Should().HaveCount(1);
                context.Errors[expectedPath].Should().HaveCount(1);
                context.Errors[expectedPath].ElementAt(0).Should().Be(123);
            }
Example #7
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 #8
0
            public void Should_AddError_OnlyWhen_NotExistsUnderSamePath_And_SkipIfDuplicateInPath_Is_True()
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                context.EnterPath("test1");

                context.AddError(123, true);
                context.AddError(123, true);
                context.AddError(123);

                context.EnterPath("test2");
                context.AddError(123, true);
                context.AddError(123, true);
                context.AddError(123);

                context.EnterPath("test3");
                context.AddError(123, true);
                context.AddError(123);
                context.AddError(123);

                context.Errors.Should().HaveCount(3);

                context.Errors["test1"].Should().HaveCount(2);
                context.Errors["test1"].ElementAt(0).Should().Be(123);
                context.Errors["test1"].ElementAt(1).Should().Be(123);

                context.Errors["test1.test2"].Should().HaveCount(2);
                context.Errors["test1.test2"].ElementAt(0).Should().Be(123);
                context.Errors["test1.test2"].ElementAt(1).Should().Be(123);

                context.Errors["test1.test2.test3"].Should().HaveCount(3);
                context.Errors["test1.test2.test3"].ElementAt(0).Should().Be(123);
                context.Errors["test1.test2.test3"].ElementAt(1).Should().Be(123);
                context.Errors["test1.test2.test3"].ElementAt(2).Should().Be(123);
            }