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); }
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); }
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")); }
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)); }
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); }
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>(); }
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")); }
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); }
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); }
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); }
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)); }); }
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))); }
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); }); }
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, })
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));
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));
public void Given_Valid_NumberOfSeats_When_Create_Then_Created() { var number = SeatsNumber.From(10); Assert.Equal(10, number.Value); }
public void Given_Invalid_NumberOfSeats_When_Create_Then_Exception(int invalidSeatsNumber) => Assert.Throws <ArgumentException>(() => SeatsNumber.From(invalidSeatsNumber));