예제 #1
0
        public async Task ShouldAssignMinuteServicesToRoomAndRemoveCurrentConnections()
        {
            //Arrange
            var context    = new iReceptionDbContext(DbOptions);
            var repository = new RoomToMinuteServiceRepository(context);

            var existingMinuteServices = new RoomToMinuteService()
            {
                RoomId          = 1,
                MinuteServiceId = 21
            };
            await context.RoomToMinuteServices.AddAsync((existingMinuteServices));

            await context.SaveChangesAsync();

            int roomId = 1;

            int[] serviceIds = { 2, 3, 4 };

            //Act
            var actual = await repository.AssignAsync(roomId, serviceIds);

            var expected      = serviceIds;
            var deletedRecord = await context.RoomToServices.FindAsync(1, 21);

            //Assert
            actual.Should().BeEquivalentTo(serviceIds);
            deletedRecord.Should().BeNull();
        }
        public async Task <int[]> AssignAsync(int roomId, int[] serviceIds)
        {
            var existingConnections = _db.RoomToMinuteServices.Where(r => r.RoomId == roomId);

            _db.RoomToMinuteServices.RemoveRange(existingConnections);

            foreach (var minuteServiceId in serviceIds)
            {
                var relation = new RoomToMinuteService
                {
                    RoomId          = roomId,
                    MinuteServiceId = minuteServiceId
                };
                await _db.RoomToMinuteServices.AddAsync(relation);
            }

            await _db.SaveChangesAsync();

            return(serviceIds);
        }
예제 #3
0
        public async Task ShouldClearExistingConnections()
        {
            //Arrange
            var context    = new iReceptionDbContext(DbOptions);
            var repository = new RoomToMinuteServiceRepository(context);

            var existingMinuteService = new RoomToMinuteService
            {
                RoomId          = 1,
                MinuteServiceId = 21
            };
            await context.RoomToMinuteServices.AddAsync(existingMinuteService);

            await context.SaveChangesAsync();

            //Act
            await repository.DeleteAsync(1);

            var actual = context.RoomToMinuteServices.ToList();

            //Assert
            actual.Should().BeEmpty();
        }