Exemple #1
0
        public void NotEqualOperatorWhenTestDifferentNickname()
        {
            var userId1 = UserId.Parse("12345");
            var userId2 = UserId.Parse("67890");

            Assert.IsTrue(userId1 != userId2);
        }
Exemple #2
0
        public void NotEqualWhenTestDifferentNickname()
        {
            var userId1 = UserId.Parse("12345");
            var userId2 = UserId.Parse("67890");

            Assert.AreNotEqual(userId1, userId2);
        }
Exemple #3
0
        public void EqualOperatorWhenTestSameNickname()
        {
            var userId1 = UserId.Parse("12345");
            var userId2 = UserId.Parse("12345");

            Assert.IsTrue(userId1 == userId2);
        }
Exemple #4
0
        public void ShouldSerializeUserId()
        {
            var userId     = UserId.Parse("@sharparam:matrix.sharparam.com");
            var serialized = JsonConvert.SerializeObject(userId);

            Assert.AreEqual("\"@sharparam:matrix.sharparam.com\"", serialized);
        }
Exemple #5
0
        public void EqualWhenTestSameUserId()
        {
            var userId1 = UserId.Parse("12345");
            var userId2 = UserId.Parse("12345");

            Assert.AreEqual(userId1, userId2);
        }
Exemple #6
0
        public void CreatePlaylistDeezer()
        {
            var userId       = UserId.Parse("12345");
            var playlistId   = PlaylistId.Parse("100");
            var playlistName = "playlistName";
            var accessToken  = "accessToken";

            var deezerService = DeezerApiBuilder.Create();

            var actualPlaylistId = deezerService
                                   .SetCreatePlaylist(playlistId)
                                   .Build()
                                   .CreatePlaylist(accessToken, userId, playlistName);

            Assert.AreEqual(actualPlaylistId, actualPlaylistId);
        }
Exemple #7
0
        public void RaiseMessageWhenDeleteUser()
        {
            var stream             = new MemoryEventStream();
            var deezerApi          = DeezerApiBuilder.Create().Build();
            var songRepository     = SongRepositoryBuilder.Create().Build();
            var playlistRepository = PlaylistRepositoryBuilder.Create().Build();

            stream.Add(new UserCreated(Identity.Parse("*****@*****.**", "dublow", "12345", "accessToken")));

            var publisher = new EventBus(stream);

            var user = new User(stream, publisher, deezerApi, songRepository, playlistRepository, 1);

            user.Delete();

            Assert.IsTrue(stream.GetEvents().Contains(new UserDeleted(UserId.Parse("12345"))));
        }
        public void UseRepositoryWhenPlaylistIsDeleted()
        {
            // arrange
            var userId       = UserId.Parse("12345");
            var playlistId   = PlaylistId.Parse("100");
            var playlistName = "playlistName";

            var mockedPlaylistRepository = PlaylistRepositoryBuilder.Create();

            mockedPlaylistRepository.Playlists.Add((userId, playlistId, playlistName));
            var playlistRepository = mockedPlaylistRepository.Build();
            var playlistHandler    = new PlaylistHandler(playlistRepository);

            // act
            playlistHandler.Handle(new PlaylistDeleted(userId, playlistId, playlistName));
            // assert
            Assert.AreEqual(0, mockedPlaylistRepository.Playlists.Count);
        }
Exemple #9
0
        public void NoRaiseMessageWhenAddPlaylistWithDeletedUser()
        {
            var stream             = new MemoryEventStream();
            var deezerApi          = DeezerApiBuilder.Create().Build();
            var songRepository     = SongRepositoryBuilder.Create().Build();
            var playlistRepository = PlaylistRepositoryBuilder.Create().Build();

            stream.Add(new UserCreated(Identity.Parse("*****@*****.**", "dublow", "12345", "accessToken")));
            stream.Add(new UserDeleted(UserId.Parse("12345")));

            var publisher = new EventBus(stream);

            var user = new User(stream, publisher, deezerApi, songRepository, playlistRepository, 1);

            user.AddPlaylist("playlistName");

            Assert.AreEqual(0, stream.GetEvents().OfType <PlaylistAdded>().Count());
        }
Exemple #10
0
        public void UseRepositoryWhenUserIsDeleted()
        {
            // arrange
            var email    = Email.Parse("*****@*****.**");
            var nickName = Nickname.Parse("nickname");
            var userId   = UserId.Parse("12345");

            var mockedUserRepository = UserRepositoryBuilder.Create();

            mockedUserRepository.Users.Add((email, nickName, userId));
            var userRepository = mockedUserRepository.Build();
            var userHandler    = new UserHandler(userRepository);

            // act
            userHandler.Handle(new UserDeleted(userId));
            // assert
            Assert.AreEqual(0, mockedUserRepository.Users.Count);
        }
