예제 #1
0
        /// <summary>
        /// Call this method to create an instance representing the result of a failed operation.
        /// </summary>
        /// <param name="errors">All the detected errors</param>
        /// <exception cref="ArgumentNullException">Throws ArgumentNullException when parameter errors is null</exception>
        /// <returns>An instance representing the result of a failed operation.</returns>
        public static OperationResult <TOutput, TError> CreateFailure(NonEmptySequence <TError> errors)
        {
            if (errors == null)
            {
                throw new ArgumentNullException(nameof(errors));
            }

            return(new OperationResult <TOutput, TError>(default, errors));
        public void Error_Does_Not_Throw_When_Operation_Is_Failed_With_Several_Errors()
        {
            // ARRANGE
            var errors = new NonEmptySequence <string>(new[] { "something bad happened!", "kaboom!" });
            var target = OperationResult <string, string> .CreateFailure(errors);

            // ACT
            Assert.DoesNotThrow(() => _ = target.Error);
        }
        public void Error_Returns_First_Error_When_Operation_Is_Failed_With_Several_Errors()
        {
            // ARRANGE
            var errors = new NonEmptySequence <string>(new[] { "something bad happened!", "kaboom!" });
            var target = OperationResult <string, string> .CreateFailure(errors);

            // ACT
            var result = target.Error;

            // ASSERT
            Assert.AreEqual("something bad happened!", result);
        }
예제 #4
0
        public void Ctor_Creates_An_Enumerable_Instance()
        {
            // ARRANGE
            var items = new[] { "foo", "bar" };

            // ACT
            var result = new NonEmptySequence <string>(items);

            // ASSERT
            Assert.IsNotNull(result);
            CollectionAssert.AreEqual(new[] { "foo", "bar" }, result);
        }
        public void CreateFailure_Throws_When_Errors_Is_Null()
        {
            // ARRANGE
            NonEmptySequence <string> nullSequence = null;

            // ACT
            var exception = Assert.Throws <ArgumentNullException>(() =>
                                                                  OperationResult <string, string> .CreateFailure(nullSequence)
                                                                  );

            // ASSERT
            Assert.IsNotNull(exception);
            Assert.AreEqual("errors", exception.ParamName);
        }