Beispiel #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");
        }
Beispiel #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])");
        }
        public void Map_ScenarioTitleNone_ScenarioTitleRemainsAsNone()
        {
            var newCtn = new Ctn <int>(DefaultValue, None)
                         .Map(value => true);

            newCtn.ScenarioTitle.ShouldBeNone();
        }
Beispiel #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);
            });
        }
        public void Map_OutcomesEmptyViaDefaultCtor_OutcomesRemainsAsEmpty()
        {
            var newCtn = new Ctn <int>(DefaultValue, None)
                         .Map(value => true);

            newCtn.StepOutcomes.Should().NotBeNull();
            newCtn.StepOutcomes.Should().BeEmpty();
        }
Beispiel #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();
 }
Beispiel #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])");
        }
        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();
        }
Beispiel #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);
            });
        }
Beispiel #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");
        }
Beispiel #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();
        }
Beispiel #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();
        }
Beispiel #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));
        }
Beispiel #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:");
        }
Beispiel #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);
            });
        }
Beispiel #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}");
        }
Beispiel #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)
                                              );
        }
Beispiel #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);
        }
Beispiel #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();
        }
Beispiel #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);
        }
Beispiel #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();
 }
Beispiel #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;
        }
Beispiel #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");
        }
Beispiel #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);
            });
        }
Beispiel #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();
        }
Beispiel #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);
            });
        }
Beispiel #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);
        }
Beispiel #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> >());
        }
Beispiel #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();
        }
Beispiel #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);
        }