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));
        }
        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));
        }
        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");
        }
        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);
        }