Exemple #11
0
        public void RaiseMessageWhenAddPlaylistToUser()
        {
            var stream         = new MemoryEventStream();
            var deezerApi      = DeezerApiBuilder.Create().SetCreatePlaylist(PlaylistId.Parse("100")).Build();
            var songRepository = SongRepositoryBuilder.Create()
                                 .SetRandomSongs(1, new[] { new Song(SongId.Parse("100"), "title", "artist") }).Build();
            var playlistRepository = PlaylistRepositoryBuilder.Create().Build();

            stream.Add(new UserCreated(Identity.Parse("*****@*****.**", "dublow", "12345", "accessToken")));

            var publisher = new EventBus(stream);

            var user = new User(stream, publisher, deezerApi, songRepository, playlistRepository, 1);

            user.AddPlaylist("playlistName");

            Assert.IsTrue(stream.GetEvents().Contains(new PlaylistAdded(UserId.Parse("12345"), PlaylistId.Parse("100"), "playlistName")));
        }
Exemple #12
0
        public void GetPlaylistsByUserIdWithUserId()
        {
            // arrange
            var playlistId  = PlaylistId.Parse("100");
            var userId      = UserId.Parse("12345");
            var accessToken = "accessToken";

            var deezerService = DeezerApiBuilder
                                .Create()
                                .SetPlaylistIdsByUserId(new[] { playlistId })
                                .Build();
            // act
            var actual = deezerService.GetPlaylistIdsByUserId(accessToken, userId, s => true);

            // assert
            Assert.AreEqual(1, actual.Count());
            Assert.AreEqual(playlistId, actual.First());
        }
        public void UseRepositoryWhenPlaylistIsAdded()
        {
            // arrange
            var userId       = UserId.Parse("12345");
            var playlistId   = PlaylistId.Parse("100");
            var playlistName = "playlistName";

            var mockedPlaylistRepository = PlaylistRepositoryBuilder.Create();
            var playlistRepository       = mockedPlaylistRepository.Build();
            var playlistHandler          = new PlaylistHandler(playlistRepository);

            // act
            playlistHandler.Handle(new PlaylistAdded(userId, playlistId, playlistName));
            // assert
            var(actualUserId, actualPlaylisId, actualPlaylistName) = mockedPlaylistRepository.Playlists.First();
            Assert.AreEqual(userId, actualUserId);
            Assert.AreEqual(playlistId, actualPlaylisId);
            Assert.AreEqual(playlistName, actualPlaylistName);
        }
Exemple #14
0
        public void UseRepositoryWhenUserIsCreated()
        {
            // arrange
            var email       = "*****@*****.**";
            var nickName    = "nickname";
            var userId      = "12345";
            var accessToken = "accessToken";

            var mockedUserRepository = UserRepositoryBuilder.Create();
            var userRepository       = mockedUserRepository.Build();
            var userHandler          = new UserHandler(userRepository);
            // act
            var identity = Identity.Parse(email, nickName, userId, accessToken);

            userHandler.Handle(new UserCreated(identity));
            // assert
            var(actualEmail, actualNickname, actualUserId) = mockedUserRepository.Users.First();
            Assert.AreEqual(Email.Parse(email), actualEmail);
            Assert.AreEqual(Nickname.Parse(nickName), actualNickname);
            Assert.AreEqual(UserId.Parse(userId), actualUserId);
        }
Exemple #15
0
        public void UseRepositoryWhenSongIsAdded()
        {
            // arrange
            var userId     = UserId.Parse("12345");
            var playlistId = PlaylistId.Parse("100");
            var songId     = SongId.Parse("001");
            var title      = "title";
            var artist     = "artist";

            var mockedSongRepository = SongRepositoryBuilder.Create();
            var songRepository       = mockedSongRepository.Build();
            var songHandler          = new SongHandler(songRepository);

            // act
            songHandler.Handle(new SongAdded(userId, playlistId, songId, title, artist));
            // assert
            var(actualUserId, actualPlaylistId, actualSongId, actualTitle, actualArtist) = mockedSongRepository.Songs.First();
            Assert.AreEqual(userId, actualUserId);
            Assert.AreEqual(playlistId, actualPlaylistId);
            Assert.AreEqual(songId, actualSongId);
            Assert.AreEqual(title, actualTitle);
            Assert.AreEqual(artist, actualArtist);
        }
Exemple #16
0
 public void InvalidWhenCreateUserId()
 {
     Assert.Throws <ArgumentException>(() => UserId.Parse("abcde"));
 }
