public async Task GetAllAsync_Should_Return_Valid_Result()
        {
            var context = _context.Context;
            var fixture = new Fixture();
            var item1   = new CurrentPlaylistItem(fixture.Build <VideoItem>()
                                                  .Without(item => item.PlaylistVideoItems)
                                                  .With(item => item.DurationInSeconds, 20)
                                                  .Create(),
                                                  1);
            var item2 = new CurrentPlaylistItem(fixture.Build <VideoItem>()
                                                .Without(item => item.PlaylistVideoItems)
                                                .With(item => item.DurationInSeconds, 30)
                                                .Create(),
                                                2);
            var item3 = new CurrentPlaylistItem(fixture.Build <VideoItem>()
                                                .Without(item => item.PlaylistVideoItems)
                                                .With(item => item.DurationInSeconds, 60)
                                                .Create(),
                                                3);
            var expected = new[] { item1, item2, item3 };
            await context.AddRangeAsync(item3, item1, item2).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);

            var actual = await _repository.GetAllAsync().ConfigureAwait(false);

            actual.CurrentPlaylistItems.Should().BeEquivalentTo(expected, options => options.WithStrictOrdering());
            Assert.Equal(1, actual.TotalMinutes);
            Assert.Equal(50, actual.TotalSeconds);
        }
Beispiel #2
0
        private void load()
        {
            InternalChild = sprite = CreateBackgroundSprite();

            CurrentPlaylistItem.BindValueChanged(_ => updateBeatmap());
            Playlist.CollectionChanged += (_, __) => updateBeatmap();

            updateBeatmap();
        }
        public async Task GetFirstAsync_Should_Return_Valid_Result()
        {
            var context = _context.Context;
            var fixture = new Fixture();
            var item1   = new CurrentPlaylistItem(fixture.Build <VideoItem>()
                                                  .Without(item => item.PlaylistVideoItems)
                                                  .Create(),
                                                  1);
            var item2 = new CurrentPlaylistItem(fixture.Build <VideoItem>()
                                                .Without(item => item.PlaylistVideoItems)
                                                .Create(),
                                                2);
            var expected = item1;
            await context.AddRangeAsync(item2, item1).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);

            var actual = await _repository.GetFirstAsync().ConfigureAwait(false);

            actual.Should().BeEquivalentTo(expected);
        }
Beispiel #4
0
        public async Task <CurrentPlaylistItem> AddAsync([NotNull] VideoItem videoItem)
        {
            if (videoItem == null)
            {
                throw new ArgumentNullException(nameof(videoItem));
            }

            videoItem = await _videoRepository.GetAttachedOfFoundedAsync(videoItem, _context).ConfigureAwait(false);

            var maxOrder = await _context.CurrentPlaylist.AsNoTracking()
                           .Select(s => s.Order)
                           .DefaultIfEmpty(0)
                           .MaxAsync()
                           .ConfigureAwait(false);

            var playlistItem = new CurrentPlaylistItem(videoItem, maxOrder + 1);
            await _context.CurrentPlaylist.AddAsync(playlistItem).ConfigureAwait(false);

            _context.SaveChanges();

            return(playlistItem);
        }
        public async Task ReorderAsync_Should_Reorder_With_Not_In_Range()
        {
            const int count   = 3;
            var       context = _context.Context;
            var       fixture = new Fixture();
            var       items   = new CurrentPlaylistItem[count];

            for (var i = 0; i < count; i++)
            {
                var idAndOrder = i + 1;
                items[i] = fixture.Build <CurrentPlaylistItem>()
                           .With(item => item.Id, idAndOrder)
                           .With(item => item.Order, idAndOrder)
                           .With(item => item.Video,
                                 fixture.Build <VideoItem>().Without(item => item.PlaylistVideoItems).Create())
                           .Create();
            }

            await context.CurrentPlaylist.AddRangeAsync(items).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);

            var ids      = new[] { count };
            var expected = new[]
        public async Task ReorderAsync_Should_Reorder()
        {
            const int count   = 3;
            var       context = _context.Context;
            var       fixture = new Fixture();
            var       items   = new CurrentPlaylistItem[count];

            for (var i = 0; i < count; i++)
            {
                var idAndOrder = i + 1;
                items[i] = fixture.Build <CurrentPlaylistItem>()
                           .With(item => item.Id, idAndOrder)
                           .With(item => item.Order, idAndOrder)
                           .With(item => item.Video,
                                 fixture.Build <VideoItem>().Without(item => item.PlaylistVideoItems).Create())
                           .Create();
            }

            await context.CurrentPlaylist.AddRangeAsync(items).ConfigureAwait(false);

            await context.SaveChangesAsync().ConfigureAwait(false);

            var ids = Enumerable.Range(1, count).OrderByDescending(o => o).ToArray();

            await _repository.ReorderAsync(ids).ConfigureAwait(false);

            var actual = context.CurrentPlaylist.OrderBy(o => o.Order).ToArray();

            for (var i = 0; i < count; i++)
            {
                var expectedOrder = i + 1;
                var expectedId    = ids[i];
                Assert.Equal(expectedOrder, actual[i].Order);
                Assert.Equal(expectedId, actual[i].Id);
            }
        }
Beispiel #7
0
        public async Task <CurrentPlaylistItem> AddToStartAsync([NotNull] VideoItem videoItem)
        {
            if (videoItem == null)
            {
                throw new ArgumentNullException(nameof(videoItem));
            }

            var newOrder = _context.CurrentPlaylist.ToArray();

            foreach (var item in newOrder)
            {
                item.Order++;
            }

            _context.CurrentPlaylist.UpdateRange(newOrder);
            videoItem = await _videoRepository.GetAttachedOfFoundedAsync(videoItem, _context).ConfigureAwait(false);

            var currentPlaylistItem = new CurrentPlaylistItem(videoItem);
            await _context.CurrentPlaylist.AddAsync(currentPlaylistItem).ConfigureAwait(false);

            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(currentPlaylistItem);
        }
Beispiel #8
0
        protected override void LoadComplete()
        {
            base.LoadComplete();

            CurrentPlaylistItem.BindValueChanged(_ => updateState());
        }
 public CurrentPlaylistVideos()
 {
     CurrentPlaylistItems = new CurrentPlaylistItem[0];
 }