コード例 #1
0
        public void If_candidate_has_resigned_temporarily_with_resume_date__then_HasResignedEffectively_with_current_date_returns_true()
        {
            // Arrange
            var id     = EnrollmentAggregate.EnrollmentId.New;
            var event1 = new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, RecruitmentFormSubmitted>(
                new RecruitmentFormSubmitted(
                    NodaTime.SystemClock.Instance.GetCurrentInstant(),
                    "Andrzej", "Strzelba",
                    EmailAddress.Parse("*****@*****.**"), Consts.FakePhoneNumber,
                    "ala ma kota", 1, "Wolne Miasto Gdańsk", new[] { "Wadowice" }, new[] { 1 }, true),
                new Metadata(), DateTimeOffset.Now, id, 1
                );
            var enrollment = new EnrollmentAggregate(id);

            enrollment.ApplyEvents(new IDomainEvent[] { event1 });

            var recordingCoordinator = new ApplicationUser()
            {
                Id = Guid.NewGuid()
            };
            var currentDate = new NodaTime.LocalDate(2020, 06, 30);

            // Act
            var result = enrollment.RecordResignation(new RecordResignation.Command()
            {
                EnrollmentId         = id.GetGuid(),
                CommunicationChannel = CommunicationChannel.OutgoingEmail,
                ResignationReason    = "brak powodu",
                AdditionalNotes      = "notatka testowa",
                ResignationType      = RecordResignation.ResignationType.Temporary,
                ResumeDate           = currentDate.PlusWeeks(1)
            },
                                                      recordingCoordinator,
                                                      currentDate.AtStartOfDayInZone(Consts.MainTimezone).ToInstant());

            // Assert
            Assert.True(result.IsSuccess);
            var uncommittedEvent = Assert.Single(enrollment.UncommittedEvents, e => e.AggregateEvent is CandidateResignedTemporarily);
            var @event           = Assert.IsType <CandidateResignedTemporarily>(uncommittedEvent.AggregateEvent);

            Assert.Equal(recordingCoordinator.Id, @event.RecordingCoordinatorID);
            Assert.Equal(CommunicationChannel.OutgoingEmail, @event.CommunicationChannel);
            Assert.Equal("brak powodu", @event.ResignationReason);
            Assert.Equal("notatka testowa", @event.AdditionalNotes);
            Assert.Equal(currentDate.PlusWeeks(1), @event.ResumeDate);

            enrollment.HasResignedEffectively(currentDate.AtStartOfDayInZone(Consts.MainTimezone).ToInstant()).Should().BeTrue();
        }
コード例 #2
0
        public void ResumeDate_cannot_be_earlier_than_today()
        {
            // Arrange
            var id     = EnrollmentAggregate.EnrollmentId.New;
            var event1 = new DomainEvent <EnrollmentAggregate, EnrollmentAggregate.EnrollmentId, RecruitmentFormSubmitted>(
                new RecruitmentFormSubmitted(
                    NodaTime.SystemClock.Instance.GetCurrentInstant(),
                    "Andrzej", "Strzelba",
                    EmailAddress.Parse("*****@*****.**"), Consts.FakePhoneNumber,
                    "ala ma kota", 1, "Wolne Miasto Gdańsk", new[] { "Wadowice" }, new[] { 1 }, true),
                new Metadata(), DateTimeOffset.Now, id, 1
                );
            var enrollment = new EnrollmentAggregate(id);

            enrollment.ApplyEvents(new IDomainEvent[] { event1 });

            var recordingCoordinator = new ApplicationUser()
            {
                Id = Guid.NewGuid()
            };
            var currentDate = new NodaTime.LocalDate(2020, 06, 30);

            // Act
            var result = enrollment.RecordResignation(new RecordResignation.Command()
            {
                EnrollmentId         = id.GetGuid(),
                CommunicationChannel = CommunicationChannel.IncomingEmail,
                ResignationReason    = "brak powodu",
                AdditionalNotes      = "notatka testowa",
                ResignationType      = RecordResignation.ResignationType.Temporary,
                ResumeDate           = currentDate.Minus(Period.FromDays(1))
            },
                                                      recordingCoordinator,
                                                      currentDate.AtStartOfDayInZone(Consts.MainTimezone).ToInstant());

            // Assert
            Assert.False(result.IsSuccess);
            var error = Assert.IsType <Error.DomainError>(result.Error);

            error.Message.Should().BeEquivalentTo(RecordResignation_Messages.ResumeDateCannotBeEarlierThanToday);
        }