public async Task Should_Success_Joining_ToMetup() { var mockIdentityService = new Mock <IIdentityService>(); mockIdentityService.Setup((x) => x.GetUserId()).Returns("456"); var mockMeetupPolicy = new Mock <IMeetupPolicy>(); mockMeetupPolicy.Setup((x) => x.CheckCanDefineMeetup(It.IsAny <string>(), It.IsAny <DateTime>())).Callback(() => { }); var meetup = new Meetup( organizerId: "123", subject: "DDD", when: DateTime.Now.AddDays(1), description: "DDD Practices", location: new Location("YTÜ Teknopark"), policy: mockMeetupPolicy.Object); _fixture.dbContext.Add(meetup); var meetupRepository = new MeetupRepository(_fixture.dbContext); var joinMeetupCommandHandler = new JoinMeetupCommandHandler(meetupRepository, mockIdentityService.Object); var cancellationToken = new CancellationToken(); var joinMeetupCommand = new JoinMeetupCommand { MeetupId = meetup.Id }; await joinMeetupCommandHandler.Handle(joinMeetupCommand, cancellationToken); Assert.Single(_fixture.dbContext.Meetups.FirstOrDefault().Participants); }
public async Task Should_ThrowException_When_Joining_ToCompletedMeetup() { var mockIdentityService = new Mock <IIdentityService>(); mockIdentityService.Setup((x) => x.GetUserId()).Returns("456"); var mockMeetupPolicy = new Mock <IMeetupPolicy>(); mockMeetupPolicy.Setup((x) => x.CheckCanDefineMeetup(It.IsAny <string>(), It.IsAny <DateTime>())).Callback(() => { }); var meetup = new Meetup( organizerId: "123", subject: "DDD", when: DateTime.Now.AddDays(1), description: "DDD Practices", location: new Location("YTÜ Teknopark"), policy: mockMeetupPolicy.Object); meetup.Complete(); _fixture.dbContext.Add(meetup); var meetupRepository = new MeetupRepository(_fixture.dbContext); var joinMeetupCommandHandler = new JoinMeetupCommandHandler(meetupRepository, mockIdentityService.Object); var cancellationToken = new CancellationToken(); var joinMeetupCommand = new JoinMeetupCommand { MeetupId = meetup.Id }; var exception = await Assert.ThrowsAsync <MeetupDomainException>(async() => { await joinMeetupCommandHandler.Handle(joinMeetupCommand, cancellationToken); }); Assert.Equal("Meetup is completed", exception.Message); }