Beispiel #1
0
        public async Task FileDataProvider_ReturnFileContentModel()
        {
            //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, "testfiledataprovidertest2");
            string           tempFileName           = Path.Combine(tempDirectory, "file1.txt");
            DataContentModel assertFileContentModel = new DataContentModel()
            {
                FilePath       = tempFileName,
                ContentStrings = new string[]
                {
                    "Line1",
                    "Line2",
                    "Line3"
                }
            };

            if (Directory.Exists(tempDirectory))
            {
                Directory.Delete(tempDirectory, true);
            }
            Directory.CreateDirectory(tempDirectory);
            await File.WriteAllLinesAsync(tempFileName, assertFileContentModel.ContentStrings);

            //Act
            DataContentModel resultModel = await fileDataProvider.ReadDataToModelAsync(tempFileName);

            Directory.Delete(tempDirectory, true);

            //Assert
            Assert.Equal(assertFileContentModel, resultModel);
        }