public async void TestGpidValidation_MultiMatch()
        {
            // Arrange
            var service  = CreateService();
            var enrollee = TestDb.HasAnEnrollee("default,status.editable");

            enrollee.PhoneExtension = "123";
            var request = new GpidValidationParameters()
            {
                LastName       = enrollee.LastName,
                Phone          = enrollee.Phone,
                PhoneExtension = enrollee.PhoneExtension + "6"
            };

            // Act
            var response = await service.ValidateProvisionerDataAsync(enrollee.GPID, request);

            // Assert
            Assert.NotNull(response);
            Assert.True(response.AllPropertiesNullExcept(
                            nameof(response.LastName),
                            nameof(response.Phone),
                            nameof(response.PhoneExtension)));
            Assert.Equal(GpidValidationResponse.MatchText, response.LastName);
            Assert.Equal(GpidValidationResponse.MatchText, response.Phone);
            Assert.Equal(GpidValidationResponse.NoMatchText, response.PhoneExtension);
        }
        public async void TestGpidValidation_MatchesEmail()
        {
            // Arrange
            var service  = CreateService();
            var enrollee = TestDb.HasAnEnrollee("default,status.editable");
            var request  = new GpidValidationParameters()
            {
                Email = enrollee.Email
            };

            // Act
            var response = await service.ValidateProvisionerDataAsync(enrollee.GPID, request);

            // Assert
            Assert.NotNull(response);
            Assert.True(response.AllPropertiesNullExcept(nameof(response.Email)));
            Assert.Equal(GpidValidationResponse.MatchText, response.Email);
        }
        public async void TestGpidValidation_NoParams()
        {
            // Arrange
            var service  = CreateService();
            var enrollee = TestDb.HasAnEnrollee("default,status.editable");
            var request  = new GpidValidationParameters();

            // Act
            var response = await service.ValidateProvisionerDataAsync(enrollee.GPID, request);

            // Assert
            Assert.NotNull(response);
            foreach (var property in typeof(GpidValidationParameters).GetProperties())
            {
                var responseProp = typeof(GpidValidationResponse).GetProperty(property.Name);
                Assert.NotNull(responseProp);
                Assert.Null(responseProp.GetValue(response));
            }
        }
        public async void TestGpidValidation_Birthdate(bool requestMatches)
        {
            // Arrange
            var service  = CreateService();
            var enrollee = TestDb.HasAnEnrollee("default,status.editable");
            var request  = new GpidValidationParameters()
            {
                DateOfBirth = enrollee.DateOfBirth.AddDays(requestMatches ? 0 : 2)
            };
            var expectedText = requestMatches ? GpidValidationResponse.MatchText : GpidValidationResponse.NoMatchText;

            // Act
            var response = await service.ValidateProvisionerDataAsync(enrollee.GPID, request);

            // Assert
            Assert.NotNull(response);
            Assert.True(response.AllPropertiesNullExcept(nameof(response.DateOfBirth)));
            Assert.Equal(expectedText, response.DateOfBirth);
        }
        public async void TestGpidValidation_NoMatch()
        {
            // Arrange
            var service  = CreateService();
            var enrollee = TestDb.HasAnEnrollee("default,status.editable");

            enrollee.SmsPhone = null;
            var request = new GpidValidationParameters()
            {
                MobilePhone = "1-800-COOL-ENROLLEE"
            };

            // Act
            var response = await service.ValidateProvisionerDataAsync(enrollee.GPID, request);

            // Assert
            Assert.NotNull(response);
            Assert.True(response.AllPropertiesNullExcept(nameof(response.MobilePhone)));
            Assert.Equal(GpidValidationResponse.MissingText, response.MobilePhone);
        }
        public async void TestGpidValidation_Certifications()
        {
            // Arrange
            var service  = CreateService();
            var enrollee = TestDb.HasAnEnrollee("default,status.editable");

            enrollee.Certifications = new Certification[]
            {
                new Certification
                {
                    License = new License
                    {
                        Prefix = "91"
                    },
                    LicenseNumber = "11111"
                },
                new Certification
                {
                    License = new License
                    {
                        Prefix = "P1"
                    },
                    LicenseNumber = "22222"
                },
                new Certification
                {
                    License = new License
                    {
                        Prefix = "96"
                    },
                    LicenseNumber = "33333"
                }
            };

            var matchingRecord = new GpidValidationParameters.CollegeRecord
            {
                CollegeName = "P1",
                CollegeId   = "22222"
            };
            var nonMatchingRecord = new GpidValidationParameters.CollegeRecord
            {
                CollegeName = "96",
                CollegeId   = "77777"
            };
            var request = new GpidValidationParameters()
            {
                CollegeRecords = new[] { matchingRecord, nonMatchingRecord }
            };

            // Act
            var response = await service.ValidateProvisionerDataAsync(enrollee.GPID, request);

            // Assert
            Assert.NotNull(response);
            Assert.True(response.AllPropertiesNullExcept(nameof(response.CollegeRecords)));
            Assert.Equal(request.CollegeRecords.Count(), response.CollegeRecords.Count());

            var matchingResponse = response.CollegeRecords.Single(c => c.CollegeName == matchingRecord.CollegeName && c.CollegeId == matchingRecord.CollegeId);

            Assert.Equal(GpidValidationResponse.MatchText, matchingResponse.Match);

            var nonMatchingResponse = response.CollegeRecords.Single(c => c.CollegeName == nonMatchingRecord.CollegeName && c.CollegeId == nonMatchingRecord.CollegeId);

            Assert.Equal(GpidValidationResponse.NoMatchText, nonMatchingResponse.Match);
        }
Ejemplo n.º 7
0
        public async Task <GpidValidationResponse> ValidateProvisionerDataAsync(string gpid, GpidValidationParameters parameters)
        {
            var enrollee = await _context.Enrollees
                           .Include(e => e.Certifications)
                           .ThenInclude(c => c.College)
                           .SingleOrDefaultAsync(e => e.GPID == gpid);

            if (enrollee == null)
            {
                return(null);
            }

            return(parameters.ValidateAgainst(enrollee));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <GpidValidationResponse> > ValidateGpid(string gpid, GpidValidationParameters parameters)
        {
            if (parameters == null)
            {
                return(BadRequest(ApiResponse.Message($"Must supply validation parameters")));
            }

            var response = await _enrolleeService.ValidateProvisionerDataAsync(gpid, parameters);

            if (response == null)
            {
                return(NotFound(ApiResponse.Message($"Enrollee not found with GPID {gpid}")));
            }

            return(Ok(ApiResponse.Result(response)));
        }