public async Task Handle_RemoveCalendarEvent_WhenItExists() { var calendarEvent = new CalendarEvent( "Music fetival", DateTimeOffset.Now.ToUnixTimeSeconds(), "Oosterpark, Amsterdam ", "Rafael Caviquioli" ); calendarEvent.AddMember("Aleida"); _context.Add(calendarEvent); await _context.SaveChangesAsync(); _context.DetachAllEntities(); var command = new RemoveCalendarEventCommand(calendarEvent.Id); var handler = new RemoveCalendarEventCommandHandler(_calendarEventRepository); await handler.Handle(command, CancellationToken.None); var calendarEventExpected = await _context.CalendarEvents .FirstOrDefaultAsync(ce => ce.Id == calendarEvent.Id); calendarEventExpected .Should().BeNull("Because calendar event was removed from database"); }
public async Task Handle_ShouldThrowResourceNotFoundException_WhenTryToRemoveACalendarEventThatDoesNotExists() { var command = new RemoveCalendarEventCommand("5e5c341ad9978660124015f6"); var handler = new RemoveCalendarEventCommandHandler(_calendarEventRepository); await Assert.ThrowsAsync <ResourceNotFoundException>( async() => await handler.Handle(command, CancellationToken.None) ); }
public async Task <ActionResult> RemoveCalendarEvent([FromRoute] string calendarEventId) { try { var command = new RemoveCalendarEventCommand(calendarEventId); await _mediator.Send(command); return(Ok()); } catch (ResourceNotFoundException) { return(NotFound(calendarEventId)); } }