コード例 #1
0
        public void FileDataProvider_ReturnFileNamesList()
        {
            //Arrange
            Mock <ILogger <FileDataProvider> > moq = new Mock <ILogger <FileDataProvider> >(MockBehavior.Loose);

            FileDataProvider fileDataProvider    = new FileDataProvider(moq.Object);
            string           path                = Path.GetTempPath();
            string           tempDirectory       = Path.Combine(path, "testfiledataprovidertest1");
            List <string>    assertFileNamesList = new List <string>
            {
                Path.Combine(tempDirectory, "file1.txt"),
                Path.Combine(tempDirectory, "file2.txt"),
                Path.Combine(tempDirectory, "file3.txt"),
                Path.Combine(tempDirectory, "file4.txt"),
            };

            if (Directory.Exists(tempDirectory))
            {
                Directory.Delete(tempDirectory, true);
            }
            Directory.CreateDirectory(tempDirectory);
            assertFileNamesList.ForEach(async fileName => await File.WriteAllTextAsync(fileName, ""));

            //Act
            List <string> resultList = fileDataProvider.GetDataNamesEnumerator(tempDirectory).OrderBy(name => name).ToList();

            Directory.Delete(tempDirectory, true);

            //Assert
            Assert.Equal(assertFileNamesList, resultList);
        }