コード例 #1
0
 private static MeetupAggregate ExecuteCommand(this MeetupAggregate @this, Func <MeetupAggregate> command)
 {
     @this.UpdateNumberOfSeats(SeatsNumber.From(numberOfSeats));
     @this.UpdateLocation(Address.From(address));
     @this.UpdateTime(timeRange);
     @this = command();
     return(@this);
 }
コード例 #2
0
 private static Meetup ExecuteCommand(this Meetup @this, Action command)
 {
     @this.UpdateNumberOfSeats(SeatsNumber.From(numberOfSeats));
     @this.UpdateLocation(Address.From(address));
     @this.UpdateTime(timeRange);
     command();
     return(@this);
 }
コード例 #3
0
ファイル: SeatsNumberTest.cs プロジェクト: Nino-Dioses/meetup
        public void Given_Same_NumberOfSeats_When_Use_AsDictionaryKey_Then_Exception()
        {
            var number1 = SeatsNumber.From(10);
            var number2 = SeatsNumber.From(10);
            var numbers = new Dictionary <SeatsNumber, string>();

            numbers.Add(number1, "meetup1");
            Assert.Throws <ArgumentException>(() => numbers.Add(number2, "meetup2"));
        }
コード例 #4
0
 public void Given_Invalid_Meetup_When_Build_Then_Throws(MeetupState state)
 {
     Assert.Throws <MeetupDomainException>(() =>
                                           new Meetup(
                                               MeetupId.From(id),
                                               MeetupTitle.From(title),
                                               Address.None,
                                               SeatsNumber.From(numberOfSeats),
                                               timeRange,
                                               state));
 }
コード例 #5
0
        public void Given_Valid_Meetup_When_Publish_Then_Published()
        {
            var meetup = CreateMeetup().AssertProperties();

            meetup.UpdateNumberOfSeats(SeatsNumber.From(numberOfSeats));
            meetup.UpdateLocation(Address.From(address));
            meetup.UpdateTime(timeRange);

            meetup.Publish();
            Assert.Equal(MeetupState.Published, meetup.State);
        }
コード例 #6
0
        public void Given_Valid_Meetup_When_Publish_Then_Published()
        {
            var meetup = CreateMeetup();

            meetup.UpdateNumberOfSeats(SeatsNumber.From(numberOfSeats));
            meetup.UpdateLocation(Address.From(address));
            meetup.UpdateTime(timeRange);
            meetup.Publish();

            meetup.Events.Last().AssertEvent <Events.MeetupPublished>();
        }
コード例 #7
0
ファイル: SeatsNumberTest.cs プロジェクト: Nino-Dioses/meetup
        public void Given_Same_NumberOfSeats_When_Compare_Then_Equal()
        {
            var number1 = SeatsNumber.From(10);
            var number2 = SeatsNumber.From(10);

            Assert.Equal(number1, number2);
            Assert.True(number1 == number2);
            Assert.False(number1 != number2);

            var numbers = new Dictionary <SeatsNumber, string>();

            numbers.Add(number1, "meetup1");
            Assert.Throws <ArgumentException>(() => numbers.Add(number2, "meetup2"));
        }
コード例 #8
0
        public async Task <Domain.Meetup> Get(Guid id)
        {
            var doc = await _meetups
                      .Find <MeetupDocument>(meetup => meetup.Id == id)
                      .FirstOrDefaultAsync();

            return(doc != null
            ? new Domain.Meetup(
                       MeetupId.From(id),
                       MeetupTitle.From(doc.Title),
                       Address.From(doc.Location),
                       SeatsNumber.From(doc.NumberOfSeats),
                       DateTimeRange.From(doc.Start, doc.End),
                       Enum.Parse <MeetupState>(doc.State))
            : null);
        }
コード例 #9
0
        public void Given_Created_Meetup_When_Create_Then_Created()
        {
            var meetup = CreateMeetup().AssertProperties();

            meetup.UpdateTitle(MeetupTitle.From("CQRS with Postgres"));
            Assert.Equal("CQRS with Postgres", meetup.Title);

            meetup.UpdateLocation(Address.From(address));
            Assert.Equal(address, meetup.Location);

            meetup.UpdateNumberOfSeats(SeatsNumber.From(numberOfSeats));
            Assert.Equal(numberOfSeats, meetup.NumberOfSeats);

            meetup.UpdateTime(timeRange);
            Assert.Equal(timeRange, meetup.TimeRange);
        }
コード例 #10
0
        public void Given_Valid_Meetup_When_Build_Then_Built(MeetupState state)
        {
            var meetup = new Meetup(
                MeetupId.From(id),
                MeetupTitle.From(title),
                Address.From(address),
                SeatsNumber.From(numberOfSeats),
                timeRange,
                state);

            Assert.Equal(id, meetup.Id);
            Assert.Equal(title, meetup.Title);
            Assert.Equal(address, meetup.Location);
            Assert.Equal(numberOfSeats, meetup.NumberOfSeats);
            Assert.Equal(timeRange, meetup.TimeRange);
            Assert.Equal(state, meetup.State);
        }
