From 429e717a6e23ea27aed2d71852aae59ae9a2857b Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 2 Nov 2023 20:51:39 +0100 Subject: [PATCH] feat: :sparkles: Finish MyReplace --- .gitea/workflows/test.yml | 2 ++ Stream/.DS_Store | Bin 0 -> 6148 bytes Stream/Program.cs | 2 +- Stream/Stream.cs | 34 ++++++++++++++++++++++++++++++++++ Tests/Stream/StreamTest.cs | 9 +++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 Stream/.DS_Store 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 0000000000000000000000000000000000000000..42451df95aa0f5aaee27ac30b951f0ea515bfef5 GIT binary patch literal 6148 zcmeHK%SyvQ6rE|SO({Ya3SADkEtozih?@}W4;ayfN=-=7V9b;zHH%WnT7Sqd@q4^? zW&#$o7P0rj%(>5*%z?~QD(3x!dVtqPv`eHnq zY&IS1==kL9a`v3Or1DME$$@Pp2L>y62gR)B)nBHGOdr8hWmj2*!~iis3=jjm&44)< ztnO~pK&vMPh=CdgaDNcc5M6_%MzwW7hu3F}w-8Z4$F~HcFz6aAH9`c0>ry~n%FPpl z>vHf5ljj;NHR^K4)yy!CnYntra5X#lg-U1K)kr-tKn!d%(A1`l=l=!#GPRHV?Gmzx z0b<~vF~D0>f9k=a%-Q;5d3e?eXb;d(Ft0=f1oW*-02sKB^i)vC1?rIJ8Z0&9DCk$^ PfOHX1giuEe`~m}C)pAK+ literal 0 HcmV?d00001 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