コード例 #1
0
        public async Task ShouldReturnTrue_WhenUserFavoritedAudio()
        {
            // Assign
            var target = await RunAsDefaultUserAsync();

            target.TryGetUserId(out var targetId);

            var audio = new AudioFaker(targetId).Generate();

            InsertIntoDatabase(audio);

            var observer = await RunAsUserAsync();

            observer.TryGetUserId(out var observerId);

            var favoriteAudio = new FavoriteAudio
            {
                AudioId = audio.Id,
                UserId  = observerId,
            };

            InsertIntoDatabase(favoriteAudio);

            // Act
            var isFavorited = await SendAsync(new CheckIfAudioFavoritedQuery(audio.Id, observerId));

            // Assert
            isFavorited.Should().BeTrue();
        }
コード例 #2
0
        public async Task ShouldReturnFavoriteAudioSuccessfully()
        {
            // Assign
            var target = await RunAsDefaultUserAsync();

            target.TryGetUserId(out var targetId);

            var audioFaker = new AudioFaker(targetId);
            var audios     = audioFaker
                             .Generate(3);

            InsertIntoDatabase(audios.ToArray());

            var observer = await RunAsUserAsync();

            observer.TryGetUserId(out var observerId);
            observer.TryGetUserName(out var observerUsername);

            var favoriteAudios = new List <FavoriteAudio>();

            foreach (var audio in audios)
            {
                var favoriteAudio = new FavoriteAudio
                {
                    AudioId = audio.Id,
                    UserId  = observerId,
                };

                favoriteAudios.Add(favoriteAudio);
            }
            InsertIntoDatabase(favoriteAudios.ToArray());

            // Act
            var response = await SendAsync(new GetUserFavoriteAudiosQuery
            {
                Username = observerUsername
            });

            // Assert
            response.Should().NotBeNull();
            response.Items.Count.Should().Be(3);
        }
コード例 #3
0
        public async Task ShouldSuccessfullyUnfavoriteAudio()
        {
            // Assign
            var target = await RunAsDefaultUserAsync();

            target.TryGetUserId(out var targetId);

            var audio = new AudioFaker(targetId).Generate();

            InsertIntoDatabase(audio);

            var observer = await RunAsUserAsync();

            observer.TryGetUserId(out var observerId);

            var favoriteAudio = new FavoriteAudio
            {
                AudioId = audio.Id,
                UserId  = observerId,
            };

            InsertIntoDatabase(favoriteAudio);

            // Act
            await SendAsync(new SetFavoriteAudioCommand(audio.Id, observerId, false));

            var refetchAudio = ExecuteDbContext(database =>
            {
                return(database.Audios
                       .AsNoTracking()
                       .Include(u => u.FavoriteAudios)
                       .SingleOrDefault(a => a.Id == audio.Id));
            });

            // Assert
            refetchAudio.Should().NotBeNull();
            refetchAudio !.FavoriteAudios.Should().BeEmpty();
        }