public async Task Should_ThrowException_When_Joining_ToCancelledMeetup() { 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.Cancel(); _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 cancelled", exception.Message); }