public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { AppointmentRoom roomToRemove = await _arpaContext.AppointmentRooms .FirstOrDefaultAsync(ar => ar.RoomId == request.RoomId && ar.AppointmentId == request.Id, cancellationToken); _arpaContext.AppointmentRooms.Remove(roomToRemove); if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0) { return(Unit.Value); } throw new Exception("Problem removing appointment room"); }
public async Task Should_Remove_Project() { // Arrange DbSet <AppointmentRoom> mockData = MockDbSets.AppointmentRooms; AppointmentRoom appointmentRoom = AppointmentSeedData.AfterShowParty.AppointmentRooms.First(); _arpaContext.AppointmentRooms.Returns(mockData); _arpaContext.SaveChangesAsync(Arg.Any <CancellationToken>()).Returns(1); // Act Unit result = await _handler.Handle(new RemoveRoom.Command( appointmentRoom.AppointmentId, appointmentRoom.RoomId), new CancellationToken()); // Assert result.Should().BeEquivalentTo(Unit.Value); }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { Appointment existingAppointment = await _arpaContext.Appointments.FindAsync(new object[] { request.Id }, cancellationToken); Room existingRoom = await _arpaContext.Rooms.FindAsync(new object[] { request.RoomId }, cancellationToken); var appointmentRoom = new AppointmentRoom(null, existingAppointment, existingRoom); _arpaContext.AppointmentRooms.Add(appointmentRoom); if (await _arpaContext.SaveChangesAsync(cancellationToken) > 0) { return(Unit.Value); } throw new Exception("Problem creating appointment room"); }