Пример #1
0
        public void ShouldCreateInvalidRequestResult()
        {
            var errors = new List <ValidationError <ErrorForTest> >
            {
                new ValidationError <ErrorForTest>(fieldId: "FieldId", error: ErrorForTest.AnyError)
            }.AsReadOnly();

            var result = RequestValidationResult <RequestForTest, ErrorForTest> .CreateInvalidResult(
                errors : errors
                );

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(result.Errors[0].FieldId, errors[0].FieldId);
            Assert.AreEqual(result.Errors[0].Error, errors[0].Error);
            Assert.AreEqual(result.Errors.Count, 1);
        }
Пример #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));
        }