public void Should_ConstructErrorCodeAndMessages_And_RegisterItInContext_And_SetItsId(object cmds, IError error) { var registrationsCount = 0; var context = Substitute.For <IScopeBuilderContext>(); context.RegisterError(Arg.Any <IError>()).Returns(info => { var registeredError = info.Arg <IError>(); registeredError.ShouldBeEqualTo(error); registrationsCount++; return(666); }); var builder = new RuleCommandScopeBuilder <TestClass>(new RuleCommand <TestClass>(x => true)); var commands = (ICommand[])cmds; foreach (var command in commands) { builder.TryAdd(command); } var builtScope = (ICommandScope <TestClass>)builder.Build(context); builtScope.ErrorId.Should().Be(666); registrationsCount.Should().Be(1); }
public void Should_ThrowException_When_NullCommand() { var command = new RuleCommand <TestClass>(x => true); var builder = new RuleCommandScopeBuilder <TestClass>(command); Action action = () => builder.TryAdd(null); action.Should().ThrowExactly <ArgumentNullException>(); }
public void Should_ReturnRuleCommandScope() { var command = new RuleCommand <TestClass>(x => true); var context = Substitute.For <IScopeBuilderContext>(); var builder = new RuleCommandScopeBuilder <TestClass>(command); var builtScope = builder.Build(context); builtScope.Should().BeOfType <RuleCommandScope <TestClass> >(); }
public void Should_ReturnTrue_And_SetName_When_WithPathCommand() { var context = Substitute.For <IScopeBuilderContext>(); var command = new WithPathCommand("some_path"); var builder = new RuleCommandScopeBuilder <TestClass>(new RuleCommand <TestClass>(x => true)); var tryAddResult = builder.TryAdd(command); tryAddResult.Should().BeTrue(); var builtScope = (ICommandScope <TestClass>)builder.Build(context); builtScope.Path.Should().Be("some_path"); }
public void Should_ReturnTrue_And_SetCondition_When_WithConditionCommand() { Predicate <object> condition = o => true; var context = Substitute.For <IScopeBuilderContext>(); var command = new WithConditionCommand <TestClass>(condition); var builder = new RuleCommandScopeBuilder <TestClass>(new RuleCommand <TestClass>(x => true)); var tryAddResult = builder.TryAdd(command); tryAddResult.Should().BeTrue(); var builtScope = (ICommandScope <TestClass>)builder.Build(context); builtScope.ExecutionCondition.Should().BeSameAs(condition); }
public void Should_ReturnRuleCommandScope_WithIsValidPredicate() { Predicate <TestClass> predicate = x => true; var command = new RuleCommand <TestClass>(predicate); var context = Substitute.For <IScopeBuilderContext>(); var builder = new RuleCommandScopeBuilder <TestClass>(command); var builtScope = builder.Build(context); builtScope.Should().BeOfType <RuleCommandScope <TestClass> >(); var ruleCommandScope = (RuleCommandScope <TestClass>)builtScope; ruleCommandScope.IsValid.Should().Be(predicate); }
public void Should_SetOverrideMode(object cmds, IError error) { _ = error; var context = Substitute.For <IScopeBuilderContext>(); context.RegisterError(Arg.Any <IError>()).Returns(info => 666); var builder = new RuleCommandScopeBuilder <TestClass>(new RuleCommand <TestClass>(x => true)); var commands = (ICommand[])cmds; foreach (var command in commands) { builder.TryAdd(command); } var builtScope = (ICommandScope <TestClass>)builder.Build(context); builtScope.ErrorMode.Should().Be(ErrorMode.Override); }
public void Should_ThrowException_When_NullContext() { Action action = () => _ = new RuleCommandScopeBuilder <TestClass>(null); action.Should().ThrowExactly <ArgumentNullException>(); }