Пример #1
0
    public void ShouldBeInRange_WhenValueIsFromStartForDuration()
    {
        var value     = DateTimeOffset.Now;
        var start     = value.AddHours(-1);
        var end       = value.AddHours(1);
        var timeRange = DateTimeRange.From(start).For(2).Hours();

        Assert.That(timeRange.IsInRange(start), Is.True);
        Assert.That(timeRange.IsInRange(start.AddHours(-1)), Is.False);
        Assert.That(timeRange.IsInRange(value), Is.True);
        Assert.That(timeRange.IsInRange(end), Is.True);
        Assert.That(timeRange.IsInRange(end.AddHours(1)), Is.False);
    }
Пример #2
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);
        }
Пример #3
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)));
        }
Пример #4
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,
            })
Пример #5
0
        public void Given_Valid_Range_When_Create_Then_Created()
        {
            var timeRange = DateTimeRange.From(date: "2019-06-19", time: "19:00", durationInHours: 3);

            Assert.Equal(new DateTime(2019, 6, 19, 19, 0, 0), timeRange.Start);
        }
Пример #6
0
 public void Giving_wrong_date_or_pattern_should_thow_exception(string date, string time)
 {
     Assert.Throws <ArgumentException>(() =>
                                       DateTimeRange.From(date: date, time: time, durationInHours: 3)
                                       );
 }