Esempio n. 1
0
        private void EnsureInvariants(MeetupState previous)
        {
            var valid = Id != MeetupId.None && Title != MeetupTitle.None &&
                        State switch
            {
                MeetupState.Published => RequiredFields(Published),
                MeetupState.Canceled => RequiredFields(Canceled),
                MeetupState.Closed => RequiredFields(Closed),
                _ => true
            };

            if (!valid)
            {
                throw new MeetupDomainException($"Invalid state {State}");
            }

            bool RequiredFields(Func <MeetupState[]> states) =>
            states().Any(s => s == previous) &&
            Location != Address.None &&
            NumberOfSeats != SeatsNumber.None &&
            TimeRange != DateTimeRange.None;

            MeetupState[] Published() => new[] { MeetupState.Published, MeetupState.Created };
            MeetupState[] Canceled() => new[] { MeetupState.Canceled, MeetupState.Published };
            MeetupState[] Closed() => new[] { MeetupState.Closed, MeetupState.Published };
        }
    }
Esempio n. 2
0
        public void Cancel()
        {
            var previous = State;

            State = MeetupState.Canceled;
            EnsureInvariants(previous);
        }
Esempio n. 3
0
 public Meetup(MeetupTitle title, Location location)
 {
     Title         = title;
     Location      = location;
     State         = MeetupState.Created;
     NumberOfSeats = NumberOfSeats.None;
 }
Esempio n. 4
0
        public void Publish()
        {
            var previous = State;

            State = MeetupState.Published;
            EnsureInvariants(previous);
        }
Esempio n. 5
0
        public void Close()
        {
            var previous = State;

            State = MeetupState.Closed;
            Console.WriteLine($"MeetupState previous {previous}, Current {State}");
            EnsureInvariants(previous);
        }
Esempio n. 6
0
 public void Publish()
 {
     if (NumberOfSeats == NumberOfSeats.None)
     {
         throw new ArgumentException(nameof(NumberOfSeats));
     }
     State = MeetupState.Published;
 }
Esempio n. 7
0
        public MeetupState TransitionTo(MeetupState to)
        {
            if (!CanTransitionTo(to))
            {
                throw new ArgumentException($"{nameof(to)}");
            }

            return(to);
        }
Esempio n. 8
0
 public Meetup(MeetupId id, MeetupTitle title, Address location, SeatsNumber numberOfSeats, DateTimeRange timeRange, MeetupState state)
 {
     Id            = id;
     Title         = title;
     Location      = location;
     NumberOfSeats = numberOfSeats;
     TimeRange     = timeRange;
     State         = state;
     EnsureInvariants(State);
 }
Esempio n. 9
0
 public Meetup(MeetupId id, MeetupTitle title)
 {
     Id            = id;
     Title         = title;
     Location      = Address.None;
     NumberOfSeats = SeatsNumber.None;
     TimeRange     = DateTimeRange.None;
     State         = MeetupState.Created;
     EnsureInvariants();
 }
Esempio n. 10
0
 public MeetupAggregate(
     MeetupId id,
     MeetupTitle title,
     ValidatedLocation location,
     NumberOfSeats seats,
     MeetupState state,
     Dictionary <MemberId, DateTime> going,
     Dictionary <MemberId, DateTime> notGoing)
 {
     Id            = id;
     Title         = title;
     Location      = location;
     NumberOfSeats = seats;
     State         = state;
     _going        = going;
     _notGoing     = notGoing;
 }
Esempio n. 11
0
 public Meetup(
     MeetupId id,
     MeetupTitle title,
     Address location,
     SeatsNumber numberOfSeats,
     DateTimeRange timeRange,
     Dictionary <MemberId, DateTime> membersGoing,
     Dictionary <MemberId, DateTime> membersNotGoing,
     MeetupState state)
 {
     Id               = id;
     Title            = title;
     Location         = location;
     NumberOfSeats    = numberOfSeats;
     TimeRange        = timeRange;
     State            = state;
     _membersGoing    = membersGoing;
     _membersNotGoing = membersNotGoing;
     EnsureInvariants();
 }
Esempio n. 12
0
        protected override void When(object @event)
        {
            State.EnsureCanRaiseEvent(@event.GetType());
            switch (@event)
            {
            case Events.MeetupCreated ev:
                Id    = MeetupId.From(ev.Id);
                Title = MeetupTitle.From(ev.Title);
                State = MeetupState.Created;
                break;

            case Events.MeetupPublished ev:
                State = MeetupState.Published;
                break;

            case Events.MeetupCanceled ev:
                State = MeetupState.Canceled;
                break;

            case Events.MeetupClosed ev:
                State = MeetupState.Closed;
                break;

            case Events.MeetupNumberOfSeatsUpdated ev:
                NumberOfSeats = SeatsNumber.From(ev.NumberOfSeats);
                break;

            case Events.MeetupTimeUpdated ev:
                TimeRange = DateTimeRange.From(ev.Start, ev.End);
                break;

            case Events.MeetupTitleUpdated ev:
                Title = MeetupTitle.From(ev.Title);
                break;

            case Events.MeetupLocationUpdated ev:
                Location = Address.From(ev.Location);
                break;
            }
        }
Esempio n. 13
0
 public bool CanTransitionTo(MeetupState to) =>
 _allowedTransitions.Any(x => x == to);