예제 #1
0
        public async Task ItDoesNotRedownloadDownloadAFileThatExists()
        {
            var expectedPath = Path.Combine(AppContext.BaseDirectory, "microsoft.com.1.html");
            var task         = new DownloadFile
            {
                Uri             = "http://example.org/index.html",
                DestinationPath = expectedPath,
                BuildEngine     = new MockEngine(_output),
            };

            const string placeholder = "Dummy content";

            File.WriteAllText(expectedPath, placeholder);

            Assert.True(await task.ExecuteAsync(), "Task should pass");

            Assert.Equal(placeholder, File.ReadAllText(expectedPath));

            task.Overwrite = true;

            Assert.True(await task.ExecuteAsync(), "Task should pass");
            Assert.NotEqual(placeholder, File.ReadAllText(expectedPath));
        }
예제 #2
0
        public async Task ItFailsForFilesThatDoNotExist()
        {
            var engine = new MockEngine(_output)
            {
                ContinueOnError = true
            };
            var task = new DownloadFile
            {
                Uri             = "http://localhost/this/file/does/not/exist",
                DestinationPath = Path.Combine(AppContext.BaseDirectory, "dummy.txt"),
                BuildEngine     = engine,
            };

            Assert.False(await task.ExecuteAsync(), "Task should fail");
            Assert.NotEmpty(engine.Errors);
        }
예제 #3
0
        public async Task ItDownloadAFile()
        {
            var expectedPath = Path.Combine(AppContext.BaseDirectory, "microsoft.com.2.html");
            var task         = new DownloadFile
            {
                Uri             = "http://example.org/index.html",
                DestinationPath = expectedPath,
                BuildEngine     = new MockEngine(_output),
            };

            if (File.Exists(expectedPath))
            {
                File.Delete(expectedPath);
            }

            Assert.True(await task.ExecuteAsync(), "Task should pass");
            Assert.True(File.Exists(expectedPath), "The file should exist");
        }
예제 #4
0
        public async Task ItFailsIfFileAlreadyExists()
        {
            var engine = new MockEngine(_output)
            {
                ContinueOnError = true
            };
            var expectedPath = Path.Combine(AppContext.BaseDirectory, Path.GetRandomFileName());

            File.WriteAllText(expectedPath, "");
            var task = new DownloadFile
            {
                Uri         = "http://localhost/this/file/does/not/exist",
                OutputPath  = expectedPath,
                BuildEngine = engine,
            };

            Assert.False(await task.ExecuteAsync(), "Task should fail");
            Assert.NotEmpty(engine.Errors);
        }