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

                actions.RegisterError(Arg.Is <IError>(a =>
                                                      a is ReferenceLoopError &&
                                                      ((a as ReferenceLoopError).Args.Single() as TypeArg).Value == typeof(TestScope))).Returns(666);

                var context = new DiscoveryContext(actions, 0);

                var scopes = Enumerable.Range(0, levels).Select(i => Substitute.For <IDiscoverable>()).ToArray();

                for (var i = 0; i < levels; ++i)
                {
                    actions.GetDiscoverableSpecificationScope(Arg.Is(i)).Returns(scopes[i]);
                }

                for (var i = 1; i < levels; ++i)
                {
                    context.EnterPath(i.ToString(CultureInfo.InvariantCulture));
                    context.EnterScope <TestScope>(i);
                }

                context.EnterPath(levels.ToString(CultureInfo.InvariantCulture));
                context.EnterScope <TestScope>(0);

                for (var i = 1; i < levels; ++i)
                {
                    actions.Received(1).GetDiscoverableSpecificationScope(i);
                    scopes[i].Received(1).Discover(Arg.Is(context));
                }

                var errorLevel = string.Join(".", Enumerable.Range(1, levels).Select(i => i).ToArray());

                context.Errors.Keys.Should().ContainSingle(errorLevel);
                context.Errors[errorLevel].Should().HaveCount(1);
                context.Errors[errorLevel].Single().Should().Be(666);

                context.ReferenceLoopRoots.Should().ContainSingle(errorLevel);
            }
Example #2
0
            public void Should_NotEnterScope_And_Register_ReferenceLoopRoot_When_LoopExists(string name)
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                var discoverableSpecificationScope = Substitute.For <IDiscoverable>();

                actions.GetDiscoverableSpecificationScope(Arg.Is(123)).Returns(discoverableSpecificationScope);

                actions.RegisterError(Arg.Is <IError>(a =>
                                                      a is ReferenceLoopError &&
                                                      ((a as ReferenceLoopError).Args.Single() as TypeArg).Value == typeof(TestScope))).Returns(666);

                context.EnterScope <TestScope>(123);

                actions.Received(1).GetDiscoverableSpecificationScope(Arg.Is(123));
                discoverableSpecificationScope.Received(1).Discover(Arg.Is(context));

                actions.DidNotReceiveWithAnyArgs().RegisterError(Arg.Any <IError>());

                context.EnterPath(name);
                context.EnterScope <TestScope>(123);

                actions.Received(1).GetDiscoverableSpecificationScope(Arg.Is(123));
                discoverableSpecificationScope.Received(1).Discover(Arg.Is(context));

                actions.Received(1).RegisterError(Arg.Is <IError>(a =>
                                                                  a is ReferenceLoopError &&
                                                                  ((a as ReferenceLoopError).Args.Single() as TypeArg).Value == typeof(TestScope)));

                context.Errors.Keys.Should().ContainSingle(name);
                context.Errors[name].Should().HaveCount(1);
                context.Errors[name].Single().Should().Be(666);

                context.ReferenceLoopRoots.Should().ContainSingle(name);
            }
Example #3
0
            public void Should_GetDiscoverableSpecificationScope_And_ExecuteDiscover_With_ItselfAsParameter()
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                var discoverableSpecificationScope = Substitute.For <IDiscoverable>();

                actions.GetDiscoverableSpecificationScope(Arg.Is(123)).Returns(discoverableSpecificationScope);

                context.EnterScope <TestScope>(123);

                actions.Received(1).GetDiscoverableSpecificationScope(Arg.Is(123));
                discoverableSpecificationScope.Received(1).Discover(Arg.Is(context));
            }
Example #4
0
            public void Should_GetDiscoverableSpecificationScope_And_ExecuteDiscover_With_ItselfAsParameter_ManyTimes(int levels)
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                var scopes = Enumerable.Range(1, levels).Select(i => Substitute.For <IDiscoverable>()).ToArray();

                for (var i = 1; i < levels; ++i)
                {
                    actions.GetDiscoverableSpecificationScope(Arg.Is(i)).Returns(scopes[i]);
                }

                for (var i = 1; i < levels; ++i)
                {
                    context.EnterScope <TestScope>(i);
                }

                for (var i = 1; i < levels; ++i)
                {
                    actions.Received(1).GetDiscoverableSpecificationScope(i);
                    scopes[i].Received(1).Discover(Arg.Is(context));
                }
            }
Example #5
0
            public void Should_NotEnterScope_And_Populate_ReferenceLoopRoots_When_MultipleReferenceLoopsExist()
            {
                var actions = Substitute.For <IDiscoveryContextActions>();

                var context = new DiscoveryContext(actions, 0);

                var discoverableSpecificationScope = Substitute.For <IDiscoverable>();

                actions.GetDiscoverableSpecificationScope(Arg.Is(123)).Returns(discoverableSpecificationScope);

                actions.RegisterError(Arg.Is <IError>(a =>
                                                      a is ReferenceLoopError &&
                                                      ((a as ReferenceLoopError).Args.Single() as TypeArg).Value == typeof(TestScope))).Returns(666);

                actions.RegisterError(Arg.Is <IError>(a =>
                                                      a is ReferenceLoopError &&
                                                      ((a as ReferenceLoopError).Args.Single() as TypeArg).Value == typeof(int))).Returns(667);

                actions.RegisterError(Arg.Is <IError>(a =>
                                                      a is ReferenceLoopError &&
                                                      ((a as ReferenceLoopError).Args.Single() as TypeArg).Value == typeof(DateTimeOffset?))).Returns(668);

                context.EnterScope <TestScope>(123);
                context.EnterScope <int>(321);

                context.EnterPath("base");

                context.EnterScope <TestScope>(1);
                context.EnterScope <int>(2);

                context.EnterPath("path");

                context.EnterScope <TestScope>(123);
                context.EnterScope <int>(321);

                context.EnterPath("nested");
                context.EnterScope <DateTimeOffset?>(333);
                context.EnterScope <DateTimeOffset?>(333);

                actions.Received(1).GetDiscoverableSpecificationScope(Arg.Is(123));
                actions.Received(1).GetDiscoverableSpecificationScope(Arg.Is(321));
                actions.Received(1).GetDiscoverableSpecificationScope(Arg.Is(333));

                actions.Received(1).RegisterError(Arg.Is <IError>(a =>
                                                                  a is ReferenceLoopError &&
                                                                  ((a as ReferenceLoopError).Args.Single() as TypeArg).Value == typeof(TestScope)));

                actions.Received(1).RegisterError(Arg.Is <IError>(a =>
                                                                  a is ReferenceLoopError &&
                                                                  ((a as ReferenceLoopError).Args.Single() as TypeArg).Value == typeof(int)));

                actions.Received(1).RegisterError(Arg.Is <IError>(a =>
                                                                  a is ReferenceLoopError &&
                                                                  ((a as ReferenceLoopError).Args.Single() as TypeArg).Value == typeof(DateTimeOffset?)));

                context.Errors.Keys.Should().Contain("base.path");
                context.Errors["base.path"].Should().HaveCount(2);
                context.Errors["base.path"].ElementAt(0).Should().Be(666);
                context.Errors["base.path"].ElementAt(1).Should().Be(667);
                context.Errors["base.path.nested"].Should().HaveCount(1);
                context.Errors["base.path.nested"].ElementAt(0).Should().Be(668);

                context.ReferenceLoopRoots.Should().HaveCount(2);
                context.ReferenceLoopRoots.Should().Contain("base.path");
                context.ReferenceLoopRoots.Should().Contain("base.path.nested");
            }