コード例 #1
0
        public void Failed_WithErrorCode_ReturnsResultWithSameErrorCode()
        {
            var errorCode     = new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String());
            var expectedError = new ExecutionError(errorCode);

            CreationResult.Failed <DummyEntry>(errorCode)
            .Should().BeEquivalentTo(new CreationResult <DummyEntry>(expectedError));
        }
コード例 #2
0
        public void ForCommand_ResultWithErrors_ShouldReturnErrorWithCorrectSource()
        {
            var errorCode      = new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String());
            var creationResult = CreationResult.Failed <DummyEntry>(errorCode);

            var result = creationResult.ForCommand <DummyEntry, FakeCreateCommand>(c => c.Data);

            result.Entry.Should().BeNull();

            var internalError = result.Errors.Single();

            internalError.CodeInfo.Should().Be(errorCode);
            internalError.Code.Should().Be(errorCode.Code);
            internalError.Message.Should().Be(errorCode.Message);
            internalError.Source.Should().Be(SourceBuilder.BuildErrorSource <FakeCreateCommand>(c => c.Data));
        }
コード例 #3
0
        public void WithSource_FailedResultWithShorterSource_ShouldReturnCorrectSource()
        {
            var errorCode      = new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String());
            var creationResult = CreationResult.Failed <DummyEntry>(errorCode);

            var result = creationResult
                         .ForCommand <DummyEntry, FakeCreateCommand>(c => c.SomeArray[0].SomeInternalArray[0].SomeInt)
                         .WithSource <DummyEntry, FakeCreateCommand>(c => c.SomeArray[3]);

            result.Entry.Should().BeNull();

            var internalError = result.Errors.Single();

            internalError.CodeInfo.Should().Be(errorCode);
            internalError.Code.Should().Be(errorCode.Code);
            internalError.Message.Should().Be(errorCode.Message);
            internalError.Source.Should().Be("FakeCreateCommand.SomeArray.3.SomeInternalArray.0.SomeInt");
        }
コード例 #4
0
        public void ForCommand_ResultWith2Errors_ShouldReturn2Errors()
        {
            var errorCode      = new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String());
            var creationResult = CreationResult.Failed <DummyEntry>(errorCode);

            var result = creationResult
                         .ForCommand <DummyEntry, FakeCreateCommand>(c => c)
                         .ForCommand <DummyEntry, FakeCreateCommand>(c => c.Data);

            result.Entry.Should().BeNull();
            result.Errors.Count.Should().Be(2);

            var expectedError1 = new ExecutionError(errorCode, SourceBuilder.BuildErrorSource <FakeCreateCommand>(c => c));
            var expectedError2 = new ExecutionError(errorCode, SourceBuilder.BuildErrorSource <FakeCreateCommand>(c => c.Data));

            result.Errors.Should().ContainEquivalentOf(expectedError1);
            result.Errors.Should().ContainEquivalentOf(expectedError2);
        }