コード例 #11
0
ファイル: MeetupTest.cs プロジェクト: WillLeeBebi/meetup
 public void Given_Invalid_Meetup_When_Build_Then_Throws()
 {
     new[] { MeetupState.Published, MeetupState.Canceled, MeetupState.Closed }
     .ToList().ForEach(state =>
     {
         Assert.Throws <MeetupDomainException>(() =>
                                               new Meetup(
                                                   MeetupId.From(id),
                                                   MeetupTitle.From(title),
                                                   Address.None,
                                                   SeatsNumber.From(numberOfSeats),
                                                   timeRange,
                                                   new Dictionary <MemberId, DateTime>(),
                                                   new Dictionary <MemberId, DateTime>(),
                                                   state));
     });
 }
コード例 #12
0
        public void Given_Created_Meetup_When_Create_Then_Created()
        {
            var meetup = CreateMeetup();

            meetup.UpdateTitle(MeetupTitle.From("CQRS with Postgres"));
            meetup.UpdateLocation(Address.From(address));
            meetup.UpdateNumberOfSeats(SeatsNumber.From(numberOfSeats));
            meetup.UpdateTime(timeRange);

            var events = meetup.Events.ToArray();

            events[0].AssertEvent <Events.MeetupCreated>(
                ev => Assert.Equal(id, ev.Id));
            events[1].AssertEvent <Events.MeetupTitleUpdated>(
                ev => Assert.Equal("CQRS with Postgres", ev.Title));
            events[2].AssertEvent <Events.MeetupLocationUpdated>(
                ev => Assert.Equal(address, ev.Location));
            events[3].AssertEvent <Events.MeetupNumberOfSeatsUpdated>(
                ev => Assert.Equal(numberOfSeats, ev.NumberOfSeats));
            events[4].AssertEvent <Events.MeetupTimeUpdated>(
                ev => Assert.Equal(timeRange, DateTimeRange.From(ev.Start, ev.End)));
        }
コード例 #13
0
ファイル: MeetupTest.cs プロジェクト: WillLeeBebi/meetup
        public void Given_Valid_Meetup_When_Build_Then_Built()
        {
            new[] { MeetupState.Created, MeetupState.Published, MeetupState.Canceled, MeetupState.Closed }
            .ToList().ForEach(state =>
            {
                var meetup = new Meetup(
                    MeetupId.From(id),
                    MeetupTitle.From(title),
                    Address.From(address),
                    SeatsNumber.From(numberOfSeats),
                    timeRange,
                    new Dictionary <MemberId, DateTime>(),
                    new Dictionary <MemberId, DateTime>(),
                    state);

                Assert.Equal(id, meetup.Id);
                Assert.Equal(title, meetup.Title);
                Assert.Equal(address, meetup.Location);
                Assert.Equal(numberOfSeats, meetup.NumberOfSeats);
                Assert.Equal(timeRange, meetup.TimeRange);
                Assert.Equal(state, meetup.State);
            });
        }
コード例 #14
0
        public async Task <Domain.Meetup> Get(Guid id)
        {
            var doc = await _meetups
                      .Find <MeetupDocument>(meetup => meetup.Id == id)
                      .FirstOrDefaultAsync();

            return(doc != null
            ? new Domain.Meetup(
                       MeetupId.From(id),
                       MeetupTitle.From(doc.Title),
                       Address.From(doc.Location),
                       SeatsNumber.From(doc.NumberOfSeats),
                       DateTimeRange.From(doc.Start, doc.End),
                       doc.MembersGoing.ToDictionary(k => MemberId.From(Guid.Parse(k.Key)), v => v.Value),
                       doc.MembersNotGoing.ToDictionary(k => MemberId.From(Guid.Parse(k.Key)), v => v.Value),
                       doc.State.ToLower() switch
            {
                "created" => MeetupState.Created,
                "published" => MeetupState.Published,
                "closed" => MeetupState.Closed,
                "canceled" => MeetupState.Canceled,
                _ => MeetupState.Created,
            })
コード例 #15
0
 public void Given_Published_Meetup_When_UpdateSeats_Then_SeatsUpdated() =>
 GivenPublishedMeetupThen <Events.MeetupNumberOfSeatsUpdated>(
     when: m => m.UpdateNumberOfSeats(SeatsNumber.From(25)),
     assert: ev => Assert.Equal(25, ev.NumberOfSeats));
コード例 #16
0
 public void Given_Published_Meetup_When_UpdateSeats_Then_SeatsUpdated() =>
 GivenPublishedMeetup <Events.MeetupNumberOfSeatsUpdated>(
     m => m.UpdateNumberOfSeats(SeatsNumber.From(25)),
     (m, ev) => Assert.Equal(m.NumberOfSeats, ev.NumberOfSeats));
コード例 #17
0
ファイル: SeatsNumberTest.cs プロジェクト: Nino-Dioses/meetup
        public void Given_Valid_NumberOfSeats_When_Create_Then_Created()
        {
            var number = SeatsNumber.From(10);

            Assert.Equal(10, number.Value);
        }
コード例 #18
0
ファイル: SeatsNumberTest.cs プロジェクト: Nino-Dioses/meetup
 public void Given_Invalid_NumberOfSeats_When_Create_Then_Exception(int invalidSeatsNumber) =>
 Assert.Throws <ArgumentException>(() => SeatsNumber.From(invalidSeatsNumber));