Exemplo n.º 1
0
        public async Task FileDataProvider_WriteFileContentModel()
        {
            //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, "testfiledataprovidertest3");
            string           tempFileName     = Path.Combine(tempDirectory, "file1.txt_result.txt");
            DataContentModel fileContentModel = new DataContentModel()
            {
                FilePath       = tempFileName,
                ContentStrings = new string[]
                {
                    "Line1",
                    "Line2",
                    "Line3"
                }
            };

            if (Directory.Exists(tempDirectory))
            {
                Directory.Delete(tempDirectory, true);
            }
            Directory.CreateDirectory(tempDirectory);

            //Act
            await fileDataProvider.WriteFileAsync(fileContentModel);

            string[] result = await File.ReadAllLinesAsync(tempFileName);

            Directory.Delete(tempDirectory, true);

            //Assert
            Assert.Equal(fileContentModel.ContentStrings, result);
        }