コード例 #1
0
        public void ShouldCreateValidRequestResult()
        {
            var requestForTest = new RequestForTest(value: "test");

            var result = RequestValidationResult <RequestForTest, Error> .CreateValidResult(
                result : requestForTest
                );

            Assert.IsTrue(result.IsValid);
            Assert.AreEqual(result.Result.Value, requestForTest.Value);
            Assert.AreEqual(result.Errors.Count, 0);
        }
コード例 #2
0
        public static RequestValidationResult <UserSignUpRequest, Error> Create(
            string email,
            string password)
        {
            CreationResult <Email, Error>    emailCreationResult    = Email.CreateAndValidate(value: email);
            CreationResult <Password, Error> passwordCreationResult = Password.CreateAndValidate(value: password);

            var errors = BuilValidationErrorsFrom <Email, Error>(creationResult: emailCreationResult, fieldId: nameof(Email))
                         .Concat(BuilValidationErrorsFrom <Password, Error>(creationResult: passwordCreationResult, fieldId: nameof(Password)))
                         .ToList();

            if (errors.Any())
            {
                return(RequestValidationResult <UserSignUpRequest, Error> .CreateInvalidResult(
                           errors : errors.AsReadOnly()
                           ));
            }

            UserSignUpRequest request = new UserSignUpRequest(
                email: emailCreationResult.Result,
                password: passwordCreationResult.Result);

            return(RequestValidationResult <UserSignUpRequest, Error> .CreateValidResult(result : request));
        }