public Either <DomainError, CommandResult> Handle(AddTrackToPLayList command)
        {
            var playList = playListPersistence.GetPlayList(command.PlaylistId);
            var error    = playList.Add(Track.With(command.TrackId));

            if (error.IsSome)
            {
                return(error.ValueUnsafe());
            }

            playListPersistence.Persist(playList);
            eventPublisher.Publish(playList.Events());
            return(CommandResult.Success);
        }
        public void add_a_track_to_a_play_list()
        {
            var aTrackId    = ATrack.Id;
            var aPlaylistId = APlaylist.Id;
            var aPlayList   = new PlayListBuilder()
                              .WithId(aPlaylistId)
                              .Build();

            playListPersistence.GetPlayList(aPlaylistId).Returns(aPlayList);
            var command = new AddTrackToPLayList(aTrackId, aPlaylistId);

            var result = addTrackToPlayListCommandHandler.Handle(command);

            result.IsRight.Should().BeTrue();
            VerifyPlayListHasBeenPersistedWith(aPlaylistId, aTrackId);
            VerifyEventHasBeenRaised(new TrackHasBeenAddedToPlayList(aTrackId, aPlaylistId), eventPublisher);
        }
        public void do_not_add_a_track_twice()
        {
            var aTrackId    = ATrack.Id;
            var aPlaylistId = APlaylist.Id;
            var aPlayList   = new PlayListBuilder()
                              .WithId(aPlaylistId)
                              .AddTrack(new TrackBuilder()
                                        .WithId(aTrackId)
                                        .Build())
                              .Build();

            playListPersistence.GetPlayList(aPlaylistId).Returns(aPlayList);
            var command = new AddTrackToPLayList(aTrackId, aPlaylistId);

            var result = addTrackToPlayListCommandHandler.Handle(command);

            result.IsLeft.Should().BeTrue();
            result.IfLeft(error => error.Should().Be(DomainError.CannotAddSameTrackTwice));
            playListPersistence.DidNotReceive().Persist(Arg.Any <PlayList>());
            eventPublisher.DidNotReceive().Publish(Arg.Any <List <Event> >());
        }
        public Either <DomainError, CommandResult> Process(AddTrackToPLayList command)
        {
            var commandHandler = tracksCommandHandlerCreator.CreateAddTrackToPlayListCommandHandler();

            return(commandHandler.Handle(command));
        }