diff --git a/core/encoding/cyrillic-to-latin/cs/Common/Common.cs b/core/encoding/cyrillic-to-latin/cs/Common/Common.cs new file mode 100644 index 00000000000..511ca3c3107 --- /dev/null +++ b/core/encoding/cyrillic-to-latin/cs/Common/Common.cs @@ -0,0 +1,15 @@ +using System; +namespace CyrillicToLatin.Common +{ + public static class Common + { + public const string NoSourceOrDestinationFile = "There must be a source and a destination file."; + + public const string FileDoesntExist = "The source file does not exist."; + + public const string WrongDirectory = "Invalid directory: {0}"; + + public const string WrongIO = "I/O exception: {0}"; + } +} + diff --git a/core/encoding/cyrillic-to-latin/cs/ConsoleModule.cs b/core/encoding/cyrillic-to-latin/cs/ConsoleModule.cs index 66864c65c49..a1b2cd71bf4 100644 --- a/core/encoding/cyrillic-to-latin/cs/ConsoleModule.cs +++ b/core/encoding/cyrillic-to-latin/cs/ConsoleModule.cs @@ -1,6 +1,9 @@ using System; using System.IO; +using System.Security.AccessControl; using System.Text; +using CyrillicToLatin.Common; + class ConsoleModule { @@ -9,9 +12,9 @@ static void Main() string[] args = Environment.GetCommandLineArgs(); // Get command line arguments. - if (args.Length != 3 || String.IsNullOrWhiteSpace(args[1]) || String.IsNullOrWhiteSpace(args[2])) + if (args.Length != 3 || string.IsNullOrWhiteSpace(args[1]) || string.IsNullOrWhiteSpace(args[2])) { - Console.WriteLine("There must be a source and a destination file."); + Console.WriteLine(Common.NoSourceOrDestinationFile); ShowSyntax(); return; } @@ -21,7 +24,7 @@ static void Main() if (!File.Exists(source)) { - Console.WriteLine("The source file does not exist."); + Console.WriteLine(Common.NoSourceOrDestinationFile); return; } @@ -74,12 +77,12 @@ static void Main() } catch (DirectoryNotFoundException e) { - Console.WriteLine($"Invalid directory: {e.Message}"); + Console.WriteLine(Common.WrongDirectory); return; } catch (IOException e) { - Console.WriteLine($"I/O exception: {e.Message}"); + Console.WriteLine(Common.WrongIO); return; } } diff --git a/core/encoding/cyrillic-to-latin/cs/CyrillicToLatin.csproj b/core/encoding/cyrillic-to-latin/cs/CyrillicToLatin.csproj index a4fb324cffe..92301346999 100644 --- a/core/encoding/cyrillic-to-latin/cs/CyrillicToLatin.csproj +++ b/core/encoding/cyrillic-to-latin/cs/CyrillicToLatin.csproj @@ -9,4 +9,10 @@ + + + + + + diff --git a/core/encoding/cyrillic-to-latin/cs/CyrillicToLatinFallback.cs b/core/encoding/cyrillic-to-latin/cs/CyrillicToLatinFallback.cs index 8fdee54dea8..c0d09e321c6 100644 --- a/core/encoding/cyrillic-to-latin/cs/CyrillicToLatinFallback.cs +++ b/core/encoding/cyrillic-to-latin/cs/CyrillicToLatinFallback.cs @@ -5,11 +5,11 @@ class CyrillicToLatinFallback : EncoderFallback { - private Dictionary table; + private Dictionary table; public CyrillicToLatinFallback() { - table = new Dictionary(); + table = new Dictionary(); // Define mappings. // Uppercase modern Cyrillic characters. table.Add('\u0410', "A"); @@ -92,12 +92,12 @@ public override int MaxCharCount public class CyrillicToLatinFallbackBuffer : EncoderFallbackBuffer { - private Dictionary table; + private Dictionary table; private int bufferIndex; private string buffer; private int leftToReturn; - internal CyrillicToLatinFallbackBuffer(Dictionary table) + internal CyrillicToLatinFallbackBuffer(Dictionary table) { this.table = table; this.bufferIndex = -1; @@ -153,4 +153,4 @@ public override int Remaining { get { return leftToReturn; } } -} +} \ No newline at end of file diff --git a/csharp/classes-quickstart/BankAccount.cs b/csharp/classes-quickstart/BankAccount.cs index 6385c069d07..01ae6e84e36 100644 --- a/csharp/classes-quickstart/BankAccount.cs +++ b/csharp/classes-quickstart/BankAccount.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; +using classes.Contracts; namespace classes { - public class BankAccount + public class BankAccount : IBank { - public string Number { get; } + public string Number { get; set; } public string Owner { get; set; } #region BalanceComputation public decimal Balance @@ -21,6 +22,7 @@ public decimal Balance return balance; } } + #endregion private static int accountNumberSeed = 1234567890; @@ -36,7 +38,8 @@ public BankAccount(string name, decimal initialBalance) #endregion #region TransactionDeclaration - private List allTransactions = new List(); + + private List allTransactions = new List(); #endregion #region DepositAndWithdrawal @@ -82,4 +85,4 @@ public string GetAccountHistory() } #endregion } -} +} \ No newline at end of file diff --git a/csharp/classes-quickstart/Contracts/IBank.cs b/csharp/classes-quickstart/Contracts/IBank.cs new file mode 100644 index 00000000000..ac1bcd4995a --- /dev/null +++ b/csharp/classes-quickstart/Contracts/IBank.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; + +namespace classes.Contracts +{ + public interface IBank + { + public string Number { get; } + + public string Owner { get; } + + public decimal Balance { get; } + } +} \ No newline at end of file diff --git a/csharp/classes-quickstart/Contracts/ITransaction.cs b/csharp/classes-quickstart/Contracts/ITransaction.cs new file mode 100644 index 00000000000..02c4d382a44 --- /dev/null +++ b/csharp/classes-quickstart/Contracts/ITransaction.cs @@ -0,0 +1,12 @@ +using System; +namespace classes.Contracts +{ + public interface ITransaction + { + public decimal Amount { get; } + + public DateTime Date { get; } + + public string Notes { get; } + } +} \ No newline at end of file diff --git a/csharp/classes-quickstart/classes.csproj b/csharp/classes-quickstart/classes.csproj index 120e38c3150..5c938e63a4c 100644 --- a/csharp/classes-quickstart/classes.csproj +++ b/csharp/classes-quickstart/classes.csproj @@ -5,4 +5,10 @@ net7.0 + + + + + + diff --git a/csharp/classes-quickstart/transaction.cs b/csharp/classes-quickstart/transaction.cs index 198418c62dd..ca256132329 100644 --- a/csharp/classes-quickstart/transaction.cs +++ b/csharp/classes-quickstart/transaction.cs @@ -1,12 +1,13 @@ using System; +using classes.Contracts; namespace classes { - public class Transaction + public class Transaction : ITransaction { - public decimal Amount { get; } + public decimal Amount { get; set; } public DateTime Date { get; } - public string Notes { get; } + public string Notes { get; set; } public Transaction(decimal amount, DateTime date, string note) { @@ -15,4 +16,4 @@ public Transaction(decimal amount, DateTime date, string note) this.Notes = note; } } -} +} \ No newline at end of file diff --git a/csharp/events/VersionOne.cs b/csharp/events/VersionOne.cs index f9959043b2a..03913237fff 100644 --- a/csharp/events/VersionOne.cs +++ b/csharp/events/VersionOne.cs @@ -13,9 +13,11 @@ public class FileSearcher public void Search(string directory, string searchPattern) { - foreach (var file in Directory.EnumerateFiles(directory, searchPattern)) + var enumeratedFiles = Directory.EnumerateFiles(directory, searchPattern); + + foreach (var file in enumeratedFiles) { FileFound?.Invoke(this, new FileFoundArgs(file)); } } -} +} \ No newline at end of file diff --git a/csharp/list-quickstart/Program.cs b/csharp/list-quickstart/Program.cs index 631ef759793..fe4c4bde932 100644 --- a/csharp/list-quickstart/Program.cs +++ b/csharp/list-quickstart/Program.cs @@ -38,25 +38,16 @@ void WorkWithString() Console.WriteLine($"The list has {names.Count} people in it"); var index = names.IndexOf("Felipe"); - if (index == -1) - { - Console.WriteLine($"When an item is not found, IndexOf returns {index}"); - } - else - { - Console.WriteLine($"The name {names[index]} is at index {index}"); - } + + Console.WriteLine(index == -1 + ? $"When an item is not found, IndexOf returns {index}" + : $"The name {names[index]} is at index {index}"); index = names.IndexOf("Not Found"); - if (index == -1) - { - Console.WriteLine($"When an item is not found, IndexOf returns {index}"); - } - else - { - Console.WriteLine($"The name {names[index]} is at index {index}"); - } + Console.WriteLine(index == -1 + ? $"When an item is not found, IndexOf returns {index}" + : $"The name {names[index]} is at index {index}"); names.Sort(); foreach (var name in names) diff --git a/csharp/unit-testing/NUnit.TestProject/ByOrder.cs b/csharp/unit-testing/NUnit.TestProject/ByOrder.cs index c7749d3584a..a9d97c43eed 100644 --- a/csharp/unit-testing/NUnit.TestProject/ByOrder.cs +++ b/csharp/unit-testing/NUnit.TestProject/ByOrder.cs @@ -10,7 +10,7 @@ public class ByOrder public static bool Test3Called; [Test, Order(5)] - public void Test1() + public void Should_Run_Last_After_Other_Tests_And_Validate_Previous_Execution_State() { Test3Called = true; @@ -20,7 +20,7 @@ public void Test1() } [Test, Order(0)] - public void Test2B() + public void Should_Run_Second_After_First_Test_And_Validate_Only_First_Has_Run() { Test2BCalled = true; @@ -30,7 +30,7 @@ public void Test2B() } [Test] - public void Test2A() + public void Should_Run_Third_When_No_Order_Is_Specified_And_All_Previous_Tests_Are_Called() { Test2ACalled = true; @@ -40,7 +40,7 @@ public void Test2A() } [Test, Order(-5)] - public void Test3() + public void Should_Run_First_Before_All_Other_Tests_And_Ensure_No_Prior_Execution() { Test1Called = true; @@ -49,4 +49,4 @@ public void Test3() Assert.That(Test3Called is false); } } -} +} \ No newline at end of file