示例#1
0
        public void CtorCtnValue_NullCtn_ThrowsArgumentNullException()
        {
            Ctn <int> value = null;
            Action    go    = () => new Pipe <int>(value);

            go.Should().ThrowExactly <ArgumentNullException>().WithMessage($"Value cannot be null.{Environment.NewLine}Parameter name: containerOfValue");
        }
示例#2
0
        public void ToString_WithCtnDefaultValue_ReturnsCorrectString()
        {
            Pipe <int> pipe   = new Ctn <int>(DefaultValue, None);
            var        result = pipe.ToString();

            result.Should().Be("Container of (BddPipe.Ctn`1[System.Int32])");
        }
示例#3
0
        public void Map_ScenarioTitleNone_ScenarioTitleRemainsAsNone()
        {
            var newCtn = new Ctn <int>(DefaultValue, None)
                         .Map(value => true);

            newCtn.ScenarioTitle.ShouldBeNone();
        }
示例#4
0
        public void Map_ThrowsInconclusiveException_PipeIsInErrorStateWithInconclusive(bool isAsync)
        {
            const string initalValue   = "initial-value";
            const string scenarioTitle = "scenario-title";
            const string givenStepText = "given-step";

            Pipe <string> pipe = new Ctn <string>(initalValue, new[]
            {
                new StepOutcome(Step.Given, Outcome.Pass, givenStepText)
            }, scenarioTitle);

            Pipe <int> result;

            if (isAsync)
            {
                result = pipe.Map(PipeMapFunctions.MapAsyncRaiseInconclusiveEx());
            }
            else
            {
                result = pipe.Map(PipeMapFunctions.MapSyncRaiseInconclusiveEx());
            }

            result.ShouldBeError(ctnError =>
            {
                ctnError.ScenarioTitle.ShouldBeSome(title => title.Should().Be(scenarioTitle));
                ctnError.Content.Should().NotBeNull();
                ctnError.Content.SourceException.Should().NotBeNull();
                ctnError.Content.SourceException.Should().BeOfType <InconclusiveException>();
                ctnError.StepOutcomes.ShouldHaveSingleStepOutcome(Outcome.Inconclusive, givenStepText, Step.Given);
            });
        }
示例#5
0
        public void Map_OutcomesEmptyViaDefaultCtor_OutcomesRemainsAsEmpty()
        {
            var newCtn = new Ctn <int>(DefaultValue, None)
                         .Map(value => true);

            newCtn.StepOutcomes.Should().NotBeNull();
            newCtn.StepOutcomes.Should().BeEmpty();
        }
示例#6
0
 private void CtnShouldHaveValueState <T>(Ctn <T> ctnValue, T expectedValue)
 {
     ctnValue.Should().NotBeNull();
     ctnValue.Content.Should().Be(expectedValue);
     ctnValue.Should().NotBeNull();
     ctnValue.ScenarioTitle.ShouldBeNone();
     ctnValue.StepOutcomes.Should().BeEmpty();
 }
示例#7
0
        public void ToString_WithCtnError_ReturnsCorrectString()
        {
            var        exInfo = ExceptionDispatchInfo.Capture(new ApplicationException("test error"));
            Pipe <int> pipe   = new Ctn <ExceptionDispatchInfo>(exInfo, None);
            var        result = pipe.ToString();

            result.Should().Be("Container of (BddPipe.Ctn`1[System.Runtime.ExceptionServices.ExceptionDispatchInfo])");
        }
示例#8
0
        public void ToResult_StepOutcomesEmpty_StepResultsEmpty()
        {
            var ctn            = new Ctn <int>(DefaultValue, None);
            var scenarioResult = ctn.ToResult();

            scenarioResult.Should().NotBeNull();
            scenarioResult.StepResults.Should().NotBeNull();
            scenarioResult.StepResults.Should().BeEmpty();
        }
示例#9
0
        public void CtorCtnValue_WithCtnValue_IsInValueState()
        {
            Ctn <int> value = new Ctn <int>(DefaultValue, None);
            var       pipe  = new Pipe <int>(value);

            pipe.ShouldBeSuccessful(p =>
            {
                p.Content.Should().Be(DefaultValue);
            });
        }
示例#10
0
        public void CtorCtnException_NullCtnViaImplicit_ThrowsArgumentNullException()
        {
            Ctn <ExceptionDispatchInfo> value = null;
            Action go = () =>
            {
                Pipe <int> pipe = value;
            };

            go.Should().ThrowExactly <ArgumentNullException>().WithMessage($"Value cannot be null.{Environment.NewLine}Parameter name: containerOfError");
        }
示例#11
0
        public void Ctor_NullReferenceType_DoesNotThrow()
        {
            var ctn = new Ctn <string>(null, None);

            ctn.Should().NotBeNull();
            ctn.Content.Should().Be(null);
            ctn.StepOutcomes.Should().NotBeNull();
            ctn.StepOutcomes.Count.Should().Be(0);
            ctn.ScenarioTitle.ShouldBeNone();
        }
