Фух, ui тесты заработали
This commit is contained in:
parent
6715396027
commit
3eff31e7b3
@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmployeeManagmentBusinessLo
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmployeeManagmentDataModels", "EmployeeManagmentDataModels\EmployeeManagmentDataModels.csproj", "{C5293211-E924-4CFA-9DE5-69003D8C9F48}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmployeeManagmentDataModels", "EmployeeManagmentDataModels\EmployeeManagmentDataModels.csproj", "{C5293211-E924-4CFA-9DE5-69003D8C9F48}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeManagmentDataBaseImplement", "EmployeeManagmentDataBaseImplement\EmployeeManagmentDataBaseImplement.csproj", "{18CB8173-C3E1-4655-A453-A48F20E1DF2E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmployeeManagmentDataBaseImplement", "EmployeeManagmentDataBaseImplement\EmployeeManagmentDataBaseImplement.csproj", "{18CB8173-C3E1-4655-A453-A48F20E1DF2E}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeManagmentTests", "EmployeeManagmentTests\EmployeeManagmentTests.csproj", "{6C2F1F37-B54C-493D-82DC-70561145CF49}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -39,6 +41,10 @@ Global
|
|||||||
{18CB8173-C3E1-4655-A453-A48F20E1DF2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{18CB8173-C3E1-4655-A453-A48F20E1DF2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{18CB8173-C3E1-4655-A453-A48F20E1DF2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{18CB8173-C3E1-4655-A453-A48F20E1DF2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{18CB8173-C3E1-4655-A453-A48F20E1DF2E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{18CB8173-C3E1-4655-A453-A48F20E1DF2E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6C2F1F37-B54C-493D-82DC-70561145CF49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6C2F1F37-B54C-493D-82DC-70561145CF49}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6C2F1F37-B54C-493D-82DC-70561145CF49}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6C2F1F37-B54C-493D-82DC-70561145CF49}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
34
EmployeeManagmentTests/EmployeeManagmentTests.csproj
Normal file
34
EmployeeManagmentTests/EmployeeManagmentTests.csproj
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<UseWPF>true</UseWPF>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Appium.WebDriver" Version="6.0.1" />
|
||||||
|
<PackageReference Include="FlaUI.Core" Version="4.0.0" />
|
||||||
|
<PackageReference Include="FlaUI.UIA3" Version="4.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||||
|
<PackageReference Include="Microsoft.TestPlatform" Version="17.12.0" />
|
||||||
|
<PackageReference Include="Moq" Version="4.20.72" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
|
||||||
|
<PackageReference Include="xunit" Version="2.9.2" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\EmployeeManagmentBusinessLogic\EmployeeManagmentBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\EmployeeManagmentContracts\EmployeeManagmentContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\EmployeeManagmentDataBaseImplement\EmployeeManagmentDataBaseImplement.csproj" />
|
||||||
|
<ProjectReference Include="..\EmployeeManagmentDataModels\EmployeeManagmentDataModels.csproj" />
|
||||||
|
<ProjectReference Include="..\EmployeeManagmentView\EmployeeManagmentView.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
83
EmployeeManagmentTests/UI/MainWindowTests.cs
Normal file
83
EmployeeManagmentTests/UI/MainWindowTests.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using FlaUI.Core;
|
||||||
|
using FlaUI.Core.AutomationElements;
|
||||||
|
using FlaUI.Core.Input;
|
||||||
|
using FlaUI.Core.Tools;
|
||||||
|
using FlaUI.UIA3;
|
||||||
|
using Xunit;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace EmployeeManagmentTests.UI
|
||||||
|
{
|
||||||
|
[Collection("Sequential")]
|
||||||
|
public class MainWindowTests : IDisposable
|
||||||
|
{
|
||||||
|
private readonly Application _application;
|
||||||
|
private readonly AutomationBase _automation;
|
||||||
|
|
||||||
|
public MainWindowTests()
|
||||||
|
{
|
||||||
|
_automation = new UIA3Automation();
|
||||||
|
_application = Application.Launch("C:\\Users\\kashi\\Desktop\\Univer\\7\\КПО\\Project\\EmployeeManagmentView\\bin\\Debug\\net8.0-windows\\EmployeeManagmentView.exe");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestOpenEmployeeManagementWindow()
|
||||||
|
{
|
||||||
|
var mainWindow = _application.GetMainWindow(_automation);
|
||||||
|
var employeeButton = mainWindow.FindFirstDescendant(cf => cf.ByText("Работа с сотрудниками")).AsButton();
|
||||||
|
|
||||||
|
// Проверяем, что кнопка доступна и выполняем клик
|
||||||
|
Assert.True(employeeButton.IsEnabled, "Работа с сотрудниками");
|
||||||
|
employeeButton.Invoke();
|
||||||
|
|
||||||
|
// Ждем появления окна "Работа с сотрудниками" с тайм-аутом
|
||||||
|
var employeeManagementWindow = WaitForWindow("Управление сотрудниками");
|
||||||
|
Assert.NotNull(employeeManagementWindow);
|
||||||
|
|
||||||
|
// Проверяем, что окно доступно и готово к взаимодействию
|
||||||
|
Assert.True(employeeManagementWindow.IsEnabled, "Управление сотрудниками");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void TestOpenPhysicalPersonManagementWindow()
|
||||||
|
{
|
||||||
|
var mainWindow = _application.GetMainWindow(_automation);
|
||||||
|
var physicalPersonButton = mainWindow.FindFirstDescendant(cf => cf.ByText("Работа с физ. лицами")).AsButton();
|
||||||
|
|
||||||
|
// Проверяем, что кнопка доступна и выполняем клик
|
||||||
|
Assert.True(physicalPersonButton.IsEnabled, "Работа с физ. лицами");
|
||||||
|
physicalPersonButton.Invoke();
|
||||||
|
|
||||||
|
// Ждем появления окна "Работа с физ. лицами" с тайм-аутом
|
||||||
|
var physicalPersonManagementWindow = WaitForWindow("Управление физическими лицами");
|
||||||
|
Assert.NotNull(physicalPersonManagementWindow);
|
||||||
|
|
||||||
|
// Проверяем, что окно доступно и готово к взаимодействию
|
||||||
|
Assert.True(physicalPersonManagementWindow.IsEnabled, "Управление физическими лицами");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Window WaitForWindow(string windowTitle, int timeout = 10000) // Увеличен таймаут
|
||||||
|
{
|
||||||
|
var startTime = DateTime.Now;
|
||||||
|
while ((DateTime.Now - startTime).TotalMilliseconds < timeout)
|
||||||
|
{
|
||||||
|
var window = _application.GetAllTopLevelWindows(_automation)
|
||||||
|
.FirstOrDefault(w => w.Title.Contains(windowTitle));
|
||||||
|
if (window != null && window.IsEnabled)
|
||||||
|
{
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
Thread.Sleep(200); // Увеличена пауза между попытками
|
||||||
|
}
|
||||||
|
return null; // Если окно не найдено в пределах тайм-аута
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_application.Close();
|
||||||
|
_automation.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
138
EmployeeManagmentTests/Unit/EmployeeLogicTests.cs
Normal file
138
EmployeeManagmentTests/Unit/EmployeeLogicTests.cs
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
using Xunit;
|
||||||
|
using Moq;
|
||||||
|
using EmployeeManagmentBusinessLogic.BusinessLogic;
|
||||||
|
using EmployeeManagmentContracts.ViewModels;
|
||||||
|
using EmployeeManagmentContracts.SearchModels;
|
||||||
|
using EmployeeManagmentContracts.StoragesContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace EmployeeManagmentTests.Unit
|
||||||
|
{
|
||||||
|
public class EmployeeLogicTests
|
||||||
|
{
|
||||||
|
private readonly Mock<IEmployeeStorage> _mockStorage;
|
||||||
|
private readonly Mock<ILogger<EmployeeLogic>> _mockLogger;
|
||||||
|
private readonly EmployeeLogic _logic;
|
||||||
|
|
||||||
|
public EmployeeLogicTests()
|
||||||
|
{
|
||||||
|
_mockStorage = new Mock<IEmployeeStorage>();
|
||||||
|
_mockLogger = new Mock<ILogger<EmployeeLogic>>();
|
||||||
|
_logic = new EmployeeLogic(_mockLogger.Object, _mockStorage.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetFullList_ShouldReturnListOfEmployees()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedList = new List<EmployeeViewModel>
|
||||||
|
{
|
||||||
|
new EmployeeViewModel { Id = 1, NameJob = "Developer", StartJob = DateTime.Now.AddYears(-1) },
|
||||||
|
new EmployeeViewModel { Id = 2, NameJob = "Manager", StartJob = DateTime.Now.AddYears(-2) }
|
||||||
|
};
|
||||||
|
|
||||||
|
_mockStorage.Setup(x => x.GetFullList()).Returns(expectedList);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _logic.GetFullList();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(expectedList.Count, result.Count);
|
||||||
|
Assert.Equal(expectedList[0].NameJob, result[0].NameJob);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetFilteredList_ShouldReturnFilteredResults()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = new EmployeeSearchModel { NameJob = "Developer" };
|
||||||
|
var expectedList = new List<EmployeeViewModel>
|
||||||
|
{
|
||||||
|
new EmployeeViewModel { Id = 1, NameJob = "Developer", StartJob = DateTime.Now.AddYears(-1) }
|
||||||
|
};
|
||||||
|
|
||||||
|
_mockStorage.Setup(x => x.GetFilteredList(model)).Returns(expectedList);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _logic.GetFilteredList(model);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Single(result);
|
||||||
|
Assert.Equal("Developer", result[0].NameJob);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetFilteredList_ShouldReturnEmptyList_IfNoMatch()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = new EmployeeSearchModel { NameJob = "Unknown" };
|
||||||
|
_mockStorage.Setup(x => x.GetFilteredList(model)).Returns(new List<EmployeeViewModel>());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _logic.GetFilteredList(model);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Empty(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Insert_ShouldThrowException_IfNameJobIsEmpty()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var invalidModel = new EmployeeViewModel { NameJob = "" };
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<ArgumentException>(() => _logic.Insert(invalidModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Insert_ShouldCallStorageInsert_IfDataIsValid()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var validModel = new EmployeeViewModel { NameJob = "Developer", StartJob = DateTime.Now };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_logic.Insert(validModel);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_mockStorage.Verify(x => x.Insert(validModel), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Update_ShouldThrowException_IfElementNotFound()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = new EmployeeViewModel { Id = 1, NameJob = "Developer" };
|
||||||
|
_mockStorage.Setup(x => x.GetElement(model.Id)).Returns((EmployeeViewModel?)null);
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<ArgumentException>(() => _logic.Update(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Delete_ShouldThrowException_IfElementNotFound()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var id = 1;
|
||||||
|
_mockStorage.Setup(x => x.GetElement(id)).Returns((EmployeeViewModel?)null);
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<ArgumentException>(() => _logic.Delete(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Delete_ShouldCallStorageDelete_IfElementExists()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var id = 1;
|
||||||
|
var model = new EmployeeViewModel { Id = id };
|
||||||
|
_mockStorage.Setup(x => x.GetElement(id)).Returns(model);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_logic.Delete(id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_mockStorage.Verify(x => x.Delete(id), Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
139
EmployeeManagmentTests/Unit/PhisicalPersonLogicTests.cs
Normal file
139
EmployeeManagmentTests/Unit/PhisicalPersonLogicTests.cs
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
using Xunit;
|
||||||
|
using Moq;
|
||||||
|
using EmployeeManagmentBusinessLogic.BusinessLogic;
|
||||||
|
using EmployeeManagmentContracts.ViewModels;
|
||||||
|
using EmployeeManagmentContracts.SearchModels;
|
||||||
|
using EmployeeManagmentContracts.StoragesContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace EmployeeManagmentTests.Unit
|
||||||
|
{
|
||||||
|
public class PhisicalPersonLogicTests
|
||||||
|
{
|
||||||
|
private readonly Mock<IPhisicalPersonStorage> _mockStorage;
|
||||||
|
private readonly Mock<ILogger<PhisicalPersonLogic>> _mockLogger;
|
||||||
|
private readonly PhisicalPersonLogic _logic;
|
||||||
|
|
||||||
|
public PhisicalPersonLogicTests()
|
||||||
|
{
|
||||||
|
_mockStorage = new Mock<IPhisicalPersonStorage>();
|
||||||
|
_mockLogger = new Mock<ILogger<PhisicalPersonLogic>>();
|
||||||
|
_logic = new PhisicalPersonLogic(_mockLogger.Object, _mockStorage.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetFullList_ShouldReturnListOfPhisicalPersons()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedList = new List<PhisicalPersonViewModel>
|
||||||
|
{
|
||||||
|
new PhisicalPersonViewModel { Id = 1, Name = "John", Surname = "Doe" },
|
||||||
|
new PhisicalPersonViewModel { Id = 2, Name = "Jane", Surname = "Smith" }
|
||||||
|
};
|
||||||
|
|
||||||
|
_mockStorage.Setup(x => x.GetFullList()).Returns(expectedList);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _logic.GetFullList();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(expectedList.Count, result.Count);
|
||||||
|
Assert.Equal(expectedList[0].Name, result[0].Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetFilteredList_ShouldReturnFilteredResults()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = new PhisicalPersonSearchModel { Surname = "Doe" };
|
||||||
|
var expectedList = new List<PhisicalPersonViewModel>
|
||||||
|
{
|
||||||
|
new PhisicalPersonViewModel { Id = 1, Name = "John", Surname = "Doe" }
|
||||||
|
};
|
||||||
|
|
||||||
|
_mockStorage.Setup(x => x.GetFilteredList(model)).Returns(expectedList);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _logic.GetFilteredList(model);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Single(result);
|
||||||
|
Assert.Equal("Doe", result[0].Surname);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetFilteredList_ShouldReturnEmptyList_IfNoMatch()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = new PhisicalPersonSearchModel { Surname = "Unknown" };
|
||||||
|
_mockStorage.Setup(x => x.GetFilteredList(model)).Returns(new List<PhisicalPersonViewModel>());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _logic.GetFilteredList(model);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Empty(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Insert_ShouldThrowException_IfNameOrSurnameIsEmpty()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var invalidModel = new PhisicalPersonViewModel { Name = "", Surname = "" };
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<ArgumentException>(() => _logic.Insert(invalidModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Insert_ShouldCallStorageInsert_IfDataIsValid()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var validModel = new PhisicalPersonViewModel { Name = "John", Surname = "Doe" };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_logic.Insert(validModel);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_mockStorage.Verify(x => x.Insert(validModel), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Update_ShouldThrowException_IfElementNotFound()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var model = new PhisicalPersonViewModel { Id = 1, Name = "John", Surname = "Doe" };
|
||||||
|
_mockStorage.Setup(x => x.GetElement(model.Id)).Returns((PhisicalPersonViewModel?)null);
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<ArgumentException>(() => _logic.Update(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Delete_ShouldThrowException_IfElementNotFound()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var id = 1;
|
||||||
|
_mockStorage.Setup(x => x.GetElement(id)).Returns((PhisicalPersonViewModel?)null);
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
Assert.Throws<ArgumentException>(() => _logic.Delete(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Delete_ShouldCallStorageDelete_IfElementExists()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var id = 1;
|
||||||
|
var model = new PhisicalPersonViewModel { Id = id };
|
||||||
|
_mockStorage.Setup(x => x.GetElement(id)).Returns(model);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_logic.Delete(id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_mockStorage.Verify(x => x.Delete(id), Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
142
EmployeeManagmentTests/Unit/SalaryLogicTests.cs
Normal file
142
EmployeeManagmentTests/Unit/SalaryLogicTests.cs
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
using EmployeeManagmentBusinessLogic.BusinessLogic;
|
||||||
|
using EmployeeManagmentContracts.SearchModels;
|
||||||
|
using EmployeeManagmentContracts.ViewModels;
|
||||||
|
using EmployeeManagmentDataBaseImplement.Implements;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace EmployeeManagmentTests.Unit
|
||||||
|
{
|
||||||
|
public class SalaryLogicTests
|
||||||
|
{
|
||||||
|
private readonly Mock<ILogger<SalaryLogic>> _loggerMock;
|
||||||
|
private readonly SalaryStorage _salaryStorage;
|
||||||
|
private readonly SalaryLogic _salaryLogic;
|
||||||
|
|
||||||
|
public SalaryLogicTests()
|
||||||
|
{
|
||||||
|
_loggerMock = new Mock<ILogger<SalaryLogic>>();
|
||||||
|
_salaryStorage = new SalaryStorage();
|
||||||
|
_salaryLogic = new SalaryLogic(_loggerMock.Object, _salaryStorage);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetFullList_ShouldReturnAllSalaries()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedCount = _salaryStorage.GetFullList().Count;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _salaryLogic.GetFullList();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.Equal(expectedCount, result.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetFilteredList_ShouldReturnFilteredSalaries()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var filter = new SalarySearchModel
|
||||||
|
{
|
||||||
|
Date = DateTime.UtcNow.AddMonths(-1) // Используйте UTC
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _salaryLogic.GetFilteredList(filter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.All(result, salary => Assert.True(salary.Date >= filter.Date));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetElement_ShouldReturnCorrectSalary()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var salaries = _salaryLogic.GetFullList();
|
||||||
|
if (salaries.Count == 0)
|
||||||
|
{
|
||||||
|
Assert.True(false, "No salaries available for testing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var salaryId = salaries.First().Id;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _salaryLogic.GetElement(salaryId);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.Equal(salaryId, result.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Insert_ShouldAddSalary()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var newSalary = new SalaryViewModel
|
||||||
|
{
|
||||||
|
CountHours = 40,
|
||||||
|
PriceHour = 15,
|
||||||
|
Premium = 200,
|
||||||
|
Date = DateTime.UtcNow, // Используем UTC для даты
|
||||||
|
Passed = false,
|
||||||
|
EmployeeId = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
var initialCount = _salaryLogic.GetFullList().Count;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_salaryLogic.Insert(newSalary);
|
||||||
|
var updatedCount = _salaryLogic.GetFullList().Count;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(initialCount + 1, updatedCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Update_ShouldModifySalary()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var salary = _salaryLogic.GetFullList().FirstOrDefault();
|
||||||
|
if (salary == null)
|
||||||
|
{
|
||||||
|
Assert.True(false, "No salaries available for testing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
salary.PriceHour += 5;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_salaryLogic.Update(salary);
|
||||||
|
var updatedSalary = _salaryLogic.GetElement(salary.Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(updatedSalary);
|
||||||
|
Assert.Equal(salary.PriceHour, updatedSalary.PriceHour);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Delete_ShouldRemoveSalary()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var salary = _salaryLogic.GetFullList().LastOrDefault();
|
||||||
|
if (salary == null)
|
||||||
|
{
|
||||||
|
Assert.True(false, "No salaries available for testing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var initialCount = _salaryLogic.GetFullList().Count;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_salaryLogic.Delete(salary.Id);
|
||||||
|
var updatedCount = _salaryLogic.GetFullList().Count;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(initialCount - 1, updatedCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
144
EmployeeManagmentTests/Unit/VacationLogicTests.cs
Normal file
144
EmployeeManagmentTests/Unit/VacationLogicTests.cs
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
using EmployeeManagmentBusinessLogic.BusinessLogic;
|
||||||
|
using EmployeeManagmentContracts.SearchModels;
|
||||||
|
using EmployeeManagmentContracts.ViewModels;
|
||||||
|
using EmployeeManagmentDataBaseImplement.Implements;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Moq;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace EmployeeManagmentTests.Unit
|
||||||
|
{
|
||||||
|
public class VacationLogicTests
|
||||||
|
{
|
||||||
|
private readonly Mock<ILogger<VacationLogic>> _loggerMock;
|
||||||
|
private readonly VacationStorage _vacationStorage;
|
||||||
|
private readonly VacationLogic _vacationLogic;
|
||||||
|
|
||||||
|
public VacationLogicTests()
|
||||||
|
{
|
||||||
|
_loggerMock = new Mock<ILogger<VacationLogic>>();
|
||||||
|
_vacationStorage = new VacationStorage();
|
||||||
|
_vacationLogic = new VacationLogic(_loggerMock.Object, _vacationStorage);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetFullList_ShouldReturnAllVacations()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedCount = _vacationStorage.GetFullList().Count;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _vacationLogic.GetFullList();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.Equal(expectedCount, result.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetFilteredList_ShouldReturnFilteredVacations()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var filter = new VacationSearchModel
|
||||||
|
{
|
||||||
|
StartData = DateTime.UtcNow.AddMonths(-1),
|
||||||
|
EndData = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _vacationLogic.GetFilteredList(filter);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.All(result, vacation =>
|
||||||
|
Assert.True(vacation.StartData >= filter.StartData && vacation.EndData <= filter.EndData)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetElement_ShouldReturnCorrectVacation()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var vacations = _vacationLogic.GetFullList();
|
||||||
|
if (vacations.Count == 0)
|
||||||
|
{
|
||||||
|
Assert.True(false, "No vacations available for testing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var vacationId = vacations.First().Id;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = _vacationLogic.GetElement(vacationId);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.Equal(vacationId, result.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Insert_ShouldAddVacation()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var newVacation = new VacationViewModel
|
||||||
|
{
|
||||||
|
StartData = DateTime.UtcNow.AddDays(1).ToUniversalTime(), // Преобразование в UTC
|
||||||
|
EndData = DateTime.UtcNow.AddDays(10).ToUniversalTime(), // Преобразование в UTC
|
||||||
|
Passed = false,
|
||||||
|
EmployeeId = 1 // ID существующего сотрудника
|
||||||
|
};
|
||||||
|
|
||||||
|
var initialCount = _vacationLogic.GetFullList().Count;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_vacationLogic.Insert(newVacation);
|
||||||
|
var updatedCount = _vacationLogic.GetFullList().Count;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(initialCount + 1, updatedCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Update_ShouldModifyVacation()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var vacation = _vacationLogic.GetFullList().FirstOrDefault();
|
||||||
|
if (vacation == null)
|
||||||
|
{
|
||||||
|
Assert.True(false, "No vacations available for testing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
vacation.EndData = DateTime.UtcNow.AddDays(20).ToUniversalTime(); // Преобразование в UTC
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_vacationLogic.Update(vacation);
|
||||||
|
var updatedVacation = _vacationLogic.GetElement(vacation.Id);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.NotNull(updatedVacation);
|
||||||
|
|
||||||
|
// Сравниваем с учетом допустимой погрешности в миллисекундах
|
||||||
|
Assert.Equal(vacation.EndData, updatedVacation.EndData, TimeSpan.FromMilliseconds(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Delete_ShouldRemoveVacation()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var vacation = _vacationLogic.GetFullList().LastOrDefault();
|
||||||
|
if (vacation == null)
|
||||||
|
{
|
||||||
|
Assert.True(false, "No vacations available for testing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var initialCount = _vacationLogic.GetFullList().Count;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_vacationLogic.Delete(vacation.Id);
|
||||||
|
var updatedCount = _vacationLogic.GetFullList().Count;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(initialCount - 1, updatedCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
<Window x:Class="EmployeeManagmentView.Employee.EmployeeManagementWindow"
|
<Window x:Class="EmployeeManagmentView.Employee.EmployeeManagementWindow"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
Title="Управление физическими лицами"
|
Title="Управление сотрудниками"
|
||||||
Height="400" Width="400"
|
Height="400" Width="400"
|
||||||
ResizeMode="NoResize"
|
ResizeMode="NoResize"
|
||||||
WindowStartupLocation="CenterScreen"
|
WindowStartupLocation="CenterScreen"
|
||||||
|
@ -25,7 +25,7 @@ namespace EmployeeManagmentView
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenPhysicalPersonManagementWindow(object sender, RoutedEventArgs e)
|
public void OpenPhysicalPersonManagementWindow(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
foreach (Window window in Application.Current.Windows)
|
foreach (Window window in Application.Current.Windows)
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ namespace EmployeeManagmentView
|
|||||||
physicalPersonWindow.Show();
|
physicalPersonWindow.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenEmployeeManagementWindow(object sender, RoutedEventArgs e)
|
public void OpenEmployeeManagementWindow(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
foreach (Window window in Application.Current.Windows)
|
foreach (Window window in Application.Current.Windows)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user