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(); }); }
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);
public void Should_Initialize_WithDefaultValues() { var commandScope = new CollectionCommandScope <TestCollection <TestItem>, TestItem>(); commandScope.ShouldHaveDefaultValues(); }
public void Should_Initialize() { _ = new CollectionCommandScope <TestCollection <TestItem>, TestItem>(); }