From ea0b3fdc790d1cffc78176524f03965385b9f70a Mon Sep 17 00:00:00 2001 From: castaval Date: Fri, 9 Sep 2022 20:15:15 +0300 Subject: [PATCH 1/6] Finish first task --- CourseApp/Program.cs | 17 +++++-- CourseApp/behaviors/IHymnBehavior.cs | 6 +++ CourseApp/behaviors/Literary.cs | 10 ++++ CourseApp/behaviors/National.cs | 10 ++++ CourseApp/behaviors/Religic.cs | 10 ++++ CourseApp/entities/Country.cs | 69 ++++++++++++++++++++++++++++ CourseApp/entities/Floowy.cs | 13 ++++++ CourseApp/entities/Noobie.cs | 13 ++++++ CourseApp/entities/Smowia.cs | 13 ++++++ 9 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 CourseApp/behaviors/IHymnBehavior.cs create mode 100644 CourseApp/behaviors/Literary.cs create mode 100644 CourseApp/behaviors/National.cs create mode 100644 CourseApp/behaviors/Religic.cs create mode 100644 CourseApp/entities/Country.cs create mode 100644 CourseApp/entities/Floowy.cs create mode 100644 CourseApp/entities/Noobie.cs create mode 100644 CourseApp/entities/Smowia.cs diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index d6d2c87..9b015b8 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,12 +1,23 @@ namespace CourseApp { - using System; - public class Program { public static void Main(string[] args) { - Console.WriteLine("Hello World"); + Country floowy = new Floowy(300, 1000, "Floowy"); + floowy.PerformHymn(); + floowy.SetHymnBehavior(new Religic()); + floowy.PerformHymn(); + + Country noobie = new Noobie(150, 10_000, "Noobie"); + noobie.PerformHymn(); + noobie.SetHymnBehavior(new Literary()); + noobie.PerformHymn(); + + Country smowia = new Smowia(10_000, 100_000, "Smowia"); + smowia.PerformHymn(); + smowia.SetHymnBehavior(new National()); + smowia.PerformHymn(); } } } diff --git a/CourseApp/behaviors/IHymnBehavior.cs b/CourseApp/behaviors/IHymnBehavior.cs new file mode 100644 index 0000000..edbb3e9 --- /dev/null +++ b/CourseApp/behaviors/IHymnBehavior.cs @@ -0,0 +1,6 @@ +namespace CourseApp; + +public interface IHymnBehavior +{ + public void Hymn(); +} \ No newline at end of file diff --git a/CourseApp/behaviors/Literary.cs b/CourseApp/behaviors/Literary.cs new file mode 100644 index 0000000..a0bf221 --- /dev/null +++ b/CourseApp/behaviors/Literary.cs @@ -0,0 +1,10 @@ +namespace CourseApp; +using System; + +public class Literary : IHymnBehavior +{ + public void Hymn() + { + Console.WriteLine("Literary Hymn!"); + } +} \ No newline at end of file diff --git a/CourseApp/behaviors/National.cs b/CourseApp/behaviors/National.cs new file mode 100644 index 0000000..4e0ce36 --- /dev/null +++ b/CourseApp/behaviors/National.cs @@ -0,0 +1,10 @@ +namespace CourseApp; +using System; + +public class National : IHymnBehavior +{ + public void Hymn() + { + Console.WriteLine("National Hymn!"); + } +} \ No newline at end of file diff --git a/CourseApp/behaviors/Religic.cs b/CourseApp/behaviors/Religic.cs new file mode 100644 index 0000000..d9e94c0 --- /dev/null +++ b/CourseApp/behaviors/Religic.cs @@ -0,0 +1,10 @@ +namespace CourseApp; +using System; + +public class Religic : IHymnBehavior +{ + public void Hymn() + { + Console.WriteLine("Religic Hymn!"); + } +} \ No newline at end of file diff --git a/CourseApp/entities/Country.cs b/CourseApp/entities/Country.cs new file mode 100644 index 0000000..a4f2e21 --- /dev/null +++ b/CourseApp/entities/Country.cs @@ -0,0 +1,69 @@ +namespace CourseApp; +using System; + +public abstract class Country +{ + private IHymnBehavior hymnBehavior; + private int gdp; + private int population; + private string countryName; + + public int Gdp + { + get => gdp; + set + { + if (value > 1 && value <= 5000) + { + gdp = value; + } + else + { + Console.WriteLine("GDP not suitable"); + } + } + } + + public int Population + { + get => population; + set + { + if (value > 800) + { + population = value; + } + else + { + Console.WriteLine("Population not suitable"); + } + } + } + + public IHymnBehavior HymnBehavior + { + get => hymnBehavior; + set => hymnBehavior = value; + } + + public string CountryName + { + get => countryName; + set => countryName = value; + } + + public void SetHymnBehavior(IHymnBehavior hb) + { + hymnBehavior = hb; + } + + public void PerformHymn() + { + hymnBehavior.Hymn(); + } + + public void PrintCountryName() + { + Console.WriteLine("Country name is " + CountryName); + } +} diff --git a/CourseApp/entities/Floowy.cs b/CourseApp/entities/Floowy.cs new file mode 100644 index 0000000..14db4fb --- /dev/null +++ b/CourseApp/entities/Floowy.cs @@ -0,0 +1,13 @@ +namespace CourseApp; + +public class Floowy : Country +{ + public Floowy(int gdp, int population, string countryName) + { + Gdp = gdp; + Population = population; + CountryName = countryName; + + HymnBehavior = new National(); + } +} \ No newline at end of file diff --git a/CourseApp/entities/Noobie.cs b/CourseApp/entities/Noobie.cs new file mode 100644 index 0000000..b650f44 --- /dev/null +++ b/CourseApp/entities/Noobie.cs @@ -0,0 +1,13 @@ +namespace CourseApp; + +public class Noobie : Country +{ + public Noobie(int gdp, int population, string countryName) + { + Gdp = gdp; + Population = population; + CountryName = countryName; + + HymnBehavior = new Religic(); + } +} \ No newline at end of file diff --git a/CourseApp/entities/Smowia.cs b/CourseApp/entities/Smowia.cs new file mode 100644 index 0000000..9144649 --- /dev/null +++ b/CourseApp/entities/Smowia.cs @@ -0,0 +1,13 @@ +namespace CourseApp; + +public class Smowia : Country +{ + public Smowia(int gdp, int population, string countryName) + { + Gdp = gdp; + Population = population; + CountryName = countryName; + + HymnBehavior = new Literary(); + } +} \ No newline at end of file From 33f3e87b8043da7a4db9d79f62c21abad3ca5f96 Mon Sep 17 00:00:00 2001 From: castaval Date: Tue, 20 Sep 2022 15:09:34 +0300 Subject: [PATCH 2/6] fix: delete country classes, add new functions --- CourseApp/Program.cs | 26 +++++++++-------- CourseApp/behaviors/IHymnBehavior.cs | 3 +- CourseApp/behaviors/Literary.cs | 2 ++ CourseApp/behaviors/National.cs | 2 ++ CourseApp/behaviors/Religic.cs | 1 + CourseApp/entities/Country.cs | 43 ++++++++++++++++++++++------ CourseApp/entities/Floowy.cs | 13 --------- CourseApp/entities/Noobie.cs | 13 --------- CourseApp/entities/Smowia.cs | 13 --------- 9 files changed, 56 insertions(+), 60 deletions(-) delete mode 100644 CourseApp/entities/Floowy.cs delete mode 100644 CourseApp/entities/Noobie.cs delete mode 100644 CourseApp/entities/Smowia.cs diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 9b015b8..2bb84bf 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -4,20 +4,22 @@ public class Program { public static void Main(string[] args) { - Country floowy = new Floowy(300, 1000, "Floowy"); - floowy.PerformHymn(); - floowy.SetHymnBehavior(new Religic()); - floowy.PerformHymn(); - Country noobie = new Noobie(150, 10_000, "Noobie"); - noobie.PerformHymn(); - noobie.SetHymnBehavior(new Literary()); - noobie.PerformHymn(); + Country Vitilia = new Country(); + Vitilia.PerformHymn(); + Vitilia.HymnBehavior = new National(); + Vitilia.PerformHymn(); + Vitilia.PrintCountryInformation(); + + Country Vovia = new Country("Vovia", 1000, 3000, new Religic()); + Vovia.PerformHymn(); + Vovia.HymnBehavior = new Literary(); + Vovia.PerformHymn(); + Vovia.PrintCountryInformation(); - Country smowia = new Smowia(10_000, 100_000, "Smowia"); - smowia.PerformHymn(); - smowia.SetHymnBehavior(new National()); - smowia.PerformHymn(); + + Vitilia.PopulationCensus(); + Vovia.PopulationCensus(); } } } diff --git a/CourseApp/behaviors/IHymnBehavior.cs b/CourseApp/behaviors/IHymnBehavior.cs index edbb3e9..5d410a8 100644 --- a/CourseApp/behaviors/IHymnBehavior.cs +++ b/CourseApp/behaviors/IHymnBehavior.cs @@ -1,6 +1,7 @@ namespace CourseApp; public interface IHymnBehavior -{ +{ + public string HymnType { get; } public void Hymn(); } \ No newline at end of file diff --git a/CourseApp/behaviors/Literary.cs b/CourseApp/behaviors/Literary.cs index a0bf221..6fce25b 100644 --- a/CourseApp/behaviors/Literary.cs +++ b/CourseApp/behaviors/Literary.cs @@ -3,6 +3,8 @@ namespace CourseApp; public class Literary : IHymnBehavior { + public string HymnType { get => "Literary"; } + public void Hymn() { Console.WriteLine("Literary Hymn!"); diff --git a/CourseApp/behaviors/National.cs b/CourseApp/behaviors/National.cs index 4e0ce36..ca32dcf 100644 --- a/CourseApp/behaviors/National.cs +++ b/CourseApp/behaviors/National.cs @@ -3,6 +3,8 @@ namespace CourseApp; public class National : IHymnBehavior { + public string HymnType { get => "National"; } + public void Hymn() { Console.WriteLine("National Hymn!"); diff --git a/CourseApp/behaviors/Religic.cs b/CourseApp/behaviors/Religic.cs index d9e94c0..2473397 100644 --- a/CourseApp/behaviors/Religic.cs +++ b/CourseApp/behaviors/Religic.cs @@ -3,6 +3,7 @@ namespace CourseApp; public class Religic : IHymnBehavior { + public string HymnType { get => "Religic"; } public void Hymn() { Console.WriteLine("Religic Hymn!"); diff --git a/CourseApp/entities/Country.cs b/CourseApp/entities/Country.cs index a4f2e21..3a79d37 100644 --- a/CourseApp/entities/Country.cs +++ b/CourseApp/entities/Country.cs @@ -1,13 +1,26 @@ namespace CourseApp; using System; -public abstract class Country +public class Country { private IHymnBehavior hymnBehavior; private int gdp; private int population; private string countryName; + public Country() : this("Vitalia") { } + public Country(string countryName) : this(countryName, 3000) { } + public Country(string countryName, int population) : this(countryName, population, 1000) { } + public Country(string countryName, int population, int gdp) : this(countryName, population, gdp, new Literary()) { } + public Country(string countryName, int population, int gdp, IHymnBehavior hymnBehavior) + { + CountryName = countryName; + Population = population; + Gdp = gdp; + + HymnBehavior = hymnBehavior; + } + public int Gdp { get => gdp; @@ -19,7 +32,7 @@ public int Gdp } else { - Console.WriteLine("GDP not suitable"); + throw new Exception("GDP not suitable"); } } } @@ -35,7 +48,7 @@ public int Population } else { - Console.WriteLine("Population not suitable"); + throw new Exception("Population not suitable"); } } } @@ -52,18 +65,32 @@ public string CountryName set => countryName = value; } - public void SetHymnBehavior(IHymnBehavior hb) + + public int PopulationCensus() { - hymnBehavior = hb; + for (int person = 1; person <= Population; person++) + { + if (person % 100 == 0) + { + Console.WriteLine($"People counted - {person}"); + } + } + + Console.WriteLine($"Population census carried out in {CountryName}"); + return Population; } - public void PerformHymn() + + public string PerformHymn() { hymnBehavior.Hymn(); + return hymnBehavior.HymnType; } - public void PrintCountryName() + public string PrintCountryInformation() { - Console.WriteLine("Country name is " + CountryName); + string countryInformation = $"Country name is {CountryName}, Gdp is {Gdp}, Population is {Population}, Hymn is {hymnBehavior.HymnType}"; + Console.WriteLine(countryInformation); + return countryInformation; } } diff --git a/CourseApp/entities/Floowy.cs b/CourseApp/entities/Floowy.cs deleted file mode 100644 index 14db4fb..0000000 --- a/CourseApp/entities/Floowy.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CourseApp; - -public class Floowy : Country -{ - public Floowy(int gdp, int population, string countryName) - { - Gdp = gdp; - Population = population; - CountryName = countryName; - - HymnBehavior = new National(); - } -} \ No newline at end of file diff --git a/CourseApp/entities/Noobie.cs b/CourseApp/entities/Noobie.cs deleted file mode 100644 index b650f44..0000000 --- a/CourseApp/entities/Noobie.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CourseApp; - -public class Noobie : Country -{ - public Noobie(int gdp, int population, string countryName) - { - Gdp = gdp; - Population = population; - CountryName = countryName; - - HymnBehavior = new Religic(); - } -} \ No newline at end of file diff --git a/CourseApp/entities/Smowia.cs b/CourseApp/entities/Smowia.cs deleted file mode 100644 index 9144649..0000000 --- a/CourseApp/entities/Smowia.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CourseApp; - -public class Smowia : Country -{ - public Smowia(int gdp, int population, string countryName) - { - Gdp = gdp; - Population = population; - CountryName = countryName; - - HymnBehavior = new Literary(); - } -} \ No newline at end of file From 302687ad8e07d9f7cbed23bb00407c3deecd9a3b Mon Sep 17 00:00:00 2001 From: castaval Date: Wed, 21 Sep 2022 15:28:10 +0300 Subject: [PATCH 3/6] feat: add xUnit tests --- CourseApp.Tests/CountryTest/CountryTest.cs | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 CourseApp.Tests/CountryTest/CountryTest.cs diff --git a/CourseApp.Tests/CountryTest/CountryTest.cs b/CourseApp.Tests/CountryTest/CountryTest.cs new file mode 100644 index 0000000..c22b559 --- /dev/null +++ b/CourseApp.Tests/CountryTest/CountryTest.cs @@ -0,0 +1,132 @@ +namespace CourseApp.Tests +{ + using Xunit; + + public class CountryTest + { + [Fact] + public void EmptryConstructorTest() + { + Country country = new Country(); + + string countryName = "Vitalia"; + int countryPopulation = 3000; + int countryGdp = 1000; + bool result = false; + + + if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) { + result = true; + } + + Assert.True(result); + } + + [Fact] + public void OneParameterConstructorTest() + { + Country country = new Country("Kenva"); + + string countryName = "Kenva"; + int countryPopulation = 3000; + int countryGdp = 1000; + bool result = false; + + + if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) { + result = true; + } + + Assert.True(result); + } + + [Fact] + public void TwoParameterConstructorTest() + { + Country country = new Country("Kenva", 20000); + + string countryName = "Kenva"; + int countryPopulation = 20000; + int countryGdp = 1000; + bool result = false; + + + if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) { + result = true; + } + + Assert.True(result); + } + + [Fact] + public void ThreeParameterConstructorTest() + { + Country country = new Country("Kenva", 20000, 5000); + + string countryName = "Kenva"; + int countryPopulation = 20000; + int countryGdp = 5000; + bool result = false; + + + if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation) { + result = true; + } + + Assert.True(result); + } + + [Fact] + public void FourParameterConstructorTest() + { + Country country = new Country("Kenva", 20000, 5000, new Religic()); + + string countryName = "Kenva"; + int countryPopulation = 20000; + int countryGdp = 5000; + bool result = false; + + + if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Religic) { + result = true; + } + + Assert.True(result); + } + + [Fact] + public void PopulationCensusTest() + { + Country country = new Country("Balva", 10000, 5000, new National()); + + bool result = country.Population == country.PopulationCensus(); + + Assert.True(result); + } + + [Fact] + public void PerformHymnTest() + { + Country country = new Country("Balva", 10000, 5000, new National()); + + bool result = country.PerformHymn().Equals("National"); + + Assert.True(result); + } + + [Fact] + public void PrintCountryInformationTest() + { + string countryName = "Balva"; + int countryPopulation = 10000; + int countryGpd = 5000; + IHymnBehavior countryHymnBehavior = new National(); + + Country country = new Country(countryName, countryPopulation, countryGpd, countryHymnBehavior); + + bool result = country.PrintCountryInformation().Equals($"Country name is {countryName}, Gdp is {countryGpd}, Population is {countryPopulation}, Hymn is {countryHymnBehavior.HymnType}"); + + Assert.True(result); + } + } +} From 6744afe642c1d1649a5842d8668aaef5ff25ba70 Mon Sep 17 00:00:00 2001 From: castaval Date: Wed, 21 Sep 2022 15:54:09 +0300 Subject: [PATCH 4/6] refactor: use stylecop --- CourseApp.Tests/CountryTest/CountryTest.cs | 28 +++++++++---------- CourseApp/Program.cs | 26 ++++++++---------- CourseApp/behaviors/IHymnBehavior.cs | 3 +- CourseApp/behaviors/Religic.cs | 1 + CourseApp/entities/Country.cs | 32 ++++++++++++++++------ 5 files changed, 52 insertions(+), 38 deletions(-) diff --git a/CourseApp.Tests/CountryTest/CountryTest.cs b/CourseApp.Tests/CountryTest/CountryTest.cs index c22b559..9f080ae 100644 --- a/CourseApp.Tests/CountryTest/CountryTest.cs +++ b/CourseApp.Tests/CountryTest/CountryTest.cs @@ -14,8 +14,8 @@ public void EmptryConstructorTest() int countryGdp = 1000; bool result = false; - - if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) { + if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) + { result = true; } @@ -32,8 +32,8 @@ public void OneParameterConstructorTest() int countryGdp = 1000; bool result = false; - - if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) { + if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) + { result = true; } @@ -50,8 +50,8 @@ public void TwoParameterConstructorTest() int countryGdp = 1000; bool result = false; - - if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) { + if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) + { result = true; } @@ -68,8 +68,8 @@ public void ThreeParameterConstructorTest() int countryGdp = 5000; bool result = false; - - if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation) { + if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation) + { result = true; } @@ -86,8 +86,8 @@ public void FourParameterConstructorTest() int countryGdp = 5000; bool result = false; - - if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Religic) { + if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Religic) + { result = true; } @@ -112,18 +112,18 @@ public void PerformHymnTest() bool result = country.PerformHymn().Equals("National"); Assert.True(result); - } + } [Fact] - public void PrintCountryInformationTest() - { + public void PrintCountryInformationTest() + { string countryName = "Balva"; int countryPopulation = 10000; int countryGpd = 5000; IHymnBehavior countryHymnBehavior = new National(); Country country = new Country(countryName, countryPopulation, countryGpd, countryHymnBehavior); - + bool result = country.PrintCountryInformation().Equals($"Country name is {countryName}, Gdp is {countryGpd}, Population is {countryPopulation}, Hymn is {countryHymnBehavior.HymnType}"); Assert.True(result); diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 2bb84bf..aab4181 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -4,22 +4,20 @@ public class Program { public static void Main(string[] args) { + Country vitilia = new Country(); + vitilia.PerformHymn(); + vitilia.HymnBehavior = new National(); + vitilia.PerformHymn(); + vitilia.PrintCountryInformation(); - Country Vitilia = new Country(); - Vitilia.PerformHymn(); - Vitilia.HymnBehavior = new National(); - Vitilia.PerformHymn(); - Vitilia.PrintCountryInformation(); - - Country Vovia = new Country("Vovia", 1000, 3000, new Religic()); - Vovia.PerformHymn(); - Vovia.HymnBehavior = new Literary(); - Vovia.PerformHymn(); - Vovia.PrintCountryInformation(); + Country vovia = new Country("Vovia", 1000, 3000, new Religic()); + vovia.PerformHymn(); + vovia.HymnBehavior = new Literary(); + vovia.PerformHymn(); + vovia.PrintCountryInformation(); - - Vitilia.PopulationCensus(); - Vovia.PopulationCensus(); + vitilia.PopulationCensus(); + vovia.PopulationCensus(); } } } diff --git a/CourseApp/behaviors/IHymnBehavior.cs b/CourseApp/behaviors/IHymnBehavior.cs index 5d410a8..16f6e3b 100644 --- a/CourseApp/behaviors/IHymnBehavior.cs +++ b/CourseApp/behaviors/IHymnBehavior.cs @@ -1,7 +1,8 @@ namespace CourseApp; public interface IHymnBehavior -{ +{ public string HymnType { get; } + public void Hymn(); } \ No newline at end of file diff --git a/CourseApp/behaviors/Religic.cs b/CourseApp/behaviors/Religic.cs index 2473397..f6ef01e 100644 --- a/CourseApp/behaviors/Religic.cs +++ b/CourseApp/behaviors/Religic.cs @@ -4,6 +4,7 @@ namespace CourseApp; public class Religic : IHymnBehavior { public string HymnType { get => "Religic"; } + public void Hymn() { Console.WriteLine("Religic Hymn!"); diff --git a/CourseApp/entities/Country.cs b/CourseApp/entities/Country.cs index 3a79d37..5ad1f07 100644 --- a/CourseApp/entities/Country.cs +++ b/CourseApp/entities/Country.cs @@ -8,11 +8,27 @@ public class Country private int population; private string countryName; - public Country() : this("Vitalia") { } - public Country(string countryName) : this(countryName, 3000) { } - public Country(string countryName, int population) : this(countryName, population, 1000) { } - public Country(string countryName, int population, int gdp) : this(countryName, population, gdp, new Literary()) { } - public Country(string countryName, int population, int gdp, IHymnBehavior hymnBehavior) + public Country() + : this("Vitalia") + { + } + + public Country(string countryName) + : this(countryName, 3000) + { + } + + public Country(string countryName, int population) + : this(countryName, population, 1000) + { + } + + public Country(string countryName, int population, int gdp) + : this(countryName, population, gdp, new Literary()) + { + } + + public Country(string countryName, int population, int gdp, IHymnBehavior hymnBehavior) { CountryName = countryName; Population = population; @@ -65,12 +81,11 @@ public string CountryName set => countryName = value; } - public int PopulationCensus() { - for (int person = 1; person <= Population; person++) + for (int person = 1; person <= Population; person++) { - if (person % 100 == 0) + if (person % 100 == 0) { Console.WriteLine($"People counted - {person}"); } @@ -80,7 +95,6 @@ public int PopulationCensus() return Population; } - public string PerformHymn() { hymnBehavior.Hymn(); From 35fcb3634b7a6084b91533449b76ef540771508d Mon Sep 17 00:00:00 2001 From: castaval Date: Sat, 1 Oct 2022 15:04:46 +0300 Subject: [PATCH 5/6] typescript --- .dockerignore | 4 - .eslintrc.js | 22 +++ .github/workflows/dotnetcore.yml | 27 --- .gitignore | 208 +-------------------- .vscode/settings.json | 11 -- CourseApp.Tests/CountryTest/CountryTest.cs | 132 ------------- CourseApp.Tests/CourseApp.Tests.csproj | 32 ---- CourseApp.Tests/DemoTest.cs | 13 -- CourseApp.sln | 31 --- CourseApp/.vscode/launch.json | 25 --- CourseApp/.vscode/tasks.json | 42 ----- CourseApp/CourseApp.csproj | 22 --- CourseApp/Program.cs | 23 --- CourseApp/behaviors/IHymnBehavior.cs | 8 - CourseApp/behaviors/Literary.cs | 12 -- CourseApp/behaviors/National.cs | 12 -- CourseApp/behaviors/Religic.cs | 12 -- CourseApp/entities/Country.cs | 110 ----------- Dockerfile | 17 -- README.md | 36 ---- _stylecop/stylecop.json | 12 -- _stylecop/stylecop.ruleset | 13 -- courseworkspace.code-workspace | 22 --- docker-compose.yml | 15 -- package.json | 32 ++++ src/classes/cake.ts | 25 +++ src/classes/steak.ts | 25 +++ src/dish.ts | 92 +++++++++ src/index.ts | 19 ++ tests/access.spec.ts | 84 +++++++++ tests/cake.spec.ts | 27 +++ tests/constructors.spec.ts | 49 +++++ tests/dish.spec.ts | 27 +++ tests/steak.spec.ts | 27 +++ tsconfig.json | 6 + 35 files changed, 437 insertions(+), 837 deletions(-) delete mode 100644 .dockerignore create mode 100644 .eslintrc.js delete mode 100644 .github/workflows/dotnetcore.yml delete mode 100644 .vscode/settings.json delete mode 100644 CourseApp.Tests/CountryTest/CountryTest.cs delete mode 100644 CourseApp.Tests/CourseApp.Tests.csproj delete mode 100644 CourseApp.Tests/DemoTest.cs delete mode 100644 CourseApp.sln delete mode 100644 CourseApp/.vscode/launch.json delete mode 100644 CourseApp/.vscode/tasks.json delete mode 100644 CourseApp/CourseApp.csproj delete mode 100644 CourseApp/Program.cs delete mode 100644 CourseApp/behaviors/IHymnBehavior.cs delete mode 100644 CourseApp/behaviors/Literary.cs delete mode 100644 CourseApp/behaviors/National.cs delete mode 100644 CourseApp/behaviors/Religic.cs delete mode 100644 CourseApp/entities/Country.cs delete mode 100644 Dockerfile delete mode 100644 README.md delete mode 100644 _stylecop/stylecop.json delete mode 100644 _stylecop/stylecop.ruleset delete mode 100644 courseworkspace.code-workspace delete mode 100644 docker-compose.yml create mode 100644 package.json create mode 100644 src/classes/cake.ts create mode 100644 src/classes/steak.ts create mode 100644 src/dish.ts create mode 100644 src/index.ts create mode 100644 tests/access.spec.ts create mode 100644 tests/cake.spec.ts create mode 100644 tests/constructors.spec.ts create mode 100644 tests/dish.spec.ts create mode 100644 tests/steak.spec.ts create mode 100644 tsconfig.json diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 88617c8..0000000 --- a/.dockerignore +++ /dev/null @@ -1,4 +0,0 @@ -**/bin/ -**/obj/ -CourseApp.Tests/ -CourseApp/CourseApp.sln \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..2cfa619 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,22 @@ +module.exports = { + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "overrides": [ + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + } +} diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml deleted file mode 100644 index dffe441..0000000 --- a/.github/workflows/dotnetcore.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: .NET Core - -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - matrix: - dotnet: [ '2.1', '5.0.x', '6.0.x' ] - - steps: - - uses: actions/checkout@v2 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: ${{ matrix.dotnet-version }} - include-prerelease: true - - name: Build with dotnet - run: | - cd CourseApp - dotnet build --configuration Release - - name: Run tests - run: | - cd CourseApp.Tests - dotnet test diff --git a/.gitignore b/.gitignore index 12f59b6..2e9954e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,206 +1,2 @@ -# Download this file using PowerShell v3 under Windows with the following comand: -# Invoke-WebRequest https://gist.githubusercontent.com/kmorcinek/2710267/raw/ -OutFile .gitignore -# or wget: -# wget --no-check-certificate http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore - -# User-specific files -*.suo -*.user -*.sln.docstates - -# Build results - -[Dd]ebug/ -[Rr]elease/ -x64/ -build/ -[Bb]in/ -[Oo]bj/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -*_i.c -*_p.c -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.log -*.scc - -# OS generated files # -.DS_Store* -Icon? - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -*.ncrunch* -.*crunch*.local.xml - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.Publish.xml - -# Windows Azure Build Output -csx -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Others -*.Cache -ClientBin/ -# [Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.[Pp]ublish.xml -*.pfx -*.publishsettings -modulesbin/ -tempbin/ - -# EPiServer Site file (VPP) -AppData/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# vim -*.txt~ -*.swp -*.swo - -# svn -.svn - -# Remainings from resolvings conflicts in Source Control -*.orig - -# SQL Server files -**/App_Data/*.mdf -**/App_Data/*.ldf -**/App_Data/*.sdf - - -#LightSwitch generated files -GeneratedArtifacts/ -_Pvt_Extensions/ -ModelManifest.xml - -# ========================= -# Windows detritus -# ========================= - -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Mac desktop service store files -.DS_Store - -# SASS Compiler cache -.sass-cache - -# Visual Studio 2014 CTP -**/*.sln.ide - -# Visual Studio temp something -.vs/ - -# VS 2015+ -*.vc.vc.opendb -*.vc.db - -# Rider -.idea/ - -**/node_modules/* - -# Added by Jskonst -# .vscode/ -Properties/ - -##### -# End of core ignore list, below put you custom 'per project' settings (patterns or path) -##### \ No newline at end of file +node_modules +dist/**/* \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e2cc5c5..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "files.exclude": { - "**/.git": true, - "**/.svn": true, - "**/CVS": true, - "**/.DS_Store": true, - "CourseApp": true, - "CourseApp.Tests":true, - "WebApplication":true - } -} \ No newline at end of file diff --git a/CourseApp.Tests/CountryTest/CountryTest.cs b/CourseApp.Tests/CountryTest/CountryTest.cs deleted file mode 100644 index 9f080ae..0000000 --- a/CourseApp.Tests/CountryTest/CountryTest.cs +++ /dev/null @@ -1,132 +0,0 @@ -namespace CourseApp.Tests -{ - using Xunit; - - public class CountryTest - { - [Fact] - public void EmptryConstructorTest() - { - Country country = new Country(); - - string countryName = "Vitalia"; - int countryPopulation = 3000; - int countryGdp = 1000; - bool result = false; - - if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) - { - result = true; - } - - Assert.True(result); - } - - [Fact] - public void OneParameterConstructorTest() - { - Country country = new Country("Kenva"); - - string countryName = "Kenva"; - int countryPopulation = 3000; - int countryGdp = 1000; - bool result = false; - - if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) - { - result = true; - } - - Assert.True(result); - } - - [Fact] - public void TwoParameterConstructorTest() - { - Country country = new Country("Kenva", 20000); - - string countryName = "Kenva"; - int countryPopulation = 20000; - int countryGdp = 1000; - bool result = false; - - if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Literary) - { - result = true; - } - - Assert.True(result); - } - - [Fact] - public void ThreeParameterConstructorTest() - { - Country country = new Country("Kenva", 20000, 5000); - - string countryName = "Kenva"; - int countryPopulation = 20000; - int countryGdp = 5000; - bool result = false; - - if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation) - { - result = true; - } - - Assert.True(result); - } - - [Fact] - public void FourParameterConstructorTest() - { - Country country = new Country("Kenva", 20000, 5000, new Religic()); - - string countryName = "Kenva"; - int countryPopulation = 20000; - int countryGdp = 5000; - bool result = false; - - if (country.CountryName == countryName && country.Gdp == countryGdp && country.Population == countryPopulation && country.HymnBehavior is Religic) - { - result = true; - } - - Assert.True(result); - } - - [Fact] - public void PopulationCensusTest() - { - Country country = new Country("Balva", 10000, 5000, new National()); - - bool result = country.Population == country.PopulationCensus(); - - Assert.True(result); - } - - [Fact] - public void PerformHymnTest() - { - Country country = new Country("Balva", 10000, 5000, new National()); - - bool result = country.PerformHymn().Equals("National"); - - Assert.True(result); - } - - [Fact] - public void PrintCountryInformationTest() - { - string countryName = "Balva"; - int countryPopulation = 10000; - int countryGpd = 5000; - IHymnBehavior countryHymnBehavior = new National(); - - Country country = new Country(countryName, countryPopulation, countryGpd, countryHymnBehavior); - - bool result = country.PrintCountryInformation().Equals($"Country name is {countryName}, Gdp is {countryGpd}, Population is {countryPopulation}, Hymn is {countryHymnBehavior.HymnType}"); - - Assert.True(result); - } - } -} diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj deleted file mode 100644 index e43252f..0000000 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ /dev/null @@ -1,32 +0,0 @@ - - - - net6.0 - True - false - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - ../_stylecop/stylecop.ruleset - true - - - - - - - diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs deleted file mode 100644 index cf7cbb1..0000000 --- a/CourseApp.Tests/DemoTest.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CourseApp.Tests -{ - using Xunit; - - public class DemoTest - { - [Fact] - public void Test1() - { - Assert.True(true); - } - } -} diff --git a/CourseApp.sln b/CourseApp.sln deleted file mode 100644 index 12714a0..0000000 --- a/CourseApp.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.32014.148 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp", "CourseApp\CourseApp.csproj", "{F069B4EF-B995-4AF8-8E63-770D1E0A0884}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp.Tests", "CourseApp.Tests\CourseApp.Tests.csproj", "{3F66714D-FFFA-4512-A62B-4D038AB148AD}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F069B4EF-B995-4AF8-8E63-770D1E0A0884}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F069B4EF-B995-4AF8-8E63-770D1E0A0884}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F069B4EF-B995-4AF8-8E63-770D1E0A0884}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F069B4EF-B995-4AF8-8E63-770D1E0A0884}.Release|Any CPU.Build.0 = Release|Any CPU - {3F66714D-FFFA-4512-A62B-4D038AB148AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3F66714D-FFFA-4512-A62B-4D038AB148AD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3F66714D-FFFA-4512-A62B-4D038AB148AD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3F66714D-FFFA-4512-A62B-4D038AB148AD}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {064E603C-674E-4DB9-A061-4B08C0ACD98C} - EndGlobalSection -EndGlobal diff --git a/CourseApp/.vscode/launch.json b/CourseApp/.vscode/launch.json deleted file mode 100644 index 211a200..0000000 --- a/CourseApp/.vscode/launch.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - "program": "${workspaceFolder}/bin/Debug/net6.0/CourseApp.dll", - "args": [], - "cwd": "${workspaceFolder}", - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file diff --git a/CourseApp/.vscode/tasks.json b/CourseApp/.vscode/tasks.json deleted file mode 100644 index f8c71cd..0000000 --- a/CourseApp/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/CourseApp.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/CourseApp.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/CourseApp.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj deleted file mode 100644 index eb22147..0000000 --- a/CourseApp/CourseApp.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - - Exe - net6.0 - True - - - - - - - - ../_stylecop/stylecop.ruleset - true - - - - - - - diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs deleted file mode 100644 index aab4181..0000000 --- a/CourseApp/Program.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace CourseApp -{ - public class Program - { - public static void Main(string[] args) - { - Country vitilia = new Country(); - vitilia.PerformHymn(); - vitilia.HymnBehavior = new National(); - vitilia.PerformHymn(); - vitilia.PrintCountryInformation(); - - Country vovia = new Country("Vovia", 1000, 3000, new Religic()); - vovia.PerformHymn(); - vovia.HymnBehavior = new Literary(); - vovia.PerformHymn(); - vovia.PrintCountryInformation(); - - vitilia.PopulationCensus(); - vovia.PopulationCensus(); - } - } -} diff --git a/CourseApp/behaviors/IHymnBehavior.cs b/CourseApp/behaviors/IHymnBehavior.cs deleted file mode 100644 index 16f6e3b..0000000 --- a/CourseApp/behaviors/IHymnBehavior.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace CourseApp; - -public interface IHymnBehavior -{ - public string HymnType { get; } - - public void Hymn(); -} \ No newline at end of file diff --git a/CourseApp/behaviors/Literary.cs b/CourseApp/behaviors/Literary.cs deleted file mode 100644 index 6fce25b..0000000 --- a/CourseApp/behaviors/Literary.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace CourseApp; -using System; - -public class Literary : IHymnBehavior -{ - public string HymnType { get => "Literary"; } - - public void Hymn() - { - Console.WriteLine("Literary Hymn!"); - } -} \ No newline at end of file diff --git a/CourseApp/behaviors/National.cs b/CourseApp/behaviors/National.cs deleted file mode 100644 index ca32dcf..0000000 --- a/CourseApp/behaviors/National.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace CourseApp; -using System; - -public class National : IHymnBehavior -{ - public string HymnType { get => "National"; } - - public void Hymn() - { - Console.WriteLine("National Hymn!"); - } -} \ No newline at end of file diff --git a/CourseApp/behaviors/Religic.cs b/CourseApp/behaviors/Religic.cs deleted file mode 100644 index f6ef01e..0000000 --- a/CourseApp/behaviors/Religic.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace CourseApp; -using System; - -public class Religic : IHymnBehavior -{ - public string HymnType { get => "Religic"; } - - public void Hymn() - { - Console.WriteLine("Religic Hymn!"); - } -} \ No newline at end of file diff --git a/CourseApp/entities/Country.cs b/CourseApp/entities/Country.cs deleted file mode 100644 index 5ad1f07..0000000 --- a/CourseApp/entities/Country.cs +++ /dev/null @@ -1,110 +0,0 @@ -namespace CourseApp; -using System; - -public class Country -{ - private IHymnBehavior hymnBehavior; - private int gdp; - private int population; - private string countryName; - - public Country() - : this("Vitalia") - { - } - - public Country(string countryName) - : this(countryName, 3000) - { - } - - public Country(string countryName, int population) - : this(countryName, population, 1000) - { - } - - public Country(string countryName, int population, int gdp) - : this(countryName, population, gdp, new Literary()) - { - } - - public Country(string countryName, int population, int gdp, IHymnBehavior hymnBehavior) - { - CountryName = countryName; - Population = population; - Gdp = gdp; - - HymnBehavior = hymnBehavior; - } - - public int Gdp - { - get => gdp; - set - { - if (value > 1 && value <= 5000) - { - gdp = value; - } - else - { - throw new Exception("GDP not suitable"); - } - } - } - - public int Population - { - get => population; - set - { - if (value > 800) - { - population = value; - } - else - { - throw new Exception("Population not suitable"); - } - } - } - - public IHymnBehavior HymnBehavior - { - get => hymnBehavior; - set => hymnBehavior = value; - } - - public string CountryName - { - get => countryName; - set => countryName = value; - } - - public int PopulationCensus() - { - for (int person = 1; person <= Population; person++) - { - if (person % 100 == 0) - { - Console.WriteLine($"People counted - {person}"); - } - } - - Console.WriteLine($"Population census carried out in {CountryName}"); - return Population; - } - - public string PerformHymn() - { - hymnBehavior.Hymn(); - return hymnBehavior.HymnType; - } - - public string PrintCountryInformation() - { - string countryInformation = $"Country name is {CountryName}, Gdp is {Gdp}, Population is {Population}, Hymn is {hymnBehavior.HymnType}"; - Console.WriteLine(countryInformation); - return countryInformation; - } -} diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index b2a2650..0000000 --- a/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:5.0 AS build-env -WORKDIR /app - -# Copy csproj and restore as distinct layers -COPY ./CourseApp/*.csproj ./ -RUN dotnet restore - -# Copy everything else and build -COPY ./CourseApp/* ./ -COPY ./_stylecop/ /_stylecop/ -RUN dotnet publish -c Release -o out - -# Build runtime image -FROM mcr.microsoft.com/dotnet/core/aspnet:5.0 -WORKDIR /app -COPY --from=build-env /app/out . -ENTRYPOINT ["dotnet", "CourseApp.dll"] \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index a79bfa3..0000000 --- a/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# Tprogramming 2021 - -Master branch :) - -`docker volume create --name=mssqldata` - -### Adding migrations - -To create initial migration in the console please add the following commands. First of all you need to install migration [tools](https://docs.microsoft.com/ru-ru/ef/core/cli/dotnet). - -``` -dotnet tool install --global dotnet-ef -dotnet tool update --global dotnet-ef -``` -Restart you terminal/VScode - and check the following command in terminal. -``` -dotnet ef -``` - -**Note!** If you faced with issues ant the command was not executed - check you environmental variables. For windows in `Path` variable you should be able to see - -``` -%USERPROFILE%\.dotnet\tools -``` - -Execute next command strictly in the `WebApplication` folder - -``` -dotnet add package Microsoft.EntityFrameworkCore.Design -``` - -Finally you may work with migration (from `WebApplication` folder). The following command will create initial migration. - -``` -dotnet ef migrations add InitialMigration -``` \ No newline at end of file diff --git a/_stylecop/stylecop.json b/_stylecop/stylecop.json deleted file mode 100644 index 4a96e8f..0000000 --- a/_stylecop/stylecop.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "documentExposedElements": false, - "documentInterfaces": false, - "companyName": "Test Company", - "copyrightText": "This source code is Copyright © {companyName} and MAY NOT be copied, reproduced,\npublished, distributed or transmitted to or stored in any manner without prior\nwritten consent from {companyName} (www.yourcompany.com).", - "xmlHeader":false - } - } -} \ No newline at end of file diff --git a/_stylecop/stylecop.ruleset b/_stylecop/stylecop.ruleset deleted file mode 100644 index f109ca9..0000000 --- a/_stylecop/stylecop.ruleset +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/courseworkspace.code-workspace b/courseworkspace.code-workspace deleted file mode 100644 index 38f6cc3..0000000 --- a/courseworkspace.code-workspace +++ /dev/null @@ -1,22 +0,0 @@ -{ - "folders": [ - { - "path": "CourseApp" - }, - { - "path": "CourseApp.Tests" - }, - { - "name": "Configs (Root)", - "path": "." - }, - ], - "settings": {}, - "extensions": { - "recommendations": [ - "ms-azuretools.vscode-docker", - "ms-dotnettools.csharp", - "ms-mssql.mssql" - ] - } -} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 30b0b11..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: '3' -services: - mssql: - image: mcr.microsoft.com/mssql/server:2019-latest - ports: - - 4433:1433 - environment: - - ACCEPT_EULA=Y - - SA_PASSWORD=Secret1234 - volumes: - - mssqldata:/var/opt/mssql - - ./database/backup:/var/opt/mssql/backup -volumes: - mssqldata: - external: true \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..eaf7069 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "dish", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "ts-node --script-mode src/index.ts", + "test": "jest", + "lint": "eslint src --ext .js --ext .jsx --ext .ts --ext .tsx", + "lint:fix": "npm run lint -- --fix" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "@types/jest": "^27.0.3", + "@types/node": "^16.11.0", + "@typescript-eslint/eslint-plugin": "^5.38.1", + "@typescript-eslint/parser": "^5.38.1", + "eslint": "^7.28.0", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-import": "^2.23.4", + "eslint-plugin-prettier": "^3.4.0", + "jest": "^27.2.5", + "prettier": "^2.4.1", + "ts-jest": "^27.1.2", + "ts-node": "^10.3.0", + "typescript": "^4.4.4" + }, + "jest": { + "preset": "ts-jest" + } +} diff --git a/src/classes/cake.ts b/src/classes/cake.ts new file mode 100644 index 0000000..92c553b --- /dev/null +++ b/src/classes/cake.ts @@ -0,0 +1,25 @@ +import { Dish } from "../dish"; + +export class Cake extends Dish { + constructor(nameOfDish: string, price: number, ingrediens?: number, description?: string) { + super(nameOfDish, price, ingrediens, description); + } + + getMethodCooking(): string { + return `Cake is cooking!`; + } + + getCakeInfo(): string { + return `Cake (name: ${this.nameOfDish} price: ${this.price} ingrediens: ${this.ingrediens} description: ${this.description})`; + } + + methodCooking(): void { + const cook = this.getMethodCooking(); + console.log(cook); + } + + toString(): void { + const info = this.getCakeInfo(); + console.log(info); + } +} \ No newline at end of file diff --git a/src/classes/steak.ts b/src/classes/steak.ts new file mode 100644 index 0000000..2dc8627 --- /dev/null +++ b/src/classes/steak.ts @@ -0,0 +1,25 @@ +import { Dish } from "../dish"; + +export class Steak extends Dish { + constructor(nameOfDish: string, price: number, ingrediens?: number, description?: string) { + super(nameOfDish, price, ingrediens, description); + } + + getMethodCooking(): string { + return `Steak is cooking!`; + } + + getSteakInfo(): string { + return `Steak (name: ${this.nameOfDish} price: ${this.price} ingrediens: ${this.ingrediens} description: ${this.description})`; + } + + methodCooking(): void { + const cook = this.getMethodCooking(); + console.log(cook); + } + + toString(): void { + const info = this.getSteakInfo(); + console.log(info); + } +} \ No newline at end of file diff --git a/src/dish.ts b/src/dish.ts new file mode 100644 index 0000000..e49418e --- /dev/null +++ b/src/dish.ts @@ -0,0 +1,92 @@ +export abstract class Dish { + protected price: number; + protected ingrediens: number; + protected nameOfDish: string; + protected description: string; + + constructor(nameOfDish: string, price: number, ingrediens?: number, + description?: string) { + this.Name = nameOfDish; + this.Price = price; + + if (ingrediens) { + this.Ingrediens = ingrediens + } else { + this.Ingrediens = 1; + } + + if (description) { + this.Description = description; + } else { + this.Description = "UNDEFINED!!!"; + } + } + + get Name(): string { + return this.nameOfDish; + } + + set Name(name: string) { + if (name.length <= 2) { + throw new Error(); + } + + this.nameOfDish = name; + } + + get Price(): number { + return this.price; + } + + set Price(price: number) { + if (price == 0) { + throw new Error(); + } + + this.price = price; + } + + get Ingrediens(): number { + return this.ingrediens; + } + + set Ingrediens(ingrediens: number) { + if (ingrediens == 0) { + throw new Error(); + } + + this.ingrediens = ingrediens; + } + + get Description(): string { + return this.description; + } + + set Description(description: string) { + if (description.length < 10) { + throw new Error(); + } + + this.description = description; + } + + abstract methodCooking(): void; + + getInformation(): string { + return `Dish\nName: ${this.nameOfDish}\nPrice: ${this.price}\nDescription: ${this.description}\nIngrediens: ${this.ingrediens}`; + } + + displayInformation(): void { + const information = this.getInformation(); + console.log(information); + } + + getOrderDish(): string { + return `Your Dish is ${this.nameOfDish}`; + } + + orderDish(): void { + const dish = this.getOrderDish(); + console.log(dish); + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..66f4090 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,19 @@ +import { Cake } from "./classes/cake"; +import { Steak } from "./classes/steak"; +import { Dish } from "./dish"; + +const cake = new Cake("cake", 100); +cake.displayInformation() +cake.orderDish(); +cake.Price = 200; +cake.displayInformation(); +cake.toString(); + +const steak = new Steak("steak", 600, 1, "The best steak ever"); +steak.displayInformation(); +steak.Name = "Steak!!!"; +steak.orderDish(); +steak.toString(); + +const array: Dish[] = [cake, steak]; +array.forEach((value) => value.methodCooking()); diff --git a/tests/access.spec.ts b/tests/access.spec.ts new file mode 100644 index 0000000..ae28547 --- /dev/null +++ b/tests/access.spec.ts @@ -0,0 +1,84 @@ +import { Cake } from "../src/classes/cake"; +import { Steak } from "../src/classes/steak"; + +describe('Access Method Get', () => { + it('name', () => { + const name = "Cakee"; + const price = 200; + const cake = new Cake(name, price); + + expect(cake.Name).toEqual(name); + }); + + it('price', () => { + const name = "Steakk"; + const price = 499; + const steak = new Steak(name, price); + + expect(steak.Price).toEqual(price); + }); + + it('ingrediens', () => { + const name = "Steakk"; + const price = 499; + const ingrediens = 3; + const steak = new Steak(name, price, ingrediens); + + expect(steak.Ingrediens).toEqual(ingrediens); + }); + + it('description', () => { + const name = "Steakk"; + const price = 499; + const ingrediens = 3; + const description = "This is a test description"; + const steak = new Steak(name, price, ingrediens, description); + + expect(steak.Description).toEqual(description); + }); +}); + +describe('Access Method Set', () => { + it('name', () => { + let name = "Cakee"; + const price = 200; + const cake = new Cake(name, price); + name = "ULTRA CAKE" + cake.Name = name; + + expect(cake.Name).toEqual(name); + }); + + it('price', () => { + const name = "Steakk"; + let price = 499; + const steak = new Steak(name, price); + price = 200; + steak.Price = price; + + expect(steak.Price).toEqual(price); + }); + + it('ingrediens', () => { + const name = "Steakk"; + const price = 499; + let ingrediens = 3; + const steak = new Steak(name, price, ingrediens); + ingrediens = 4; + steak.Ingrediens = ingrediens; + + expect(steak.Ingrediens).toEqual(ingrediens); + }); + + it('description', () => { + const name = "Steakk"; + const price = 499; + const ingrediens = 3; + let description = "This is a test description"; + const steak = new Steak(name, price, ingrediens, description); + description = "This is a teeest description"; + steak.Description = description; + + expect(steak.Description).toEqual(description); + }); +}); \ No newline at end of file diff --git a/tests/cake.spec.ts b/tests/cake.spec.ts new file mode 100644 index 0000000..ada6adc --- /dev/null +++ b/tests/cake.spec.ts @@ -0,0 +1,27 @@ +import { Cake } from "../src/classes/cake"; + +describe('Cake', () => { + it('get cake method cooking', () => { + const name = "Cakee"; + const price = 300; + const ingrediens = 3; + const description = "This is a usually cake"; + const cake = new Cake(name, price, ingrediens, description); + + const information = `Cake is cooking!`; + + expect(cake.getMethodCooking()).toEqual(information); + }); + + it('get cake info', () => { + const name = "Cakeee"; + const price = 499; + const ingrediens = 1; + const description = "This is a usually cake"; + const cake = new Cake(name, price, ingrediens, description); + + const info = `Cake (name: ${name} price: ${price} ingrediens: ${ingrediens} description: ${description})`; + + expect(cake.getCakeInfo()).toEqual(info); + }); +}); \ No newline at end of file diff --git a/tests/constructors.spec.ts b/tests/constructors.spec.ts new file mode 100644 index 0000000..d276614 --- /dev/null +++ b/tests/constructors.spec.ts @@ -0,0 +1,49 @@ +import { Cake } from "../src/classes/cake"; +import { Steak } from "../src/classes/steak"; + +describe('Constructors', () => { + it('all parameters', () => { + const name = "Cakee"; + const price = 300; + const ingrediens = 3; + const description = "This is a usually cake"; + let condition = false; + const cake = new Cake(name, price, ingrediens, description); + + if (name == cake.Name && price == cake.Price && ingrediens == cake.Ingrediens && description && cake.Description) { + condition = true; + } + + expect(condition).toBeTruthy(); + }); + + it('three parameters', () => { + const name = "Steakk"; + const price = 499; + const ingrediens = 1; + const description = "UNDEFINED!!!"; + let condition = false; + const steak = new Steak(name, price, ingrediens); + + if (name == steak.Name && price == steak.Price && ingrediens == steak.Ingrediens && description && steak.Description) { + condition = true; + } + + expect(condition).toBeTruthy(); + }); + + it('two parameters', () => { + const name = "Steakk"; + const price = 499; + const ingrediens = 1; + const description = "UNDEFINED!!!"; + let condition = false; + const steak = new Steak(name, price); + + if (name == steak.Name && price == steak.Price && ingrediens == steak.Ingrediens && description && steak.Description) { + condition = true; + } + + expect(condition).toBeTruthy(); + }); +}); \ No newline at end of file diff --git a/tests/dish.spec.ts b/tests/dish.spec.ts new file mode 100644 index 0000000..0e2663b --- /dev/null +++ b/tests/dish.spec.ts @@ -0,0 +1,27 @@ +import { Cake } from "../src/classes/cake"; +import { Steak } from "../src/classes/steak"; + +describe('Dish', () => { + it('get information', () => { + const name = "Cakee"; + const price = 300; + const ingrediens = 3; + const description = "This is a usually cake"; + const cake = new Cake(name, price, ingrediens, description); + + const information = `Dish\nName: ${name}\nPrice: ${price}\nDescription: ${description}\nIngrediens: ${ingrediens}`; + + expect(cake.getInformation()).toEqual(information); + }); + + it('get order', () => { + const name = "Steakk"; + const price = 499; + const ingrediens = 1; + const steak = new Steak(name, price, ingrediens); + + const order = `Your Dish is ${name}`; + + expect(steak.getOrderDish()).toEqual(order); + }); +}); \ No newline at end of file diff --git a/tests/steak.spec.ts b/tests/steak.spec.ts new file mode 100644 index 0000000..7bb81f2 --- /dev/null +++ b/tests/steak.spec.ts @@ -0,0 +1,27 @@ +import { Steak } from "../src/classes/steak"; + +describe('Steak', () => { + it('get steak method cooking', () => { + const name = "Steak"; + const price = 300; + const ingrediens = 3; + const description = "This is a usually steak"; + const steak = new Steak(name, price, ingrediens, description); + + const information = `Steak is cooking!`; + + expect(steak.getMethodCooking()).toEqual(information); + }); + + it('get steak info', () => { + const name = "Steak"; + const price = 499; + const ingrediens = 1; + const description = "This is a usually steak"; + const steak = new Steak(name, price, ingrediens, description); + + const info = `Steak (name: ${name} price: ${price} ingrediens: ${ingrediens} description: ${description})`; + + expect(steak.getSteakInfo()).toEqual(info); + }); +}); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8062b24 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "types": ["jest", "node"], + "target": "ES5", + } +} \ No newline at end of file From e4b8ab85a0daab6ca3fbafd9b0dc3072d982891d Mon Sep 17 00:00:00 2001 From: castaval Date: Sat, 1 Oct 2022 15:07:24 +0300 Subject: [PATCH 6/6] feat: add package-lock.json --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2e9954e..755a027 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules +package-lock.json dist/**/* \ No newline at end of file