// Copyright (c) Arlo Godfrey. All Rights Reserved.
// Licensed under the GNU Lesser General Public License, Version 3.0 with additional terms.
// See the LICENSE, LICENSE.LESSER and LICENSE.ADDITIONAL files in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using OwlCore.Events;
using StrixMusic.Sdk.AdapterModels;
using StrixMusic.Sdk.AppModels;
using StrixMusic.Sdk.CoreModels;
using StrixMusic.Sdk.MediaPlayback;
namespace StrixMusic.Sdk.Tests.Mock.AppModels;
///
/// Wraps an instance of with the provided plugins.
///
public class MockPlayableCollectionGroup : IPlayableCollectionGroup
{
private readonly List _albums = new();
private readonly List _artists = new();
private readonly List _playlists = new();
private readonly List _tracks = new();
private readonly List _children = new();
private readonly List _images = new();
private readonly List _urls = new();
private int _totalUrlCount;
private int _totalImageCount;
private bool _isChangeNameAsyncAvailable;
private bool _isChangeDescriptionAsyncAvailable;
private bool _isChangeDurationAsyncAvailable;
private string? _description;
private string _name = string.Empty;
private TimeSpan _duration;
private int _totalPlaylistItemsCount;
private bool _isPausePlaylistCollectionAsyncAvailable;
private bool _isPlayPlaylistCollectionAsyncAvailable;
private PlaybackState _playbackState;
private int _totalTrackCount;
private readonly string _id = Guid.NewGuid().ToString();
private bool _isPlayTrackCollectionAsyncAvailable;
private bool _isPauseTrackCollectionAsyncAvailable;
private int _totalAlbumItemsCount;
private bool _isPlayAlbumCollectionAsyncAvailable;
private bool _isPauseAlbumCollectionAsyncAvailable;
private int _totalArtistItemsCount;
private bool _isPlayArtistCollectionAsyncAvailable;
private bool _isPauseArtistCollectionAsyncAvailable;
private int _totalChildrenCount;
private DownloadInfo _downloadInfo;
///
/// Initializes a new instance of the class.
///
internal MockPlayableCollectionGroup()
{
}
///
public event EventHandler? ImagesCountChanged;
///
public event EventHandler? UrlsCountChanged;
///
public event EventHandler? PlaybackStateChanged;
///
public event EventHandler? NameChanged;
///
public event EventHandler? DescriptionChanged;
///
public event EventHandler? DurationChanged;
///
public event EventHandler? LastPlayedChanged;
///
public event EventHandler? IsChangeNameAsyncAvailableChanged;
///
public event EventHandler? IsChangeDescriptionAsyncAvailableChanged;
///
public event EventHandler? IsChangeDurationAsyncAvailableChanged;
///
public event EventHandler? IsPlayPlaylistCollectionAsyncAvailableChanged;
///
public event EventHandler? IsPausePlaylistCollectionAsyncAvailableChanged;
///
public event EventHandler? PlaylistItemsCountChanged;
///
public event EventHandler? IsPlayTrackCollectionAsyncAvailableChanged;
///
public event EventHandler? IsPauseTrackCollectionAsyncAvailableChanged;
///
public event EventHandler? TracksCountChanged;
///
public event EventHandler? IsPlayAlbumCollectionAsyncAvailableChanged;
///
public event EventHandler? IsPauseAlbumCollectionAsyncAvailableChanged;
///
public event EventHandler? AlbumItemsCountChanged;
///
public event EventHandler? IsPlayArtistCollectionAsyncAvailableChanged;
///
public event EventHandler? IsPauseArtistCollectionAsyncAvailableChanged;
///
public event EventHandler? ArtistItemsCountChanged;
///
public event EventHandler? ChildrenCountChanged;
///
public event CollectionChangedEventHandler? ImagesChanged;
///
public event CollectionChangedEventHandler? UrlsChanged;
///
public event EventHandler? DownloadInfoChanged;
///
public event CollectionChangedEventHandler? PlaylistItemsChanged;
///
public event CollectionChangedEventHandler? TracksChanged;
///
public event CollectionChangedEventHandler? AlbumItemsChanged;
///
public event CollectionChangedEventHandler? ArtistItemsChanged;
///
public event CollectionChangedEventHandler? ChildItemsChanged;
///
public int TotalImageCount
{
get => _totalImageCount;
set
{
_totalImageCount = value;
ImagesCountChanged?.Invoke(this, value);
}
}
///
public Task IsAddImageAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public Task IsRemoveImageAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public Task RemoveImageAsync(int index, CancellationToken cancellationToken = default)
{
var removedItem = _images[index];
_images.RemoveAt(index);
TotalImageCount = _images.Count;
ImagesChanged?.Invoke(this, new List>(), new List> { new(removedItem, index) });
return Task.CompletedTask;
}
///
public int TotalUrlCount
{
get => _totalUrlCount;
set
{
_totalUrlCount = value;
UrlsCountChanged?.Invoke(this, value);
}
}
///
public Task RemoveUrlAsync(int index, CancellationToken cancellationToken = default)
{
var removedItem = _urls[index];
_urls.RemoveAt(index);
TotalUrlCount = _urls.Count;
UrlsChanged?.Invoke(this, new List>(), new List> { new(removedItem, index) });
return Task.CompletedTask;
}
///
public Task IsAddUrlAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public Task IsRemoveUrlAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public string Id => _id;
///
public string Name
{
get => _name;
set
{
_name = value;
NameChanged?.Invoke(this, value);
}
}
///
public string? Description
{
get => _description;
set
{
_description = value;
DescriptionChanged?.Invoke(this, value);
}
}
///
public DateTime? LastPlayed => DateTime.UnixEpoch;
///
public PlaybackState PlaybackState
{
get => _playbackState;
set
{
_playbackState = value;
PlaybackStateChanged?.Invoke(this, value);
}
}
///
public TimeSpan Duration
{
get => _duration;
set
{
_duration = value;
DurationChanged?.Invoke(this, value);
}
}
///
public bool IsChangeNameAsyncAvailable
{
get => _isChangeNameAsyncAvailable;
set
{
_isChangeNameAsyncAvailable = value;
IsChangeNameAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public bool IsChangeDescriptionAsyncAvailable
{
get => _isChangeDescriptionAsyncAvailable;
set
{
_isChangeDescriptionAsyncAvailable = value;
IsChangeDescriptionAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public bool IsChangeDurationAsyncAvailable
{
get => _isChangeDurationAsyncAvailable;
set
{
_isChangeDurationAsyncAvailable = value;
IsChangeDurationAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public Task ChangeNameAsync(string name, CancellationToken cancellationToken = default)
{
Name = name;
return Task.CompletedTask;
}
///
public Task ChangeDescriptionAsync(string? description, CancellationToken cancellationToken = default)
{
Description = description;
return Task.CompletedTask;
}
///
public Task ChangeDurationAsync(TimeSpan duration, CancellationToken cancellationToken = default)
{
Duration = duration;
return Task.CompletedTask;
}
///
public DateTime? AddedAt => null;
///
public int TotalPlaylistItemsCount
{
get => _totalPlaylistItemsCount;
set
{
_totalPlaylistItemsCount = value;
PlaylistItemsCountChanged?.Invoke(this, value);
}
}
///
public bool IsPlayPlaylistCollectionAsyncAvailable
{
get => _isPlayPlaylistCollectionAsyncAvailable;
set
{
_isPlayPlaylistCollectionAsyncAvailable = value;
IsPlayPlaylistCollectionAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public bool IsPausePlaylistCollectionAsyncAvailable
{
get => _isPausePlaylistCollectionAsyncAvailable;
set
{
_isPausePlaylistCollectionAsyncAvailable = value;
IsPausePlaylistCollectionAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public Task PlayPlaylistCollectionAsync(CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Playing;
return Task.CompletedTask;
}
///
public Task PausePlaylistCollectionAsync(CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Paused;
return Task.CompletedTask;
}
///
public Task RemovePlaylistItemAsync(int index, CancellationToken cancellationToken = default)
{
var removedItem = _playlists[index];
_playlists.RemoveAt(index);
TotalPlaylistItemsCount = _playlists.Count;
PlaylistItemsChanged?.Invoke(this, new List>(), new List> { new(removedItem, index) });
return Task.CompletedTask;
}
///
public Task IsAddPlaylistItemAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public Task IsRemovePlaylistItemAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public int TotalTrackCount
{
get => _totalTrackCount;
set
{
_totalTrackCount = value;
TracksCountChanged?.Invoke(this, value);
}
}
///
public bool IsPlayTrackCollectionAsyncAvailable
{
get => _isPlayTrackCollectionAsyncAvailable;
set
{
_isPlayTrackCollectionAsyncAvailable = value;
IsPlayTrackCollectionAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public bool IsPauseTrackCollectionAsyncAvailable
{
get => _isPauseTrackCollectionAsyncAvailable;
set
{
_isPauseTrackCollectionAsyncAvailable = value;
IsPauseTrackCollectionAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public Task PlayTrackCollectionAsync(CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Playing;
return Task.CompletedTask;
}
///
public Task PauseTrackCollectionAsync(CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Paused;
return Task.CompletedTask;
}
///
public Task RemoveTrackAsync(int index, CancellationToken cancellationToken = default)
{
var removedItem = _tracks[index];
_tracks.RemoveAt(index);
TotalTrackCount = _tracks.Count;
TracksChanged?.Invoke(this, new List>(), new List> { new(removedItem, index) });
return Task.CompletedTask;
}
///
public Task IsAddTrackAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public Task IsRemoveTrackAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public int TotalAlbumItemsCount
{
get => _totalAlbumItemsCount;
set
{
_totalAlbumItemsCount = value;
AlbumItemsCountChanged?.Invoke(this, value);
}
}
///
public bool IsPlayAlbumCollectionAsyncAvailable
{
get => _isPlayAlbumCollectionAsyncAvailable;
set
{
_isPlayAlbumCollectionAsyncAvailable = value;
IsPlayAlbumCollectionAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public bool IsPauseAlbumCollectionAsyncAvailable
{
get => _isPauseAlbumCollectionAsyncAvailable;
set
{
_isPauseAlbumCollectionAsyncAvailable = value;
IsPauseAlbumCollectionAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public Task PlayAlbumCollectionAsync(CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Playing;
return Task.CompletedTask;
}
///
public Task PauseAlbumCollectionAsync(CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Paused;
return Task.CompletedTask;
}
///
public Task RemoveAlbumItemAsync(int index, CancellationToken cancellationToken = default)
{
var removedItem = _albums[index];
_albums.RemoveAt(index);
TotalAlbumItemsCount = _albums.Count;
AlbumItemsChanged?.Invoke(this, new List>(), new List> { new(removedItem, index) });
return Task.CompletedTask;
}
///
public Task IsAddAlbumItemAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public Task IsRemoveAlbumItemAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public int TotalArtistItemsCount
{
get => _totalArtistItemsCount;
set
{
_totalArtistItemsCount = value;
ArtistItemsCountChanged?.Invoke(this, value);
}
}
///
public bool IsPlayArtistCollectionAsyncAvailable
{
get => _isPlayArtistCollectionAsyncAvailable;
set
{
_isPlayArtistCollectionAsyncAvailable = value;
IsPlayArtistCollectionAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public bool IsPauseArtistCollectionAsyncAvailable
{
get => _isPauseArtistCollectionAsyncAvailable;
set
{
_isPauseArtistCollectionAsyncAvailable = value;
IsPauseArtistCollectionAsyncAvailableChanged?.Invoke(this, value);
}
}
///
public Task PlayArtistCollectionAsync(CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Playing;
return Task.CompletedTask;
}
///
public Task PauseArtistCollectionAsync(CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Paused;
return Task.CompletedTask;
}
///
public Task RemoveArtistItemAsync(int index, CancellationToken cancellationToken = default)
{
var removedItem = _artists[index];
_artists.RemoveAt(index);
TotalArtistItemsCount = _artists.Count;
ArtistItemsChanged?.Invoke(this, new List>(), new List> { new(removedItem, index) });
return Task.CompletedTask;
}
///
public Task IsAddArtistItemAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public Task IsRemoveArtistItemAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public Task PlayPlayableCollectionGroupAsync(CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Playing;
return Task.CompletedTask;
}
///
public Task PausePlayableCollectionGroupAsync(CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Paused;
return Task.CompletedTask;
}
///
public int TotalChildrenCount
{
get => _totalChildrenCount;
set
{
_totalChildrenCount = value;
ChildrenCountChanged?.Invoke(this, value);
}
}
///
public Task RemoveChildAsync(int index, CancellationToken cancellationToken = default)
{
var removedItem = _children[index];
_children.RemoveAt(index);
TotalChildrenCount = _children.Count;
ChildItemsChanged?.Invoke(this, new List>(), new List> { new(removedItem, index) });
return Task.CompletedTask;
}
///
public Task IsAddChildAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public Task IsRemoveChildAvailableAsync(int index, CancellationToken cancellationToken = default) => Task.FromResult(true);
///
public bool Equals(ICoreImageCollection? other) => false;
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
IReadOnlyList IMerged.Sources { get; } = new List();
///
public IAsyncEnumerable GetImagesAsync(int limit, int offset, CancellationToken cancellationToken = default) => _images.ToAsyncEnumerable();
///
public Task AddImageAsync(IImage image, int index, CancellationToken cancellationToken = default)
{
_images.Insert(index, image);
TotalImageCount = _images.Count;
ImagesChanged?.Invoke(this, new List> { new(image, index) }, new List>());
return Task.CompletedTask;
}
///
public bool Equals(ICoreUrlCollection? other) => false;
///
public IAsyncEnumerable GetUrlsAsync(int limit, int offset, CancellationToken cancellationToken = default) => _urls.ToAsyncEnumerable();
///
public Task AddUrlAsync(IUrl url, int index, CancellationToken cancellationToken = default)
{
_urls.Insert(index, url);
TotalUrlCount = _urls.Count;
UrlsChanged?.Invoke(this, new List> { new(url, index) }, new List>());
return Task.CompletedTask;
}
///
public DownloadInfo DownloadInfo
{
get => _downloadInfo;
set
{
_downloadInfo = value;
DownloadInfoChanged?.Invoke(this, value);
}
}
///
public Task StartDownloadOperationAsync(DownloadOperation operation, CancellationToken cancellationToken = default)
{
DownloadInfo = new(DownloadState.Downloading);
return Task.CompletedTask;
}
///
public bool Equals(ICorePlaylistCollectionItem? other) => false;
///
public bool Equals(ICorePlaylistCollection? other) => false;
///
public Task PlayPlaylistCollectionAsync(IPlaylistCollectionItem playlistItem, CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Playing;
return Task.CompletedTask;
}
///
public IAsyncEnumerable GetPlaylistItemsAsync(int limit, int offset, CancellationToken cancellationToken = default) => _playlists.ToAsyncEnumerable();
///
public Task AddPlaylistItemAsync(IPlaylistCollectionItem playlistItem, int index, CancellationToken cancellationToken = default)
{
_playlists.Insert(index, playlistItem);
TotalPlaylistItemsCount = _playlists.Count;
PlaylistItemsChanged?.Invoke(this, new List> { new(playlistItem, index) }, new List>());
return Task.CompletedTask;
}
///
public bool Equals(ICoreTrackCollection? other) => false;
///
public Task PlayTrackCollectionAsync(ITrack track, CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Playing;
return Task.CompletedTask;
}
///
public IAsyncEnumerable GetTracksAsync(int limit, int offset, CancellationToken cancellationToken = default) => _tracks.ToAsyncEnumerable();
///
public Task AddTrackAsync(ITrack track, int index, CancellationToken cancellationToken = default)
{
_tracks.Insert(index, track);
TotalTrackCount = _tracks.Count;
TracksChanged?.Invoke(this, new List> { new(track, index) }, new List>());
return Task.CompletedTask;
}
///
public bool Equals(ICoreAlbumCollectionItem? other) => false;
///
public bool Equals(ICoreAlbumCollection? other) => false;
///
public Task PlayAlbumCollectionAsync(IAlbumCollectionItem albumItem, CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Playing;
return Task.CompletedTask;
}
///
public IAsyncEnumerable GetAlbumItemsAsync(int limit, int offset, CancellationToken cancellationToken = default) => _albums.ToAsyncEnumerable();
///
public Task AddAlbumItemAsync(IAlbumCollectionItem albumItem, int index, CancellationToken cancellationToken = default)
{
_albums.Insert(index, albumItem);
TotalAlbumItemsCount = _albums.Count;
AlbumItemsChanged?.Invoke(this, new List> { new(albumItem, index) }, new List>());
return Task.CompletedTask;
}
///
public bool Equals(ICoreArtistCollectionItem? other) => false;
///
public bool Equals(ICoreArtistCollection? other) => false;
///
public Task PlayArtistCollectionAsync(IArtistCollectionItem artistItem, CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Playing;
return Task.CompletedTask;
}
///
public IAsyncEnumerable GetArtistItemsAsync(int limit, int offset, CancellationToken cancellationToken = default) => _artists.ToAsyncEnumerable();
///
public Task AddArtistItemAsync(IArtistCollectionItem artistItem, int index, CancellationToken cancellationToken = default)
{
_artists.Insert(index, artistItem);
TotalArtistItemsCount = _artists.Count;
ArtistItemsChanged?.Invoke(this, new List> { new(artistItem, index) }, new List>());
return Task.CompletedTask;
}
///
public bool Equals(ICorePlayableCollectionGroupChildren? other) => false;
///
public Task PlayPlayableCollectionGroupAsync(IPlayableCollectionGroup collectionGroup, CancellationToken cancellationToken = default)
{
PlaybackState = PlaybackState.Playing;
return Task.CompletedTask;
}
///
public IAsyncEnumerable GetChildrenAsync(int limit, int offset, CancellationToken cancellationToken = default) => _children.ToAsyncEnumerable();
///
public Task AddChildAsync(IPlayableCollectionGroup child, int index, CancellationToken cancellationToken = default)
{
_children.Insert(index, child);
TotalChildrenCount = _children.Count;
ChildItemsChanged?.Invoke(this, new List> { new(child, index) }, new List>());
return Task.CompletedTask;
}
///
public bool Equals(ICorePlayableCollectionGroup? other) => false;
///
public ValueTask DisposeAsync() => default;
public event EventHandler? SourcesChanged;
}