示例#12
0
        public void Ctor_NoTitle_CreatesCtnCorrectly()
        {
            var ctn = new Ctn <int>(DefaultValue, None);

            ctn.Should().NotBeNull();
            ctn.Content.Should().Be(DefaultValue);
            ctn.StepOutcomes.Should().NotBeNull();
            ctn.StepOutcomes.Count.Should().Be(0);
            ctn.ScenarioTitle.ShouldBeNone();
        }
示例#13
0
        public void Ctor_TitleAndList_CreatesCtnCorrectly()
        {
            var ctn = new Ctn <int>(DefaultValue, new List <StepOutcome>(), ScenarioTitle);

            ctn.Should().NotBeNull();
            ctn.Content.Should().Be(DefaultValue);
            ctn.StepOutcomes.Should().NotBeNull();
            ctn.StepOutcomes.Count.Should().Be(0);
            ctn.ScenarioTitle.ShouldBeSome(title => title.Should().Be(ScenarioTitle));
        }
示例#14
0
        public void ToResult_ScenarioTitleNone_TitleIsNullDescriptionIsPrefix()
        {
            var ctn            = new Ctn <int>(DefaultValue, None);
            var scenarioResult = ctn.ToResult();

            scenarioResult.Should().NotBeNull();
            scenarioResult.StepResults.Should().NotBeNull();
            scenarioResult.Title.Should().BeNull();
            scenarioResult.Description.Should().Be("Scenario:");
        }
示例#15
0
        public void CtorCtnValue_WithCtnValueViaImplicit_IsInValueState()
        {
            Ctn <int>  value = new Ctn <int>(DefaultValue, None);
            Pipe <int> pipe  = value; // lift via implicit operator

            pipe.ShouldBeSuccessful(p =>
            {
                p.Content.Should().Be(DefaultValue);
            });
        }
示例#16
0
        public void ToResult_ScenarioTitleSet_TitleIsSetDescriptionIsSet()
        {
            var ctn            = new Ctn <int>(DefaultValue, ScenarioTitle);
            var scenarioResult = ctn.ToResult();

            scenarioResult.Should().NotBeNull();
            scenarioResult.StepResults.Should().NotBeNull();
            scenarioResult.Title.Should().Be(ScenarioTitle);
            scenarioResult.Description.Should().Be($"Scenario: {ScenarioTitle}");
        }
示例#17
0
        public void Map_ScenarioTitleSome_ScenarioTitleRemainsAsSome()
        {
            const string scenarioTitle = "scenario title value";

            var newCtn = new Ctn <int>(DefaultValue, scenarioTitle)
                         .Map(value => true);

            newCtn.ScenarioTitle.ShouldBeSome(title =>
                                              title.Should().Be(scenarioTitle)
                                              );
        }
示例#18
0
        public void Map_FunctionToValueOfSameType_MapsCorrectly()
        {
            var ctnWithValueOnly = new Ctn <int>(DefaultValue, None);
            var newCtn           = ctnWithValueOnly.Map(currentValue => currentValue + 1);

            newCtn.Should().NotBeNull();
            newCtn.Content.Should().Be(DefaultValue + 1);
            newCtn.ScenarioTitle.ShouldBeNone();
            newCtn.StepOutcomes.Should().NotBeNull();
            newCtn.StepOutcomes.Count.Should().Be(0);
        }
示例#19
0
        public void Map_FromCtnIntToCtnBool_ChangesContent()
        {
            var fnMap = Substitute.For <Func <int, bool> >();

            fnMap(Arg.Any <int>()).Returns(true);

            var newCtn = new Ctn <int>(DefaultValue, None)
                         .Map(fnMap);

            newCtn.Content.Should().BeTrue();
        }
示例#20
0
        public void Map_FromCtnWithNoStepOutcomes_MapsToNewCtnType()
        {
            var ctnWithValueOnly = new Ctn <int>(DefaultValue, None);
            var newCtn           = ctnWithValueOnly.Map(currentValue => currentValue.ToString());

            newCtn.Should().NotBeNull();
            newCtn.Content.Should().Be(DefaultValue.ToString());
            newCtn.ScenarioTitle.ShouldBeNone();
            newCtn.StepOutcomes.Should().NotBeNull();
            newCtn.StepOutcomes.Count.Should().Be(0);
        }
示例#21
0
 private void CtnExceptionShouldHaveErrorState(Ctn <ExceptionDispatchInfo> ctnEx)
 {
     ctnEx.Should().NotBeNull();
     ctnEx.Content.Should().NotBeNull();
     ctnEx.Content.SourceException.Should().NotBeNull();
     ctnEx.Content.SourceException.GetType().Should().Be <ApplicationException>();
     ctnEx.Content.SourceException.Message.Should().Be(ErrorMessage);
     ctnEx.Should().NotBeNull();
     ctnEx.ScenarioTitle.ShouldBeNone();
     ctnEx.StepOutcomes.Should().BeEmpty();
 }
