Пример #1
0
        public async Task GetSongsByAlbumIdAsyncTest_ValidId_OneSong()
        {
            // Arrange
            SongDataDto[] result =
            {
                new SongDataDto
                {
                    Id       = 1,
                    Name     = "Test",
                    FileName = "test.mp3",
                    Duration = 1337
                },
            };
            var songRepoMock = new Mock <ISongRepository>();

            songRepoMock.Setup(mock => mock.GetSongsByAlbumId(1))
            .ReturnsAsync(result)
            .Verifiable();

            var songCollection = new SongCollection(songRepoMock.Object, _dependencyMapper);

            // Act
            var songs = (await songCollection.GetSongsByAlbumIdAsync(1)).ToArray();

            // Assert
            songRepoMock.Verify();
            Assert.AreEqual(1, songs.Length);
            Assert.AreEqual(1, songs[0].Id);
            Assert.AreEqual("Test", songs[0].Name);
            Assert.AreEqual("test.mp3", songs[0].FileName);
            Assert.AreEqual(1337, songs[0].Duration);
        }
Пример #2
0
        public async Task GetSongsByAlbumIdAsyncTest_InvalidId_EmptyArray()
        {
            // Arrange
            var songRepoMock = new Mock <ISongRepository>();

            songRepoMock.Setup(mock => mock.GetSongsByAlbumId(1))
            .ReturnsAsync(new SongDataDto[] { })
            .Verifiable();

            var songCollection = new SongCollection(songRepoMock.Object, _dependencyMapper);

            // Act
            var songs = (await songCollection.GetSongsByAlbumIdAsync(1)).ToArray();

            // Assert
            songRepoMock.Verify();
            Assert.AreEqual(0, songs.Length);
        }
Пример #3
0
        public async Task GetSongsByAlbumIdAsyncTest_ValidId_MultipleSongs()
        {
            // Arrange
            SongDataDto[] result =
            {
                new SongDataDto
                {
                    Id       = 1,
                    Name     = "Test",
                    FileName = "test.mp3",
                    Duration = 1337
                },
                new SongDataDto
                {
                    Id       = 2,
                    Name     = "Test 2",
                    FileName = "test2.mp3",
                    Duration = 420
                },
            };
            var songRepoMock = new Mock <ISongRepository>();

            songRepoMock.Setup(mock => mock.GetSongsByAlbumId(1))
            .ReturnsAsync(result)
            .Verifiable();

            var songCollection = new SongCollection(songRepoMock.Object, _dependencyMapper);

            // Act
            var songs = (await songCollection.GetSongsByAlbumIdAsync(1)).ToArray();

            // Assert
            songRepoMock.Verify();
            Assert.AreEqual(2, songs.Length);
            for (int i = 0; i < 2; ++i)
            {
                Assert.AreEqual(result[i].Id, songs[i].Id);
                Assert.AreEqual(result[i].Name, songs[i].Name);
                Assert.AreEqual(result[i].FileName, songs[i].FileName);
                Assert.AreEqual(result[i].Duration, songs[i].Duration);
            }
        }