This commit is contained in:
parent
1dc4d308e4
commit
429e717a6e
@ -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
|
BIN
Stream/.DS_Store
vendored
Normal file
BIN
Stream/.DS_Store
vendored
Normal file
Binary file not shown.
@ -1,3 +1,3 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
|
||||
Console.WriteLine("Hello, World!");
|
||||
Stream.Stream.MyReplace("test.txt", 'u', 'a');
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user