示例#22
0
        internal Pipe(Ctn <T> containerOfValue)
        {
            if (containerOfValue == null)
            {
                throw new ArgumentNullException(nameof(containerOfValue));
            }

            IsRight           = true;
            _containerOfValue = containerOfValue;
            _containerOfError = default(Ctn <ExceptionDispatchInfo>);
            _isInitialized    = true;
        }
示例#23
0
        public void Ctor_StepOutcomesNull_ThrowsArgumentNullException()
        {
            Action create = () =>
            {
                var ctn = new Ctn <int>(DefaultValue, null, None);
            };

            create
            .Should()
            .ThrowExactly <ArgumentNullException>()
            .WithMessage($"Value cannot be null.{Environment.NewLine}Parameter name: stepOutcomes");
        }
示例#24
0
        public void CtorCtnException_WithCtnException_IsInErrorState()
        {
            var ex     = new ApplicationException("test message");
            var exInfo = ExceptionDispatchInfo.Capture(ex);
            Ctn <ExceptionDispatchInfo> value = new Ctn <ExceptionDispatchInfo>(exInfo, None);
            var pipe = new Pipe <int>(value);

            pipe.ShouldBeError(error =>
            {
                error.Content.Should().Be(exInfo);
            });
        }
示例#25
0
        public void Match_WithFuncCtnDefaultValue_CallsFuncCtnT()
        {
            Pipe <int> pipe = new Ctn <int>(DefaultValue, None);

            var fnCtnT     = Substitute.For <Func <Ctn <int>, Unit> >();
            var fnCtnError = Substitute.For <Func <Ctn <ExceptionDispatchInfo>, Unit> >();

            pipe.Match(fnCtnT, fnCtnError);

            fnCtnT.Received()(Arg.Any <Ctn <int> >());
            fnCtnError.DidNotReceive();
        }
示例#26
0
        public void CtorCtnException_WithCtnExceptionViaImplicit_IsInErrorState()
        {
            var ex     = new ApplicationException("test message");
            var exInfo = ExceptionDispatchInfo.Capture(ex);
            Ctn <ExceptionDispatchInfo> value = new Ctn <ExceptionDispatchInfo>(exInfo, None);
            Pipe <int> pipe = value; // lift via implicit operator

            pipe.ShouldBeError(error =>
            {
                error.Content.Should().Be(exInfo);
            });
        }
示例#27
0
        public void Map_ToNull_MapsToNewCtnType()
        {
            var ctnWithValueOnly = new Ctn <string>("initial value", None);

            const string newValue = null;
            var          newCtn   = ctnWithValueOnly.Map(currentValue => newValue);

            newCtn.Should().NotBeNull();
            newCtn.Content.Should().Be(newValue);
            newCtn.ScenarioTitle.ShouldBeNone();
            newCtn.StepOutcomes.Should().NotBeNull();
            newCtn.StepOutcomes.Count.Should().Be(0);
        }
示例#28
0
        public void Match_WithFuncCtnError_CallsFuncCtnError()
        {
            var        exInfo = ExceptionDispatchInfo.Capture(new ApplicationException("test error"));
            Pipe <int> pipe   = new Ctn <ExceptionDispatchInfo>(exInfo, None);

            var fnCtnT     = Substitute.For <Func <Ctn <int>, Unit> >();
            var fnCtnError = Substitute.For <Func <Ctn <ExceptionDispatchInfo>, Unit> >();

            pipe.Match(fnCtnT, fnCtnError);

            fnCtnT.DidNotReceive();
            fnCtnError.Received()(Arg.Any <Ctn <ExceptionDispatchInfo> >());
        }
示例#29
0
        public void Match_WithFuncCtnDefaultValue_ReturnsFuncOutput()
        {
            Pipe <int> pipe = new Ctn <int>(DefaultValue, None);

            var fnCtnError = Substitute.For <Func <Ctn <ExceptionDispatchInfo>, string> >();

            const string resultText = "some result";
            var          result     = pipe.Match(ctnInt => resultText, fnCtnError);

            result.Should().Be(resultText);

            fnCtnError.DidNotReceive();
        }
示例#30
0
        public void Map_FromNull_MapsToNewCtnType()
        {
            var ctnWithValueOnly = new Ctn <string>(null, None);

            decimal newValue = 12.45m;
            var     newCtn   = ctnWithValueOnly.Map(currentValue => newValue);

            newCtn.Should().NotBeNull();
            newCtn.Content.Should().Be(newValue);
            newCtn.ScenarioTitle.ShouldBeNone();
            newCtn.StepOutcomes.Should().NotBeNull();
            newCtn.StepOutcomes.Count.Should().Be(0);
        }