Ejemplo n.º 1
0
        public async Task ShouldCreateRegistration()
        {
            var registration = await DateOfBirth.Create(new DateTime(1980, 01, 01), _systemTimeProviderMock.Object)
                               .OnSuccess(dob => Candidate.Create("John", "Smith", dob))
                               .OnSuccess(candidate => Registration.CreateAsync(new ExternalRegistrationId(), new ExamId(10), new OrderId(10), candidate,
                                                                                _systemTimeProviderMock.Object, _registrationRepositoryMock.Object));

            registration.IsSuccess.Should().BeTrue();
        }
        public static Result <CreateRegistrationCommand> Create(CreateRegistrationRequest request,
                                                                ISystemTimeProvider systemTimeProvider, IExamExistenceValidator examExistenceValidator)
        {
            var candidateResult = DateOfBirth.Create(request.DateOfBirth, systemTimeProvider)
                                  .OnSuccess(dateOfBirth => Candidate.Create(request.FirstName, request.LastName, dateOfBirth));
            var examResult  = ExamId.Create(request.ExamId, examExistenceValidator);
            var buyerResult = ContactData.Create(request.Buyer?.Name, request.Buyer?.StreetAddress, request.Buyer?.City,
                                                 request.Buyer?.ZipCode);

            return(Result.Combine(candidateResult, examResult, buyerResult)
                   .OnSuccess(() =>
                              new CreateRegistrationCommand(candidateResult.Value, examResult.Value, buyerResult.Value)));
        }
Ejemplo n.º 3
0
        public async Task ShouldAddEventOnRegistrationCreation()
        {
            var registration = await DateOfBirth.Create(new DateTime(1980, 01, 01), _systemTimeProviderMock.Object)
                               .OnSuccess(dob => Candidate.Create("John", "Smith", dob))
                               .OnSuccess(candidate => Registration.CreateAsync(new ExternalRegistrationId(), new ExamId(10), new OrderId(10), candidate,
                                                                                _systemTimeProviderMock.Object, _registrationRepositoryMock.Object));

            registration.IsSuccess.Should().BeTrue();
            registration.Value.HasDomainEvents.Should().BeTrue();

            var flushed = registration.Value.FlushDomainEvents();

            flushed.Count().Should().Be(1);
        }
Ejemplo n.º 4
0
        private Result <Candidate> CreateCandidate(BulkUploadCandidate uploadCandidate, BulkUploadCandidateGuardian candidateGuardian)
        {
            Contracts.Require(uploadCandidate != null);
            Contracts.Require(candidateGuardian != null);
            var uc = uploadCandidate;

            var fullNameOrError        = FullName.Create(uc.FirstName, uc.LastName);
            var dobOrError             = DateOfBirth.Create(uc.DateOfBirth);
            var candidateNumberOrError = CandidateNumber.CreateOptional(uc.CandidateNumber);
            var phoneNumberOrError     = PhoneNumber.CreateOptional(uc.MobilePhoneNumber);

            return(Result.Combine(fullNameOrError, dobOrError, candidateNumberOrError, phoneNumberOrError)
                   .OnSuccess(() => Candidate.Create(fullNameOrError.Value, dobOrError.Value, uc.Gender))
                   .OnSuccess(x => x.SetCandidateNumber(candidateNumberOrError.Value))
                   .OnSuccess(x => x.SetUciNumber(uc.UCI))
                   .OnSuccess(x => x.SetPhoneNumber(phoneNumberOrError.Value)));
        }
Ejemplo n.º 5
0
        public void ShouldNotCreateDateOfBirthForFutureDates()
        {
            var dateOfBirth = DateOfBirth.Create(new DateTime(2030, 03, 01), _systemTimeProviderMock.Object);

            dateOfBirth.IsSuccess.Should().BeFalse();
        }
Ejemplo n.º 6
0
        public void ShouldCreateDateOfBirthForPastDates()
        {
            var dateOfBirth = DateOfBirth.Create(new DateTime(1980, 03, 01), _systemTimeProviderMock.Object);

            dateOfBirth.IsSuccess.Should().BeTrue();
        }
Ejemplo n.º 7
0
 static CandidateTests()
 {
     SystemTimeProviderMock.Setup(provider => provider.UtcNow)
     .Returns(() => new DateTime(2020, 03, 01));
     DateOfBirth = DateOfBirth.Create(new DateTime(1980, 01, 01), SystemTimeProviderMock.Object).Value;
 }