Exemplo n.º 1
0
        public void Should_RunDiscovery(bool?shouldExecuteInfo, int?errorId, object errorModeBoxed, string path)
        {
            var commandScope = new CollectionCommandScope <TestCollection <TestItem>, TestItem>();

            commandScope.ExecutionCondition = !shouldExecuteInfo.HasValue
                ? (Predicate <TestCollection <TestItem> >)null
                : m =>
            {
                return(shouldExecuteInfo.Value);
            };

            commandScope.ErrorId = errorId;

            commandScope.ErrorMode = (ErrorMode)errorModeBoxed;

            commandScope.Path = path;

            commandScope.ScopeId = 123;

            var discoveryContext = Substitute.For <IDiscoveryContext>();

            commandScope.ShouldDiscover(discoveryContext, context =>
            {
                context.Received().EnterCollectionItemPath();
                context.Received().EnterScope <TestItem>(Arg.Is(123));
                context.Received().LeavePath();
            });
        }
Exemplo n.º 2
0
        public void Should_RunValidation_OnReferenceTypeItem(bool?shouldExecuteInfo, int?errorId, object errorModeBoxed, string path, int itemsCount)
        {
            var commandScope = new CollectionCommandScope <TestCollection <TestItem>, TestItem>();

            var items = Enumerable.Range(0, itemsCount).Select(i => new TestItem()).ToList();

            var model = new TestCollection <TestItem>(items);

            var shouldExecuteCount = 0;

            commandScope.ExecutionCondition = !shouldExecuteInfo.HasValue
                ? (Predicate <TestCollection <TestItem> >)null
                : m =>
            {
                m.Should().BeSameAs(model);
                shouldExecuteCount++;

                return(shouldExecuteInfo.Value);
            };

            commandScope.ErrorId = errorId;

            commandScope.ErrorMode = (ErrorMode)errorModeBoxed;

            commandScope.Path = path;

            commandScope.ScopeId = 123;

            var validationContext = Substitute.For <IValidationContext>();

            var itemScope = Substitute.For <IValidatable <TestItem> >();

            commandScope.ShouldValidate(
                model,
                validationContext,
                shouldExecuteInfo,
                context =>
            {
                for (var i = 0; i < itemsCount; ++i)
                {
                    context.Received().EnterCollectionItemPath(Arg.Is(i));
                    context.Received().EnterScope(Arg.Is(123), Arg.Is(items[i]));
                    context.Received().LeavePath();
                }
            });

            if (itemsCount == 0)
            {
                validationContext.DidNotReceiveWithAnyArgs().EnterCollectionItemPath(default);
Exemplo n.º 3
0
        public void Should_Initialize_WithDefaultValues()
        {
            var commandScope = new CollectionCommandScope <TestCollection <TestItem>, TestItem>();

            commandScope.ShouldHaveDefaultValues();
        }
Exemplo n.º 4
0
 public void Should_Initialize()
 {
     _ = new CollectionCommandScope <TestCollection <TestItem>, TestItem>();
 }