Пример #1
0
        public void Requires_unique_UserName_and_Email()
        {
            var mock             = new Mock <IUserAuthRepository>();
            var mockExistingUser = new UserAuth();

            mock.Expect(x => x.GetUserAuthByUserName(It.IsAny <string>()))
            .Returns(mockExistingUser);

            var service = new RegistrationService {
                RegistrationValidator = new RegistrationValidator {
                    UserAuthRepo = mock.Object
                },
                UserAuthRepo            = mock.Object,
                ServiceExceptionHandler = (req, ex) =>
                                          ValidationFeature.HandleException(new BasicResolver(), req, ex)
            };

            var request = new Registration {
                DisplayName = "DisplayName",
                Email       = "*****@*****.**",
                FirstName   = "FirstName",
                LastName    = "LastName",
                Password    = "******",
                UserName    = "******",
            };

            var response = (HttpError)service.Post(request);
            var errors   = response.GetFieldErrors();

            Assert.That(errors.Count, Is.EqualTo(2));
            Assert.That(errors[0].ErrorCode, Is.EqualTo("AlreadyExists"));
            Assert.That(errors[0].FieldName, Is.EqualTo("UserName"));
            Assert.That(errors[1].ErrorCode, Is.EqualTo("AlreadyExists"));
            Assert.That(errors[1].FieldName, Is.EqualTo("Email"));
        }
Пример #2
0
        public AuthService GetAuthService()
        {
            var authService = new AuthService {
                RequestContext          = new MockRequestContext(),
                ServiceExceptionHandler = (req, ex) =>
                                          ValidationFeature.HandleException(new BasicResolver(), req, ex)
            };

            return(authService);
        }
Пример #3
0
        public static RegistrationService GetRegistrationService(
            AbstractValidator <Registration> validator = null,
            IUserAuthRepository authRepo = null)
        {
            var requestContext = new MockRequestContext();
            var service        = new RegistrationService {
                RegistrationValidator = validator ?? new RegistrationValidator {
                    UserAuthRepo = GetStubRepo()
                },
                UserAuthRepo            = authRepo ?? GetStubRepo(),
                RequestContext          = requestContext,
                ServiceExceptionHandler = (req, ex) =>
                                          ValidationFeature.HandleException(new BasicResolver(), req, ex)
            };

            return(service);
        }
Пример #4
0
 public override object HandleException(IRequestContext requestContext, T request, System.Exception ex)
 {
     return(ValidationFeature.HandleException(new BasicResolver(), request, ex));
 }