Ejemplo n.º 1
0
        public async Task GetPlaylistDetails_ForExistingOwner_DetailsContainsOwnerUsername()
        {
            var playlistOwner = new IdentityUser(userName: "******");

            var userRepo = Substitute.For <IUserRepository>();

            userRepo
            .FindByIdAsync(Arg.Any <string>(), CancellationToken.None)
            .Returns(x => playlistOwner);

            var playlistRepo = Substitute.For <IPlaylistEntriesRepository>();

            playlistRepo
            .GetByIdAsync(Arg.Any <Guid>(), CancellationToken.None)
            .Returns(x => new PlaylistBuilder().Build());

            var sut = new PlaylistServiceBuilder()
                      .WithPlaylistRepository(playlistRepo)
                      .WithUserRepository(userRepo)
                      .WithMapper(new MapperBuilder().WithDefaultProfile().Build())
                      .Build();

            var playlistDetails = await sut.GetPlaylistDetails(new Guid(), CancellationToken.None);

            var actual = playlistDetails.OwnerUsername;

            actual.Should().Be("Foo");
        }
Ejemplo n.º 2
0
        public async Task GetPlaylistDetails_ForPlaylistContainingAnAudio_DetailsContainsASingleAudio()
        {
            var playlist = new PlaylistBuilder()
                           .WithId(GuidFactory.MakeFromInt(42))
                           .Build();

            var playlistRepo = Substitute.For <IPlaylistEntriesRepository>();

            playlistRepo
            .GetByIdAsync(Arg.Any <Guid>(), CancellationToken.None)
            .Returns(x => playlist);

            var audioRepo = Substitute.For <IAudioEntriesRepository>();

            audioRepo
            .GetAudioEntriesByPlaylistAsync(playlist.PlaylistId, CancellationToken.None)
            .Returns(x => new[] { new AudioBuilder().Build() });

            var sut = new PlaylistServiceBuilder()
                      .WithPlaylistRepository(playlistRepo)
                      .WithAudioRepository(audioRepo)
                      .WithMapper(new MapperBuilder().WithDefaultProfile().Build())
                      .Build();

            var playlistDetails = await sut.GetPlaylistDetails(playlist.PlaylistId, CancellationToken.None);

            var actual = playlistDetails.AudioEntries;

            actual.Should().ContainSingle();
        }
Ejemplo n.º 3
0
        public async Task GetPlaylistDetails_ForNonexistentPlaylist_ReturnsNull()
        {
            var playlistRepo = Substitute.For <IPlaylistEntriesRepository>();

            playlistRepo
            .GetByIdAsync(Arg.Any <Guid>(), CancellationToken.None)
            .Returns(x => (Playlist)null);

            var sut = new PlaylistServiceBuilder()
                      .WithPlaylistRepository(playlistRepo)
                      .Build();

            var actual = await sut.GetPlaylistDetails(new Guid(), CancellationToken.None);

            actual.Should().BeNull();
        }