示例#1
0
        public async Task CreateSongAsyncTest()
        {
            // Arrange
            var songRepoMock = new Mock <ISongRepository>();

            songRepoMock.Setup(mock => mock.CreateSongAsync(It.Is((NewSongDataDto dataDto) => (
                                                                      dataDto.AlbumId == 1 &&
                                                                      dataDto.Name == "Test" &&
                                                                      dataDto.Duration == 1337
                                                                      ))))
            .ReturnsAsync(new SongDataDto
            {
                Id       = 1,
                AlbumId  = 1,
                Name     = "Test",
                FileName = "",
                Duration = 1337,
            })
            .Verifiable();

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

            // Act
            var song = await songCollection.CreateSongAsync(1, "Test", 1337);

            // Assert
            songRepoMock.Verify();
            Assert.AreEqual(1, song.Id);
            Assert.AreEqual("Test", song.Name);
            Assert.AreEqual("", song.FileName);
            Assert.AreEqual(1337, song.Duration);
        }