コード例 #1
0
        public void UseRepositoryWhenRadioSongWithDeezerSongIdIsParsed()
        {
            // arrange
            var songId    = SongId.Parse("001");
            var radioName = "djam";
            var title     = "title";
            var artist    = "artist";

            var mockedRadioSongRepository = RadioSongRepositoryBuilder.Create();
            var radioSongRepository       = mockedRadioSongRepository.Build();
            var deezerApi = DeezerApiBuilder
                            .Create()
                            .SetSong(new DeezerSong(songId, title, artist))
                            .Build();
            var radioSongHandler = new RadioSongHandler(radioSongRepository, deezerApi);

            // act
            var radioSongParsed = new RadioSongWithDeezerSongIdParsed(radioName, songId);

            radioSongHandler.Handle(radioSongParsed);
            // assert
            var(actualSongId, actualName, actualTitle, actualArtist) = mockedRadioSongRepository.RadioSongs.First();
            Assert.AreEqual(songId, actualSongId);
            Assert.AreEqual(radioName, actualName);
            Assert.AreEqual(title, actualTitle);
            Assert.AreEqual(artist, actualArtist);
        }
コード例 #2
0
ファイル: DeezerShould.cs プロジェクト: dublow/CqrsRadio
        public void DeletePlaylistDeezer()
        {
            var playlistId  = PlaylistId.Parse("100");
            var accessToken = "accessToken";

            var deezerService = DeezerApiBuilder.Create();

            deezerService.Build().DeletePlaylist(accessToken, playlistId);

            Assert.AreEqual(1, deezerService.PlaylistDeleted);
        }
コード例 #3
0
        public void RaiseMessageWhenCreateUser()
        {
            var stream             = new MemoryEventStream();
            var publisher          = new EventBus(stream);
            var deezerApi          = DeezerApiBuilder.Create().Build();
            var songRepository     = SongRepositoryBuilder.Create().Build();
            var playlistRepository = PlaylistRepositoryBuilder.Create().Build();

            User.Create(stream, publisher, deezerApi, songRepository, playlistRepository, "*****@*****.**", "dublow", "12345", "accessToken");

            var identity = Identity.Parse("*****@*****.**", "dublow", "12345", "accessToken");

            Assert.IsTrue(stream.GetEvents().Contains(new UserCreated(identity)));
        }
コード例 #4
0
ファイル: DeezerShould.cs プロジェクト: dublow/CqrsRadio
        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);
        }
コード例 #5
0
ファイル: DeezerShould.cs プロジェクト: dublow/CqrsRadio
        public void GetSongFromDeezerWhenSongNotFound()
        {
            // arrange
            string title       = "title";
            string artist      = "artist";
            var    accessToken = "accessToken";

            var deezerService = DeezerApiBuilder
                                .Create()
                                .SetSong(DeezerSong.Empty)
                                .Build();
            // act
            var actual = deezerService.GetSong(accessToken, title, artist);

            // assert
            Assert.AreEqual(DeezerSong.Empty, actual);
        }
コード例 #6
0
ファイル: DeezerShould.cs プロジェクト: dublow/CqrsRadio
        public void AddSongsToPlaylistDeezer()
        {
            var playlistId  = PlaylistId.Parse("100");
            var accessToken = "accessToken";
            var songIds     = new []
            {
                SongId.Parse("001"),
                SongId.Parse("002"),
                SongId.Parse("003")
            };

            var deezerService = DeezerApiBuilder.Create();

            deezerService.Build().AddSongsToPlaylist(accessToken, playlistId, songIds);

            Assert.AreEqual(3, deezerService.SongsAdded);
        }
コード例 #7
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")));
        }
コード例 #8
0
        public void NoRaiseMessageWhenTwiceDeleteUser()
        {
            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();
            user.Delete();

            Assert.IsTrue(stream.GetEvents().Contains(new UserDeleted(UserId.Parse("12345"))));
        }
コード例 #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());
        }
コード例 #10
0
        public void UseRepositoryWhenRadioSongIsOnError()
        {
            // arrange
            var mockedRadioSongRepository = RadioSongRepositoryBuilder.Create();
            var radioSongRepository       = mockedRadioSongRepository.Build();
            var deezerApi = DeezerApiBuilder
                            .Create()
                            .Build();
            var radioSongHandler = new RadioSongHandler(radioSongRepository, deezerApi);

            (string name, string error) = ("djam", "error");
            // act
            radioSongHandler.Handle(new RadioSongError("djam", "error"));
            // assert
            var(actualName, actualError) = mockedRadioSongRepository.RadioSongErrors.First();
            Assert.AreEqual(name, actualName);
            Assert.AreEqual(error, actualError);
        }
コード例 #11
0
ファイル: DeezerShould.cs プロジェクト: dublow/CqrsRadio
        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());
        }
コード例 #12
0
        public void UseRepositoryWhenRadioSongIsDuplicated()
        {
            // arrange
            var mockedRadioSongRepository = RadioSongRepositoryBuilder.Create();
            var radioSongRepository       = mockedRadioSongRepository.Build();
            var deezerApi = DeezerApiBuilder
                            .Create()
                            .Build();
            var radioSongHandler = new RadioSongHandler(radioSongRepository, deezerApi);

            (string name, string title, string artist) = ("djam", "title", "artist");
            // act
            radioSongHandler.Handle(new RadioSongDuplicate("djam", "title", "artist"));
            // assert
            var(actualName, actualTitle, actualArtist) = mockedRadioSongRepository.RadioSongDuplicate.First();
            Assert.AreEqual(name, actualName);
            Assert.AreEqual(title, actualTitle);
            Assert.AreEqual(artist, actualArtist);
        }
コード例 #13
0
ファイル: DeezerShould.cs プロジェクト: dublow/CqrsRadio
        public void GetSongFromDeezerWhenSongExists()
        {
            // arrange
            var    songId      = SongId.Parse("001");
            string title       = "title";
            string artist      = "artist";
            var    accessToken = "accessToken";

            var deezerService = DeezerApiBuilder
                                .Create()
                                .SetSong(new DeezerSong(songId, title, artist))
                                .Build();
            // act
            var actual = deezerService.GetSong(accessToken, title, artist);

            // assert
            Assert.AreEqual(songId, actual.Id);
            Assert.AreEqual(title, actual.Title);
            Assert.AreEqual(artist, actual.Artist);
        }
コード例 #14
0
ファイル: DeezerShould.cs プロジェクト: dublow/CqrsRadio
        public void GetSongsByPlaylistIdWithPlaylistId()
        {
            // arrange
            var playlistId  = PlaylistId.Parse("100");
            var songId      = SongId.Parse("001");
            var title       = "title";
            var artist      = "artist";
            var accessToken = "accessToken";

            var deezerService = DeezerApiBuilder
                                .Create()
                                .SetSongsByPlaylistId(new [] { new DeezerSong(songId, title, artist) })
                                .Build();
            // act
            var actual = deezerService.GetSongsByPlaylistId(accessToken, playlistId);

            // assert
            Assert.AreEqual(1, actual.Count());
            Assert.AreEqual(songId, actual.First().Id);
            Assert.AreEqual(title, actual.First().Title);
            Assert.AreEqual(artist, actual.First().Artist);
        }