public void ShouldNotFindRegisteredDomainForInvalidEmail(string value)
        {
            var check = new RegisteredDomainCheck
            {
                Username = value
            };
            var service = new GraphAuthService(_registrationService);

            var result = Assert.Throws <HttpError>(() => service.Post(check));

            Assert.NotNull(result);
            Assert.IsAssignableFrom <HttpError>(result);
            Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
        }
        public void ShouldNotFindUnRegisteredDomain()
        {
            var check = new RegisteredDomainCheck
            {
                Username = "******"
            };
            var service = new GraphAuthService(_registrationService);

            var result = service.Post(check);

            Assert.NotNull(result);
            Assert.IsAssignableFrom <RegisteredDomainCheckResponse>(result);
            Assert.False(((RegisteredDomainCheckResponse)result).IsRegistered);
        }
예제 #3
0
        public object Post(RegisteredDomainCheck request)
        {
            if (string.IsNullOrWhiteSpace(request?.Username))
            {
                throw new HttpError(HttpStatusCode.BadRequest);
            }

            if (!EmailRegex.IsMatch(request.Username))
            {
                throw new HttpError(HttpStatusCode.BadRequest);
            }

            var idx          = request.Username.IndexOf("@", StringComparison.Ordinal);
            var isRegistered = _registry.ApplicationIsRegistered(request.Username.Substring(idx + 1));

            return(new RegisteredDomainCheckResponse
            {
                IsRegistered = isRegistered
            });
        }