diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index c1a0d32..f80c6de 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -20,5 +20,7 @@ jobs: # Add files into /Tests/bin/Debug/net7.0 and create thisfileexist.txt run: | echo "incredible file" > /workspace/EPITA-TP-PROG/B2B-Training/Tests/bin/Debug/net7.0/thisfileexist.txt + echo -n "Bonjour,\nCeci est un message de test.\nJ'espere que vous allez reussir vos exams :D." > /workspace/EPITA-TP-PROG/B2B-Training/Tests/bin/Debug/net7.0/MyReplaceTestFile.txt + echo "✅ Finished" - name: "✅ Test" run: dotnet test \ No newline at end of file diff --git a/Stream/.DS_Store b/Stream/.DS_Store new file mode 100644 index 0000000..42451df Binary files /dev/null and b/Stream/.DS_Store differ diff --git a/Stream/Program.cs b/Stream/Program.cs index e5dff12..0f5d5ee 100644 --- a/Stream/Program.cs +++ b/Stream/Program.cs @@ -1,3 +1,3 @@ // See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); \ No newline at end of file +Stream.Stream.MyReplace("test.txt", 'u', 'a'); \ No newline at end of file diff --git a/Stream/Stream.cs b/Stream/Stream.cs index 603bc08..6bf7b6a 100644 --- a/Stream/Stream.cs +++ b/Stream/Stream.cs @@ -7,4 +7,38 @@ public class Stream { return File.Exists(path); } + + public static void MyReplace(string path, char toReplace, char replace) + { + string preResult = String.Empty; + string result = String.Empty; + try + { + using (StreamReader sr = new StreamReader(path)) + { + preResult = sr.ReadToEnd(); + } + + foreach (var chara in preResult) + { + if (chara == toReplace) + { + result += replace; + } + else + { + result += chara; + } + } + + using (StreamWriter sw = new StreamWriter(path)) + { + sw.WriteLine(result); + } + } + catch (Exception) + { + throw new ArgumentException("Error"); + } + } } \ No newline at end of file diff --git a/Tests/Stream/StreamTest.cs b/Tests/Stream/StreamTest.cs index 89f7157..9459bc9 100644 --- a/Tests/Stream/StreamTest.cs +++ b/Tests/Stream/StreamTest.cs @@ -10,4 +10,13 @@ public class StreamTest { Assert.Equal(expected, global::Stream.Stream.ExistFile(filePath)); } + + [Theory] + [InlineData("MyReplaceTestFile.txt", 'e', 'f')] + + public void MyReplaceTest(string filePath, char toReplace, char replace) + { + global::Stream.Stream.MyReplace(filePath, toReplace, replace); + Assert.Equal("Bonjour,\nCfci fst un mfssagf df tfst.\nJ'fspfrf quf vous allfz rfussir vos fxams :D.\n", File.ReadAllText(filePath)); + } } \ No newline at end of file