diff --git a/OopUnitTesting/OopUnitTesting.csproj b/OopUnitTesting/OopUnitTesting.csproj new file mode 100644 index 0000000..0aa3ad5 --- /dev/null +++ b/OopUnitTesting/OopUnitTesting.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp2.0 + + false + + + + + + + + + + + + + diff --git a/OopUnitTesting/SalaryTests.cs b/OopUnitTesting/SalaryTests.cs new file mode 100644 index 0000000..aafb8da --- /dev/null +++ b/OopUnitTesting/SalaryTests.cs @@ -0,0 +1,81 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using OopUnitTests; + +namespace OopUnitTesting +{ + [TestClass] + public class SalaryTesting + { + private Manager testEmployee; + private int experience = 1; + private int salary = 1; + Department department = new Department(); + + public void Setup() + { + testEmployee = new Manager("", "", experience, salary, null); + + } + + [TestMethod] + public void CalculateEmpSallary_TestExperience_7year_startSalary1000_result1700() + { + experience = 7; + salary = 1000; + int expected = 1700; + + this.Setup(); + + Assert.AreEqual(department.GetSallary(testEmployee), expected); + } + + [TestMethod] + public void CalculateEmpSallary_TestExperience_4year_startSalary1000_result1200() + { + experience = 4; + salary = 1000; + int expected = 1200; + + this.Setup(); + + Assert.AreEqual(department.GetSallary(testEmployee), expected); + } + + [TestMethod] + public void CalculateEmpSallary_ManagerTest_7year_startSalary1000_11members_result2000() + { + experience = 7; + salary = 1000; + int expected = 2000; + + this.Setup(); + + for (int i = 0; i < 11; i++) + { + testEmployee.AddManagerMember(testEmployee); + } + decimal actual = department.GetSallary(testEmployee); + + Assert.AreEqual(actual, expected); + } + + [TestMethod] + public void CalculateEmpSallary_ManagerTest_7year_startSalary1000_2members_result1700() + { + experience = 7; + salary = 1000; + int expected = 1700; + + this.Setup(); + + for (int i = 0; i < 2; i++) + { + testEmployee.AddManagerMember(testEmployee); + } + decimal actual = department.GetSallary(testEmployee); + + Assert.AreEqual(actual, expected); + } + } +} diff --git a/OopUnitTests.sln b/OopUnitTests.sln new file mode 100644 index 0000000..188767b --- /dev/null +++ b/OopUnitTests.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2047 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OopHomeTask", "OopUnitTests\OopHomeTask.csproj", "{3F38E30E-4B47-47A0-B0C4-6BEDAB0736DE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OopUnitTesting", "OopUnitTesting\OopUnitTesting.csproj", "{1CF62E37-343B-4EEC-ADA1-746126B1A8C5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3F38E30E-4B47-47A0-B0C4-6BEDAB0736DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3F38E30E-4B47-47A0-B0C4-6BEDAB0736DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F38E30E-4B47-47A0-B0C4-6BEDAB0736DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3F38E30E-4B47-47A0-B0C4-6BEDAB0736DE}.Release|Any CPU.Build.0 = Release|Any CPU + {1CF62E37-343B-4EEC-ADA1-746126B1A8C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1CF62E37-343B-4EEC-ADA1-746126B1A8C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1CF62E37-343B-4EEC-ADA1-746126B1A8C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1CF62E37-343B-4EEC-ADA1-746126B1A8C5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {22FEE124-AEBA-467B-988C-242A770002DE} + EndGlobalSection +EndGlobal diff --git a/OopUnitTests/App.config b/OopUnitTests/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/OopUnitTests/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/OopUnitTests/Department.cs b/OopUnitTests/Department.cs new file mode 100644 index 0000000..3526812 --- /dev/null +++ b/OopUnitTests/Department.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + public class Department + { + EmployeeSalaryCalculatorsFactory employeeFactory = new EmployeeSalaryCalculatorsFactory(); + Dictionary dictionaryEmployee = new Dictionary(); + + private List managerList = new List(); + + public void AddToManagerList(Manager emp) + { + if(!managerList.Contains(emp)) + managerList.Add(emp); + } + + public decimal GetSallary(Employee currentEmployee) + { + Type employeeType = currentEmployee.GetType(); + + if (!dictionaryEmployee.ContainsKey(employeeType)) + { + dictionaryEmployee.Add(employeeType, employeeFactory.ReturnSalaryCalculator(currentEmployee)); + + return dictionaryEmployee[employeeType].CalculateEmployeeSallary(currentEmployee); + } + else + { + return dictionaryEmployee[employeeType].CalculateEmployeeSallary(currentEmployee); + } + + } + + public void ShowAll() + { + foreach (Manager man in managerList) + { + GetSallary(man); + foreach (Employee emp in man.ManagerMember) + { + if(emp.GetType() != typeof(Manager)) + GetSallary(emp); + } + } + } + } +} diff --git a/OopUnitTests/Employee/Designer.cs b/OopUnitTests/Employee/Designer.cs new file mode 100644 index 0000000..a759f90 --- /dev/null +++ b/OopUnitTests/Employee/Designer.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + public class Designer : Employee + { + public Designer(string firstName, string secondName, int experience, decimal salary, Manager manager, decimal effCoef) + : base(firstName, secondName, experience, salary, manager) + { + //manager.AddManagerMember(this); + base.CoefForDesigner = effCoef; + } + + public override void AddToManagerList() + { + Manager.AddManagerMember(this); + } + } +} diff --git a/OopUnitTests/Employee/Developer.cs b/OopUnitTests/Employee/Developer.cs new file mode 100644 index 0000000..4067487 --- /dev/null +++ b/OopUnitTests/Employee/Developer.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + public class Developer : Employee + { + public Developer(string firstName, string secondName, int experience, decimal salary, Manager manager) + : base(firstName, secondName, experience, salary, manager) + { + //manager.AddManagerMember(this); + // developer constructor + } + + public override void AddToManagerList() + { + Manager.AddManagerMember(this); + } + } +} diff --git a/OopUnitTests/Employee/Employee.cs b/OopUnitTests/Employee/Employee.cs new file mode 100644 index 0000000..70e849c --- /dev/null +++ b/OopUnitTests/Employee/Employee.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + public abstract class Employee + { + public string FirstName { get; set; } + public string SecondName { get; set; } + public int Experience { get; set; } + public Manager Manager { get; set; } + public decimal DefaultSalary { get; set; } + public decimal CoefForDesigner { get; set; } + + public Employee(string firstName, string secondName, int experience, decimal salary, Manager manager) + { + FirstName = firstName; + SecondName = secondName; + Experience = experience; + Manager = manager; + DefaultSalary = salary; + } + + public abstract void AddToManagerList(); + } +} diff --git a/OopUnitTests/Employee/Manager.cs b/OopUnitTests/Employee/Manager.cs new file mode 100644 index 0000000..a4b10d1 --- /dev/null +++ b/OopUnitTests/Employee/Manager.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + public class Manager : Employee + { + public List ManagerMember { get; } = new List(); + + public void AddManagerMember(Employee employee) + { + ManagerMember.Add(employee); + } + + public Manager(string firstName, string secondName, int experience, decimal salary, Manager manager) + : base(firstName, secondName, experience, salary, manager) + { + // manager constructor + //if(manager != null) + //manager.AddManagerMember(this); + } + + public override void AddToManagerList() + { + Manager.AddManagerMember(this); + } + + } + +} + diff --git a/OopUnitTests/OopHomeTask.csproj b/OopUnitTests/OopHomeTask.csproj new file mode 100644 index 0000000..672d130 --- /dev/null +++ b/OopUnitTests/OopHomeTask.csproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + {3F38E30E-4B47-47A0-B0C4-6BEDAB0736DE} + Exe + OopUnitTests + OopUnitTests + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OopUnitTests/Program.cs b/OopUnitTests/Program.cs new file mode 100644 index 0000000..9ba7570 --- /dev/null +++ b/OopUnitTests/Program.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + public class Program + { + static void Main(string[] args) + { + Department department = new Department(); + + Manager manager1 = new Manager("Anatolii", "Managerskyi", 7, 1000, null); + Manager manager2 = new Manager("Serhii", "Tojmanager", 3, 600, manager1); + + manager2.AddToManagerList(); + + department.AddToManagerList(manager1); + department.AddToManagerList(manager2); + + Designer designer1 = new Designer("Klark", "Designerskyi", 3, 1000, manager1, 0.9m); + designer1.AddToManagerList(); + + Designer designer2 = new Designer("Toni", "Koshkin", 10, 1500, manager2, 0.7m); + designer2.AddToManagerList(); + + Designer designer3 = new Designer("Vitalii", "Designerskyi", 3, 900, manager1, 0.9m); + designer3.AddToManagerList(); + + Developer dev1 = new Developer("Antoni", "Developerskyi", 3, 500, manager2); + dev1.AddToManagerList(); + + Developer dev2 = new Developer("Qver", "Devchik", 9, 3000, manager1); + dev2.AddToManagerList(); + + //department.GetSallary(manager1); + + Console.WriteLine(department.GetSallary(dev1)); + + Console.ReadKey(); + } + } +} diff --git a/OopUnitTests/Properties/AssemblyInfo.cs b/OopUnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9651785 --- /dev/null +++ b/OopUnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Общие сведения об этой сборке предоставляются следующим набором +// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения, +// связанные со сборкой. +[assembly: AssemblyTitle("OopUnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OopUnitTests")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми +// для компонентов COM. Если необходимо обратиться к типу в этой сборке через +// COM, задайте атрибуту ComVisible значение TRUE для этого типа. +[assembly: ComVisible(false)] + +// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM +[assembly: Guid("3f38e30e-4b47-47a0-b0c4-6bedab0736de")] + +// Сведения о версии сборки состоят из следующих четырех значений: +// +// Основной номер версии +// Дополнительный номер версии +// Номер сборки +// Редакция +// +// Можно задать все значения или принять номер сборки и номер редакции по умолчанию. +// используя "*", как показано ниже: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OopUnitTests/SalaryCalculators/DesignerSalaryCalculator.cs b/OopUnitTests/SalaryCalculators/DesignerSalaryCalculator.cs new file mode 100644 index 0000000..9474b01 --- /dev/null +++ b/OopUnitTests/SalaryCalculators/DesignerSalaryCalculator.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + class DesignerSalaryCalculator : ICalculateSalary + { + public decimal CalculateEmployeeSallary(Employee CurrrentDesigner) + { + decimal salaryWithBonus = CurrrentDesigner.DefaultSalary; + + if (CurrrentDesigner.Experience > 5) + { + salaryWithBonus = salaryWithBonus * 1.2m; + salaryWithBonus += 500; + } + else if (CurrrentDesigner.Experience > 2) + { + salaryWithBonus += 200; + } + + return salaryWithBonus * CurrrentDesigner.CoefForDesigner; + } + } +} diff --git a/OopUnitTests/SalaryCalculators/DeveloperSalaryCalculator.cs b/OopUnitTests/SalaryCalculators/DeveloperSalaryCalculator.cs new file mode 100644 index 0000000..ac5e16c --- /dev/null +++ b/OopUnitTests/SalaryCalculators/DeveloperSalaryCalculator.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + class DeveloperSalaryCalculator : ICalculateSalary + { + public decimal CalculateEmployeeSallary(Employee CurrentDeveloper) + { + decimal salaryWithBonus = CurrentDeveloper.DefaultSalary; + + if (CurrentDeveloper.Experience > 5) + { + salaryWithBonus = salaryWithBonus * 1.2m; + salaryWithBonus += 500; + } + else if (CurrentDeveloper.Experience > 2) + { + salaryWithBonus += 200; + } + + return salaryWithBonus; + } + } +} diff --git a/OopUnitTests/SalaryCalculators/EmployeeSalaryCalculator.cs b/OopUnitTests/SalaryCalculators/EmployeeSalaryCalculator.cs new file mode 100644 index 0000000..9a088ba --- /dev/null +++ b/OopUnitTests/SalaryCalculators/EmployeeSalaryCalculator.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + class EmployeeSalaryCalculatorsFactory + { + + public ICalculateSalary ReturnSalaryCalculator(Employee CurrentEmployee) + { + if(CurrentEmployee is Developer) + return new DeveloperSalaryCalculator(); + + if (CurrentEmployee is Designer) + return new DesignerSalaryCalculator(); + + if (CurrentEmployee is Manager) + return new ManagerSalaryCalculator(); + + else + throw new FormatException("Invalid employee type"); + } + + } +} diff --git a/OopUnitTests/SalaryCalculators/ICalculateSalary.cs b/OopUnitTests/SalaryCalculators/ICalculateSalary.cs new file mode 100644 index 0000000..2b504f8 --- /dev/null +++ b/OopUnitTests/SalaryCalculators/ICalculateSalary.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + interface ICalculateSalary + { + decimal CalculateEmployeeSallary(Employee instance); + } +} diff --git a/OopUnitTests/SalaryCalculators/ManagerSalaryCalculator.cs b/OopUnitTests/SalaryCalculators/ManagerSalaryCalculator.cs new file mode 100644 index 0000000..c3a8ed2 --- /dev/null +++ b/OopUnitTests/SalaryCalculators/ManagerSalaryCalculator.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OopUnitTests +{ + class ManagerSalaryCalculator : ICalculateSalary + { + public decimal CalculateEmployeeSallary(Employee currentManager) + { + Manager CurrentManager = (Manager)currentManager; + decimal SalaryWithBonus = CurrentManager.DefaultSalary; + + if (CurrentManager.Experience > 5) + { + SalaryWithBonus = SalaryWithBonus * 1.2m; + SalaryWithBonus += 500; + } + else if (CurrentManager.Experience > 2) + { + SalaryWithBonus += 200; + } + + if (CurrentManager.ManagerMember.Count > 10) + { + SalaryWithBonus += 300m; + } + else if (CurrentManager.ManagerMember.Count > 5) + { + SalaryWithBonus += 200m; + } + + decimal DevelopersCount = 0; + + for (int i = 0; i < CurrentManager.ManagerMember.Count; i++) + { + if (CurrentManager.ManagerMember[i] is Developer) + { + DevelopersCount++; + } + } + + if (DevelopersCount > (CurrentManager.ManagerMember.Count / 2)) + SalaryWithBonus *= 1.1m; + + return SalaryWithBonus; + } + } +}