Exemple #17
0
        public HomeModule(IDeezerApi deezerApi, ISongRepository songRepository,
                          IPlaylistRepository playlistRepository, Environment environment,
                          IMetric metric)
        {
            _deezerApi          = deezerApi;
            _songRepository     = songRepository;
            _playlistRepository = playlistRepository;
            _environment        = environment;
            _metric             = metric;
            var eventStream    = new MemoryEventStream();
            var eventPublisher = new EventBus(eventStream);

            eventPublisher.Subscribe(new PlaylistHandler(playlistRepository));

            Get["/"] = _ =>
            {
                using (var timer = _metric.Timer("home"))
                {
                    var model = new
                    {
                        appid   = _environment.AppId,
                        channel = _environment.Channel
                    };

                    return(View["index", model]);
                }
            };

            Get["/channel"] = _ =>
            {
                using (var timer = _metric.Timer("channel"))
                {
                    var cacheExpire = 60 * 60 * 24 * 365;

                    return(View["channel"]
                           .WithHeader("Pragma", "public")
                           .WithHeader("Cache-Control", $"maxage={cacheExpire}")
                           .WithHeader("Expires", DateTime.Now.AddMinutes(cacheExpire).ToString("F")));
                }
            };

            Post["/login"] = _ =>
            {
                using (var timer = _metric.Timer("createplaylist"))
                {
                    var model = this.Bind <LoginViewModel>();

                    var user = User.Create(eventStream, eventPublisher, _deezerApi, _songRepository,
                                           _playlistRepository, model.Email, model.Nickname, model.UserId, model.AccessToken,
                                           _environment.Size);

                    user.AddPlaylist(model.PlaylistName);
                    Console.WriteLine(user.Playlist.PlaylistId.Value);
                    return(Response.AsJson(new { playlistCreated = !user.Playlist.PlaylistId.IsEmpty }));
                }
            };

            Get["/canCreatePlaylist/{userId}"] = parameters =>
            {
                using (var timer = _metric.Timer("hasplaylist"))
                {
                    var userId            = UserId.Parse((string)parameters.userId);
                    var canCreatePlaylist = _playlistRepository
                                            .CanCreatePlaylist(userId, DateTime.UtcNow.AddDays(-1));

                    return(Response.AsJson(new { canCreatePlaylist }));
                }
            };
        }
Exemple #18
0
        public AdminModule(IAdminRepository adminRepository,
                           IHmacProvider hmacProvider, IRequest request,
                           DatabaseSong dbsong, DatabaseDomain dbDomain,
                           IDeezerApi deezerApi, IRadioSongRepository radioSongRepository) : base("admin")
        {
            this.RequiresAuthentication();

            Get["/"] = _ => View["index"];

            Get["/AddUser"] = _ => View["addUser"];

            Post["/addUser"] = parameter =>
            {
                var model = this.Bind <AddUserViewModel>();

                if (!adminRepository.Exists(model.Login))
                {
                    adminRepository
                    .Add(
                        model.Login,
                        hmacProvider.GenerateHmac(model.Password));
                }

                return(Response.AsRedirect("/admin"));
            };

            Get["/GetCoordinate"] = _ =>
            {
                var hackManager = new HackManager(request);

                var flattenAsDateIp = File.ReadAllLines("/var/log/auth.log").Select(x =>
                {
                    var dateIp = DateIpParsor.Line(x);
                    return(dateIp);
                })
                                      .Where(x => !x.IsEmpty)
                                      .GroupBy(x => new { x.Date, x.Ip })
                                      .Select(x => DateIp.Create(x.Key.Date, x.Key.Ip))
                                      .ToList();

                var localizations = hackManager.GetLocalization(flattenAsDateIp);

                return(Response.AsJson(localizations));
            };

            Get["GenerateSong"] = _ =>
            {
                dbsong.Create();
                var playlistIds = deezerApi
                                  .GetPlaylistIdsByUserId(
                    "frKtbRGI9G18kljXooH4oQ0XbmntBD7oXeKBVBcVKIyjMMSDle0",
                    UserId.Parse("4934039"), s => s.ToLower().Contains("djam"));


                foreach (var playlistId in playlistIds)
                {
                    var songs = deezerApi.GetSongsByPlaylistId("frKtbRGI9G18kljXooH4oQ0XbmntBD7oXeKBVBcVKIyjMMSDle0", playlistId);

                    foreach (var deezerSong in songs)
                    {
                        if (!radioSongRepository.SongExists(deezerSong.Id))
                        {
                            Console.WriteLine(deezerSong.Id);
                            radioSongRepository.Add(deezerSong.Id, "NUSED", deezerSong.Title, deezerSong.Artist);
                        }
                    }
                }

                return("ok");
            };

            Get["GenerateDomain"] = _ =>
            {
                dbDomain.Create();

                dbsong.Create();
                return("ok");
            };
        }
Exemple #19
0
 public void ValidWhenCreateUserId()
 {
     UserId.Parse("12345");
     Assert.Pass();
 }