Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made OOP Home Work #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions OopUnitTesting/OopUnitTesting.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.2.1" />
<PackageReference Include="MSTest.TestFramework" Version="1.2.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OopUnitTests\OopHomeTask.csproj" />
</ItemGroup>

</Project>
81 changes: 81 additions & 0 deletions OopUnitTesting/SalaryTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
31 changes: 31 additions & 0 deletions OopUnitTests.sln
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions OopUnitTests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
52 changes: 52 additions & 0 deletions OopUnitTests/Department.cs
Original file line number Diff line number Diff line change
@@ -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<Type, ICalculateSalary> dictionaryEmployee = new Dictionary<Type, ICalculateSalary>();

private List<Manager> managerList = new List<Manager>();

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);
}
}
}
}
}
23 changes: 23 additions & 0 deletions OopUnitTests/Employee/Designer.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
23 changes: 23 additions & 0 deletions OopUnitTests/Employee/Developer.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
29 changes: 29 additions & 0 deletions OopUnitTests/Employee/Employee.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
34 changes: 34 additions & 0 deletions OopUnitTests/Employee/Manager.cs
Original file line number Diff line number Diff line change
@@ -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<Employee> ManagerMember { get; } = new List<Employee>();

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);
}

}

}

62 changes: 62 additions & 0 deletions OopUnitTests/OopHomeTask.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3F38E30E-4B47-47A0-B0C4-6BEDAB0736DE}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>OopUnitTests</RootNamespace>
<AssemblyName>OopUnitTests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Department.cs" />
<Compile Include="SalaryCalculators\DesignerSalaryCalculator.cs" />
<Compile Include="SalaryCalculators\DeveloperSalaryCalculator.cs" />
<Compile Include="SalaryCalculators\EmployeeSalaryCalculator.cs" />
<Compile Include="Employee\Designer.cs" />
<Compile Include="Employee\Developer.cs" />
<Compile Include="Employee\Employee.cs" />
<Compile Include="Employee\Manager.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SalaryCalculators\ICalculateSalary.cs" />
<Compile Include="SalaryCalculators\ManagerSalaryCalculator.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading