コード例 #1
0
        public async Task GetSongByIdAsyncTest_ValidId_CorrectData()
        {
            // Arrange
            var songRepoMock = new Mock <ISongRepository>();

            songRepoMock.Setup(mock => mock.GetSongByIdAsync(1))
            .ReturnsAsync(new SongDataDto
            {
                Id       = 1,
                Name     = "Test",
                FileName = "test.mp3",
                Duration = 1337
            })
            .Verifiable();

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

            // Act
            var song = await songCollection.GetSongByIdAsync(1);

            // Assert
            songRepoMock.Verify();
            Assert.AreEqual(1, song.Id);
            Assert.AreEqual("Test", song.Name);
            Assert.AreEqual("test.mp3", song.FileName);
            Assert.AreEqual(1337, song.Duration);
        }
コード例 #2
0
        public async Task GetSongByIdAsyncTest_InvalidId_Null()
        {
            // Arrange
            var songRepoMock = new Mock <ISongRepository>();

            songRepoMock.Setup(mock => mock.GetSongByIdAsync(1))
            .ReturnsAsync(null as SongDataDto)
            .Verifiable();

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

            // Act
            var song = await songCollection.GetSongByIdAsync(1);

            // Assert
            songRepoMock.Verify();
            Assert.AreEqual(null, song);
        }