Пример #1
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)));
        }
Пример #2
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")));
        }
Пример #3
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"))));
        }
Пример #4
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());
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }