context: #define LoginToSpotify
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using OpenPlaylistServer.Models;
  using OpenPlaylistServer.Services.Implementation;
  using SpotifyDotNet;
  using TestSuite.Properties;
  using WebAPI;
  using Xunit;
  using Track = WebAPI.Track;
  
  namespace TestSuite {
  
      #region Login
  
      public class TestsFixture : IDisposable {
          public readonly SpotifyLoggedIn Spl;
  
          public TestsFixture() {
  #if (!LoginToSpotify)
                  return;
              #endif
              var result = Spotify.Instance.Login("jensstaermose@hotmail.com",
                                                  "hejheider",
                                                  false,
                                                  Resources.spotify_appkey);
              Spl = result.Item1;
          }
  
          public void Dispose() {}
      }
  
      #endregion
  
      public class TestPlaylist : IUseFixture<TestsFixture> {
          private TestsFixture _data;
  
          public void SetFixture(TestsFixture data) {
              _data = data;
          }
  
          #region Server
  
          #region Services
  
          #region PlaylistService
  
          [Fact]
          public void PlaylistFindTrackFindsTrack() {
              var users = new UserService();
              var hist = new HistoryService();
              var pl = new PlaylistService(users, hist);
  
              var img1 = new Image(600, 600, "https://i.scdn.co/image/6885d1703f4f4fcbedd7beb231ecca8131de5683");
              var img2 = new Image(300, 300, "https://i.scdn.co/image/c70d12c712e41ed4f532e4d190f3476380d0f708");
              var img3 = new Image(64, 64, "https://i.scdn.co/image/cae856966342ec081a5dae800bb0efc8f8993612");
              IEnumerable<Image> images = new List<Image> {
                  img1,
                  img2,
                  img3
              };
              var art = new Artist("40UIlN4YEByXy4ewEZmqXu", "Aphyxion");
              var artists = new List<Artist> {
                  art
              };
              var alb = new Album("0hNtREj1dl7bKoWEz0XXMr", "Obliteration of the Weak", "album", images, artists);
  
              var track1 = new Track("19pTAbMZmWsgGkYZ4v2TM1",
                                     "Obliteration of the Weak",
                                     232120,
                                     false,
                                     1,
                                     "DKFD51642001",
                                     "https://p.scdn.co/mp3-preview/1d3ee1111d679b5e5b50c53aa3bfcceb4c83da8a",
                                     alb);
              var track2 = new Track("50JtiuLYhzRO86ozFGxqYL",
                                     "Crossing the Boundaries",
                                     220400,
                                     false,
                                     2,
                                     "DKFD51642002",
                                     "https://p.scdn.co/mp3-preview/1dbb52c571db58003ecd0eb9dcf0d09c8bc4f0bb",
                                     alb);
  
              pl.Add(track1);
              pl.Add(track2);
  
              Assert.True(pl.FindTrack(track1.Uri).Equals(track1));
              Assert.False(pl.FindTrack(track1.Uri).Equals(track2));
          }
  
          [Fact]
          public void PlaylistCalcTScoreCalculatesScore() {
              var users = new UserService();
              var hist = new HistoryService();
              var pl = new PlaylistService(users, hist);
  
              var img1 = new Image(600, 600, "https://i.scdn.co/image/6885d1703f4f4fcbedd7beb231ecca8131de5683");
              var img2 = new Image(300, 300, "https://i.scdn.co/image/c70d12c712e41ed4f532e4d190f3476380d0f708");
              var img3 = new Image(64, 64, "https://i.scdn.co/image/cae856966342ec081a5dae800bb0efc8f8993612");
              IEnumerable<Image> images = new List<Image> {
                  img1,
                  img2,
                  img3
              };
              var art = new Artist("40UIlN4YEByXy4ewEZmqXu", "Aphyxion");
              var artists = new List<Artist> {
                  art
              };
              var alb = new Album("0hNtREj1dl7bKoWEz0XXMr", "Obliteration of the Weak", "album", images, artists);
  
              var track1 = new Track("19pTAbMZmWsgGkYZ4v2TM1",
                                     "Obliteration of the Weak",
                                     232120,
                                     false,
                                     1,
                                     "DKFD51642001",
                                     "https://p.scdn.co/mp3-preview/1d3ee1111d679b5e5b50c53aa3bfcceb4c83da8a",
                                     alb);
              var track2 = new Track("50JtiuLYhzRO86ozFGxqYL",
                                     "Crossing the Boundaries",
                                     220400,
                                     false,
                                     2,
                                     "DKFD51642002",
                                     "https://p.scdn.co/mp3-preview/1dbb52c571db58003ecd0eb9dcf0d09c8bc4f0bb",
                                     alb);
              var a = new User("1234");
              var b = new User("2345");
  
              users.Add(a);
              users.Add(b);
              pl.Add(track1);
              pl.Add(track2);
  
              Assert.True(pl.CalcTScore(track1).Equals(0));
              a.Vote = track1;
              Assert.True(pl.CalcTScore(track1).Equals(1));
              b.Vote = track1;
              Assert.True(pl.CalcTScore(track1).Equals(2));
              a.Vote = track2;
              Assert.True(pl.CalcTScore(track1).Equals(1));
          }
  
          [Fact]
          public void PlaylistNextTrackHasHighestVotes() {
              //Tests that the next track is the one with highest votes
              var users = new UserService();
              var hist = new HistoryService();
              var pl = new PlaylistService(users, hist);
  
              var img1 = new Image(600, 600, "https://i.scdn.co/image/6885d1703f4f4fcbedd7beb231ecca8131de5683");
              var img2 = new Image(300, 300, "https://i.scdn.co/image/c70d12c712e41ed4f532e4d190f3476380d0f708");
              var img3 = new Image(64, 64, "https://i.scdn.co/image/cae856966342ec081a5dae800bb0efc8f8993612");
              IEnumerable<Image> images = new List<Image> {
                  img1,
                  img2,
                  img3
              };
              var art = new Artist("40UIlN4YEByXy4ewEZmqXu", "Aphyxion");
              var artists = new List<Artist> {
                  art
              };
              var alb = new Album("0hNtREj1dl7bKoWEz0XXMr", "Obliteration of the Weak", "album", images, artists);
  
              var track1 = new Track("19pTAbMZmWsgGkYZ4v2TM1",
                                     "Obliteration of the Weak",
                                     232120,
                                     false,
                                     1,
                                     "DKFD51642001",
                                     "https://p.scdn.co/mp3-preview/1d3ee1111d679b5e5b50c53aa3bfcceb4c83da8a",
                                     alb);
              var track2 = new Track("50JtiuLYhzRO86ozFGxqYL",
                                     "Crossing the Boundaries",
                                     220400,
                                     false,
                                     2,
                                     "DKFD51642002",
                                     "https://p.scdn.co/mp3-preview/1dbb52c571db58003ecd0eb9dcf0d09c8bc4f0bb",
                                     alb);
              var a = new User("1234");
              var b = new User("2345");
              var c = new User("3456");
  
              pl.Add(track1);
              pl.Add(track2);
  
              a.Vote = track2;
              b.Vote = track1;
              c.Vote = track1;
  
              users.Add(a); //votes for track 2
              Assert.Equal(track2, pl.NextTrack()); //t1 has 0 votes, t2 has 1 vote, tests that t2 is next
  
              a.Vote = track2;
              users.Add(b); //votes for track 1
              users.Add(c); //votes for track 1
  
              Assert.Equal(track1, pl.NextTrack()); //t1 has 2 votes, t2 has 1 vote, tests that t1 is next
          }
  
          [Fact]
          public void PlaylistNextTrackFindsTrackIfEmpty() {
              var users = new UserService();
              var hist = new HistoryService();
              var pl = new PlaylistService(users, hist);
  
              var img1 = new Image(600, 600, "https://i.scdn.co/image/6885d1703f4f4fcbedd7beb231ecca8131de5683");
              var img2 = new Image(300, 300, "https://i.scdn.co/image/c70d12c712e41ed4f532e4d190f3476380d0f708");
              var img3 = new Image(64, 64, "https://i.scdn.co/image/cae856966342ec081a5dae800bb0efc8f8993612");
              IEnumerable<Image> images = new List<Image> {
                  img1,
                  img2,
                  img3
              };
              var art = new Artist("40UIlN4YEByXy4ewEZmqXu", "Aphyxion");
  
gt:             var artists = new List<Artist> {