Сделал реализацию
This commit is contained in:
@@ -1,49 +1,217 @@
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract _complitedWorkStorageContract) : IComplitedWorkBusinessLogicContract
|
||||
internal class ComplitedWorkBusinessLogicContract(IComplitedWorkStorageContract _complitedWorkStorageContract, ILogger _logger) : IComplitedWorkBusinessLogicContract
|
||||
{
|
||||
private IComplitedWorkStorageContract complitedWorkStorageContract = _complitedWorkStorageContract;
|
||||
public List<ComplitedWorkDataModel> GetAllComplitedWorks()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
private ILogger logger = _logger;
|
||||
|
||||
public List<ComplitedWorkDataModel> GetComplitedWorksByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Fetching completed works between {FromDate} and {ToDate}.", fromDate, toDate);
|
||||
|
||||
if (fromDate >= toDate)
|
||||
{
|
||||
_logger.LogError("Invalid date range: fromDate ({FromDate}) must be earlier than toDate ({ToDate}).", fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(fromDate, toDate);
|
||||
if (result == null)
|
||||
{
|
||||
logger.LogError("No completed works found in the specified period.");
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetched {Count} completed works in the specified period.", result.Count);
|
||||
return result;
|
||||
}
|
||||
|
||||
public ComplitedWorkDataModel GetComplitedWorkByData(string complitedWorkId)
|
||||
{
|
||||
logger.LogInformation("Fetching completed work by ID: {WorkId}.", complitedWorkId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(complitedWorkId) || !Guid.TryParse(complitedWorkId, out _))
|
||||
{
|
||||
logger.LogError("Invalid completed work ID: {WorkId}", complitedWorkId);
|
||||
throw new ValidationException("Invalid completed work ID.");
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetElementById(complitedWorkId);
|
||||
if (result == null)
|
||||
{
|
||||
logger.LogError("Completed work with ID {WorkId} not found.", complitedWorkId);
|
||||
throw new ElementNotFoundException($"Completed work with ID {complitedWorkId} not found.");
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetched completed work {WorkId}.", result.Id);
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ComplitedWorkDataModel> GetComplitedWorksByRoomByPeriod(string roomId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
return [];
|
||||
if (string.IsNullOrWhiteSpace(roomId))
|
||||
{
|
||||
logger.LogError("Room ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(roomId), "Room ID cannot be null or empty.");
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetching completed works for room {RoomId} from {FromDate} to {ToDate}.", roomId, fromDate, toDate);
|
||||
|
||||
if (!Guid.TryParse(roomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid Room ID format: {RoomId}.", roomId);
|
||||
throw new ValidationException("Invalid Room ID.");
|
||||
}
|
||||
|
||||
if (fromDate >= toDate)
|
||||
{
|
||||
logger.LogError("Invalid date range: From {FromDate} To {ToDate}.", fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate);
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(fromDate, toDate, roomId, null, null);
|
||||
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("Storage returned null list for room {RoomId}.", roomId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Found {Count} completed works for room {RoomId}.", result.Count, roomId);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<ComplitedWorkDataModel> GetComplitedWorksByWorkTypeByPeriod(string workId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Fetching completed works for work type {WorkId} from {FromDate} to {ToDate}.", workId, fromDate, toDate);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(workId))
|
||||
{
|
||||
logger.LogError("Work ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(workId), "Work ID cannot be null or empty.");
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(workId, out _))
|
||||
{
|
||||
logger.LogError("Invalid Work ID format: {WorkId}.", workId);
|
||||
throw new ValidationException("Invalid work ID.");
|
||||
}
|
||||
|
||||
if (fromDate >= toDate)
|
||||
{
|
||||
logger.LogError("Invalid date range: From {FromDate} To {ToDate}.", fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate);
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(fromDate, toDate, null, workId, null);
|
||||
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("Storage returned null list for worker {WorkId}.", workId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Found {Count} completed works for work type {WorkId}.", result.Count, workId);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public List<ComplitedWorkDataModel> GetComplitedWorksByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Fetching completed works for worker {WorkerId} from {FromDate} to {ToDate}.", workerId, fromDate, toDate);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(workerId))
|
||||
{
|
||||
logger.LogError("Worker ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(workerId), "Worker ID cannot be null or empty.");
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(workerId, out _))
|
||||
{
|
||||
logger.LogError("Invalid Worker ID format: {WorkerId}.", workerId);
|
||||
throw new ValidationException("Invalid worker ID.");
|
||||
}
|
||||
|
||||
if (fromDate >= toDate)
|
||||
{
|
||||
logger.LogError("Invalid date range: From {FromDate} To {ToDate}.", fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate,toDate);
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(fromDate, toDate, null, null, workerId);
|
||||
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("Storage returned null list for worker {WorkerId}.", workerId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Found {Count} completed works for worker {WorkerId}.", result.Count, workerId);
|
||||
return result;
|
||||
}
|
||||
|
||||
public ComplitedWorkDataModel GetComplitedWorkByData(string data)
|
||||
{
|
||||
return new ComplitedWorkDataModel("", "", "", []);
|
||||
}
|
||||
|
||||
public void InsertComplitedWork(ComplitedWorkDataModel complitedWorkDataModel)
|
||||
{
|
||||
logger.LogInformation("Inserting completed work: {ComplitedWorkId}", complitedWorkDataModel.Id);
|
||||
|
||||
if (!Guid.TryParse(complitedWorkDataModel.Id, out _))
|
||||
{
|
||||
logger.LogError("Invalid completed work ID format: {ComplitedWorkId}", complitedWorkDataModel.Id);
|
||||
throw new ValidationException("Invalid completed work ID.");
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(complitedWorkDataModel.WorkId, out _))
|
||||
{
|
||||
logger.LogError("Invalid work ID format: {WorkId}", complitedWorkDataModel.WorkId);
|
||||
throw new ValidationException("Invalid work ID.");
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(complitedWorkDataModel.RoomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID format: {RoomId}", complitedWorkDataModel.RoomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
if (complitedWorkDataModel.Workers is null)
|
||||
{
|
||||
logger.LogError("Attempted to insert completed work without assigned workers.");
|
||||
throw new ValidationException("Completed work must have at least one assigned worker.");
|
||||
}
|
||||
|
||||
logger.LogInformation("Completed work {ComplitedWorkId} has been validated successfully.", complitedWorkDataModel.Id);
|
||||
complitedWorkStorageContract.AddElement(complitedWorkDataModel);
|
||||
}
|
||||
|
||||
public void DeleteComplitedWork(string id)
|
||||
|
||||
public void DeleteComplitedWork(string complitedWorkId)
|
||||
{
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(complitedWorkId))
|
||||
{
|
||||
logger.LogError("Attempt to delete completed work with null or empty ID.");
|
||||
throw new ArgumentNullException("Completed work ID cannot be null or empty.");
|
||||
}
|
||||
|
||||
logger.LogInformation("Deleting completed work with ID: {WorkId}.", complitedWorkId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(complitedWorkId) || !Guid.TryParse(complitedWorkId, out _))
|
||||
{
|
||||
logger.LogError("Invalid completed work ID: {WorkId}", complitedWorkId);
|
||||
throw new ValidationException("Invalid completed work ID.");
|
||||
}
|
||||
|
||||
complitedWorkStorageContract.DelElement(complitedWorkId);
|
||||
logger.LogInformation("Completed work with ID {WorkId} deleted.", complitedWorkId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,41 +1,174 @@
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class RoomBusinessLogicContract(IRoomStorageContract _roomStorageContract) : IRoomBusinessLogicContract
|
||||
internal class RoomBusinessLogicContract(IRoomStorageContract _roomStorageContract, ILogger _logger) : IRoomBusinessLogicContract
|
||||
{
|
||||
private IRoomStorageContract roomStorageContract = _roomStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
public List<RoomDataModel> GetAllRooms()
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Retrieving all rooms.");
|
||||
var rooms = roomStorageContract.GetList();
|
||||
|
||||
if (rooms == null)
|
||||
{
|
||||
logger.LogError("Room list is null.");
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Successfully retrieved {Count} rooms.", rooms.Count);
|
||||
return rooms;
|
||||
}
|
||||
|
||||
public List<RoomDataModel> GetRoomsByOwner(string ownerName)
|
||||
public List<RoomDataModel> GetRoomsByOwner(string ownerFIO)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Retrieving rooms by owner Name: {ownerFIO}", ownerFIO);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ownerFIO))
|
||||
{
|
||||
logger.LogError("Owner ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(ownerFIO));
|
||||
}
|
||||
|
||||
var rooms = roomStorageContract.GetListByOwner(ownerFIO);
|
||||
if (rooms == null)
|
||||
{
|
||||
logger.LogError("No rooms found for owner FIO: {ownerFIO}", ownerFIO);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Found {Count} rooms for owner FIO: {ownerFIO}", rooms.Count, ownerFIO);
|
||||
return rooms;
|
||||
}
|
||||
|
||||
public List<RoomDataModel> GetRoomsByAddress(string address)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Retrieving rooms by address: {Address}", address);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(address))
|
||||
{
|
||||
logger.LogError("Address is null or empty.");
|
||||
throw new ArgumentNullException(nameof(address));
|
||||
}
|
||||
|
||||
var rooms = roomStorageContract.GetListByAddress(address);
|
||||
if (rooms == null)
|
||||
{
|
||||
logger.LogError("No rooms found at address: {Address}", address);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Found {Count} rooms at address: {Address}", rooms.Count, address);
|
||||
return rooms;
|
||||
}
|
||||
|
||||
public RoomDataModel GetRoomByData(string data)
|
||||
public RoomDataModel GetRoomByData(string roomId)
|
||||
{
|
||||
return new RoomDataModel("", "", "", 0, TwoFromTheCasketContracts.Enums.TypeRoom.Office);
|
||||
logger.LogInformation("Retrieving room by ID: {RoomId}", roomId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomId))
|
||||
{
|
||||
logger.LogError("Room ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(roomId));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(roomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID format: {RoomId}", roomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
var room = roomStorageContract.GetElementById(roomId);
|
||||
if (room == null)
|
||||
{
|
||||
logger.LogError("Room not found: {RoomId}", roomId);
|
||||
throw new ElementNotFoundException(roomId);
|
||||
}
|
||||
|
||||
logger.LogInformation("Successfully retrieved room: {RoomId}", roomId);
|
||||
return room;
|
||||
}
|
||||
|
||||
public void InsertRoom(RoomDataModel roomDataModel)
|
||||
{
|
||||
logger.LogInformation("Inserting new room.");
|
||||
|
||||
if (roomDataModel == null)
|
||||
{
|
||||
logger.LogError("Attempted to insert a null room.");
|
||||
throw new ArgumentNullException(nameof(roomDataModel));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(roomDataModel.Id, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID: {RoomId}", roomDataModel.Id);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomDataModel.Address))
|
||||
{
|
||||
logger.LogError("Invalid room address.");
|
||||
throw new ValidationException("Room address cannot be empty.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomDataModel.OwnerFIO))
|
||||
{
|
||||
logger.LogError("Invalid owner FIO: {OwnerFIO}", roomDataModel.OwnerFIO);
|
||||
throw new ValidationException("Room OwnerFIO cannot be empty.");
|
||||
}
|
||||
|
||||
roomStorageContract.AddElement(roomDataModel);
|
||||
logger.LogInformation("Room {RoomId} inserted successfully.", roomDataModel.Id);
|
||||
}
|
||||
|
||||
public void UpdateRoom(RoomDataModel roomDataModel)
|
||||
{
|
||||
logger.LogInformation("Updating room: {RoomId}", roomDataModel.Id);
|
||||
|
||||
if (!Guid.TryParse(roomDataModel.Id, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID: {RoomId}", roomDataModel.Id);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomDataModel.Address))
|
||||
{
|
||||
logger.LogError("Invalid room address.");
|
||||
throw new ValidationException("Room address cannot be empty.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomDataModel.OwnerFIO))
|
||||
{
|
||||
logger.LogError("Invalid owner FIO: {OwnerFIO}", roomDataModel.OwnerFIO);
|
||||
throw new ValidationException("Room OwnerFIO cannot be empty.");
|
||||
}
|
||||
|
||||
roomStorageContract.UpdElement(roomDataModel);
|
||||
logger.LogInformation("Room {RoomId} updated successfully.", roomDataModel.Id);
|
||||
}
|
||||
|
||||
public void DeleteRoom(string id)
|
||||
public void DeleteRoom(string roomId)
|
||||
{
|
||||
logger.LogInformation("Deleting room: {RoomId}", roomId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomId))
|
||||
{
|
||||
logger.LogError("Room ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(roomId));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(roomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID format: {RoomId}", roomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
roomStorageContract.DelElement(roomId);
|
||||
logger.LogInformation("Room {RoomId} deleted successfully.", roomId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,101 @@
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class RoomHistoryBusinessLogicContract(IRoomHistoryStorageContract _roomHistoryStorageContract) : IRoomHistoryBusinessLogicContract
|
||||
internal class RoomHistoryBusinessLogicContract(IRoomHistoryStorageContract _roomHistoryStorageContract, ILogger _logger) : IRoomHistoryBusinessLogicContract
|
||||
{
|
||||
private IRoomHistoryStorageContract roomHistoryStorageContract = _roomHistoryStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
public List<RoomHistoryDataModel> GetRoomHistory(string roomId)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Retrieving history for room: {RoomId}", roomId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomId))
|
||||
{
|
||||
logger.LogError("Room ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(roomId));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(roomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID format: {RoomId}", roomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
var history = roomHistoryStorageContract.GetList(roomId);
|
||||
|
||||
if (history == null)
|
||||
{
|
||||
logger.LogError("No history found for room ID: {RoomId}", roomId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Retrieved {Count} history records for room ID: {RoomId}", history.Count, roomId);
|
||||
return history;
|
||||
}
|
||||
|
||||
public RoomHistoryDataModel GetLatestRoomHistory(string roomId)
|
||||
{
|
||||
return new RoomHistoryDataModel("", "", TwoFromTheCasketContracts.Enums.TypeRoom.Office, DateTime.Now);
|
||||
logger.LogInformation("Retrieving latest history for room: {RoomId}", roomId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(roomId))
|
||||
{
|
||||
logger.LogError("Room ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(roomId));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(roomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID format: {RoomId}", roomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
var historyRecords = roomHistoryStorageContract.GetList(roomId);
|
||||
|
||||
if (historyRecords == null || historyRecords.Count == 0)
|
||||
{
|
||||
logger.LogError("No history records found for room ID: {RoomId}", roomId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
var latestHistory = historyRecords.MaxBy(h => h.DateChange);
|
||||
if (latestHistory == null)
|
||||
{
|
||||
logger.LogError("Failed to determine latest history record for room ID: {RoomId}", roomId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Retrieved latest history record for room ID: {RoomId}", roomId);
|
||||
return latestHistory;
|
||||
}
|
||||
|
||||
public void AddRoomHistory(RoomHistoryDataModel roomHistoryDataModel)
|
||||
{
|
||||
logger.LogInformation("Adding room history.");
|
||||
|
||||
if (roomHistoryDataModel == null)
|
||||
{
|
||||
logger.LogError("Attempted to insert a null room history.");
|
||||
throw new ArgumentNullException(nameof(roomHistoryDataModel));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(roomHistoryDataModel.RoomId, out _))
|
||||
{
|
||||
logger.LogError("Invalid room ID: {RoomId}", roomHistoryDataModel.RoomId);
|
||||
throw new ValidationException("Invalid room ID.");
|
||||
}
|
||||
|
||||
if (roomHistoryDataModel.DateChange == default)
|
||||
{
|
||||
logger.LogError("Invalid change date.");
|
||||
throw new ValidationException("Invalid change date.");
|
||||
}
|
||||
|
||||
roomHistoryStorageContract.AddElement(roomHistoryDataModel);
|
||||
logger.LogInformation("Room history added successfully for room: {RoomId}", roomHistoryDataModel.RoomId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,79 @@
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract _salaryStorageContract, IWorkerStorageContract _workerStorageContract,
|
||||
IComplitedWorkStorageContract _сomplitedWorkStorageContract, ISpecializationStorageContract _specializationStorageContract) : ISalaryBusinessLogicContract
|
||||
IComplitedWorkStorageContract _сomplitedWorkStorageContract, ISpecializationStorageContract _specializationStorageContract, ILogger _logger) : ISalaryBusinessLogicContract
|
||||
{
|
||||
private ISalaryStorageContract salaryStorageContract = _salaryStorageContract;
|
||||
private IWorkerStorageContract workerStorageContract = _workerStorageContract;
|
||||
private IComplitedWorkStorageContract сomplitedWorkStorageContract = _сomplitedWorkStorageContract;
|
||||
private ISpecializationStorageContract specializationStorageContract = _specializationStorageContract;
|
||||
public List<SalaryDataModel> GetSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private ILogger logger = _logger;
|
||||
public List<SalaryDataModel> GetSalariesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
return [];
|
||||
if (string.IsNullOrWhiteSpace(workerId))
|
||||
throw new ArgumentNullException(nameof(workerId), "Worker ID cannot be null or empty.");
|
||||
|
||||
if (!Guid.TryParse(workerId, out _))
|
||||
throw new ValidationException("Invalid worker ID format.");
|
||||
|
||||
if (fromDate >= toDate)
|
||||
throw new IncorrectDatesException(fromDate,toDate);
|
||||
|
||||
_logger.LogInformation("Fetching salaries for worker {WorkerId} from {FromDate} to {ToDate}", workerId, fromDate, toDate);
|
||||
|
||||
var salaries = _salaryStorageContract.GetList(fromDate, toDate, workerId) ?? throw new NullListException();
|
||||
|
||||
return salaries;
|
||||
}
|
||||
|
||||
public List<SalaryDataModel> GetSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
if (fromDate >= toDate)
|
||||
throw new IncorrectDatesException(fromDate,toDate);
|
||||
|
||||
_logger.LogInformation("Fetching salaries from {FromDate} to {ToDate}", fromDate, toDate);
|
||||
|
||||
var salaries = _salaryStorageContract.GetList(fromDate, toDate, null) ?? throw new NullListException();
|
||||
|
||||
return salaries;
|
||||
}
|
||||
|
||||
public void CalculateSalaryByMonth(DateTime date)
|
||||
{
|
||||
return;
|
||||
_logger.LogInformation("Calculating salary for month: {Date}", date);
|
||||
|
||||
var startDate = new DateTime(date.Year, date.Month, 1);
|
||||
var finishDate = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
|
||||
|
||||
var workers = _workerStorageContract.GetList() ?? throw new StorageException(new InvalidOperationException("Failed to retrieve workerStorageContract from storage."));
|
||||
|
||||
foreach (var worker in workers)
|
||||
{
|
||||
var completedWorks = сomplitedWorkStorageContract.GetList(startDate, finishDate, WorkerId: worker.Id);
|
||||
|
||||
if (completedWorks == null)
|
||||
throw new StorageException(new InvalidOperationException("Failed to retrieve completed works from storage."));
|
||||
|
||||
var totalHours = completedWorks
|
||||
.SelectMany(cw => cw.Workers)
|
||||
.Where(wcw => wcw.WorkerId == worker.Id)
|
||||
.Sum(wcw => wcw.NumberOfWorkingHours);
|
||||
|
||||
var specialization = _specializationStorageContract.GetElementById(worker.SpecializationId)
|
||||
?? throw new NullListException();
|
||||
|
||||
var salary = specialization.Salary + (totalHours * 100);
|
||||
|
||||
_logger.LogDebug("Calculated salary for worker {WorkerId}: {Salary}", worker.Id, salary);
|
||||
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(Guid.NewGuid().ToString(), worker.Id, salary));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +1,155 @@
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class SpecializationBusinessLogicContract(ISpecializationStorageContract _specializationStorageContract) : ISpecializationBusinessLogicContract
|
||||
internal class SpecializationBusinessLogicContract(ISpecializationStorageContract _specializationStorageContract, ILogger _logger) : ISpecializationBusinessLogicContract
|
||||
{
|
||||
private ISpecializationStorageContract specializationStorageContract = _specializationStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
|
||||
public List<Specialization> GetAllSpecializations()
|
||||
{
|
||||
logger.LogInformation("Retrieving all specializations");
|
||||
|
||||
var specializations = _specializationStorageContract.GetList()
|
||||
?? throw new NullListException();
|
||||
|
||||
return specializations;
|
||||
}
|
||||
|
||||
public List<Specialization> GetAllSpecializations(bool onlyActual = true)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Retrieving all specializations (only actual: {OnlyActual})", onlyActual);
|
||||
|
||||
var specializations = _specializationStorageContract.GetList()
|
||||
?? throw new NullListException();
|
||||
|
||||
return onlyActual
|
||||
? specializations.Where(s => s.IsActual).ToList()
|
||||
: specializations;
|
||||
}
|
||||
|
||||
public Specialization GetLatestSpecializationById(string specializationId)
|
||||
{
|
||||
return new Specialization("", "", "", 0, true, DateTime.Now);
|
||||
if (string.IsNullOrWhiteSpace(specializationId))
|
||||
throw new ArgumentNullException(nameof(specializationId), "Specialization ID cannot be null or empty");
|
||||
|
||||
if (!Guid.TryParse(specializationId, out _))
|
||||
throw new ValidationException("Invalid specialization ID format");
|
||||
|
||||
logger.LogInformation("Retrieving latest specialization by ID: {SpecializationId}", specializationId);
|
||||
|
||||
var specialization = _specializationStorageContract.GetElementById(specializationId)
|
||||
?? throw new ElementNotFoundException($"Specialization with ID '{specializationId}' not found");
|
||||
|
||||
return specialization;
|
||||
}
|
||||
|
||||
public Specialization GetLatestSpecializationByName(string specializationyName)
|
||||
public Specialization GetLatestSpecializationByName(string specializationName)
|
||||
{
|
||||
return new Specialization("", "", "", 0, true, DateTime.Now);
|
||||
logger.LogInformation("Retrieving latest specialization by name: {SpecializationName}", specializationName);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(specializationName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(specializationName), "Specialization name cannot be null or empty.");
|
||||
}
|
||||
|
||||
List<Specialization> specializations;
|
||||
try
|
||||
{
|
||||
specializations = _specializationStorageContract.GetList();
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
logger.LogError(ex, "Storage exception occurred while retrieving specializations.");
|
||||
throw;
|
||||
}
|
||||
|
||||
if (specializations == null)
|
||||
{
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
var latestSpecialization = specializations
|
||||
.Where(s => s.SpecializationName == specializationName)
|
||||
.OrderByDescending(s => s.ChangeDate)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (latestSpecialization == null)
|
||||
{
|
||||
throw new ElementNotFoundException($"No specialization found with name: {specializationName}");
|
||||
}
|
||||
|
||||
return latestSpecialization;
|
||||
}
|
||||
|
||||
public void AddSpecialization(Specialization specializationId)
|
||||
|
||||
public void AddSpecialization(Specialization specialization)
|
||||
{
|
||||
|
||||
logger.LogInformation("Adding new specialization: {SpecializationName}", specialization.SpecializationName);
|
||||
|
||||
if (_specializationStorageContract.GetList()?.Any(s => s.SpecializationName.Equals(specialization.SpecializationName, StringComparison.OrdinalIgnoreCase)) == true)
|
||||
throw new ElementExistsException("Specialization", specialization.SpecializationName);
|
||||
|
||||
_specializationStorageContract.AddElement(specialization);
|
||||
}
|
||||
|
||||
public void DeactivateSpecialization(string specializationId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(specializationId))
|
||||
throw new ArgumentNullException(nameof(specializationId), "Specialization ID cannot be null or empty");
|
||||
|
||||
if (!Guid.TryParse(specializationId, out _))
|
||||
throw new ValidationException("Invalid specialization ID format");
|
||||
|
||||
logger.LogInformation("Deactivating specialization: {SpecializationId}", specializationId);
|
||||
|
||||
var specialization = _specializationStorageContract.GetElementById(specializationId)
|
||||
?? throw new ElementNotFoundException($"Specialization with ID {specializationId} not found");
|
||||
|
||||
if (!specialization.IsActual)
|
||||
throw new ValidationException("Specialization is already deactivated");
|
||||
|
||||
var updatedSpecialization = new Specialization(
|
||||
specialization.Id,
|
||||
specialization.SpecializationName,
|
||||
specialization.Salary,
|
||||
false,
|
||||
DateTime.UtcNow);
|
||||
|
||||
_specializationStorageContract.UpdElement(updatedSpecialization);
|
||||
}
|
||||
|
||||
public void RestoreSpecialization(string specializationId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(specializationId))
|
||||
throw new ArgumentNullException(nameof(specializationId), "Specialization ID cannot be null or empty");
|
||||
|
||||
if (!Guid.TryParse(specializationId, out _))
|
||||
throw new ValidationException("Invalid specialization ID format");
|
||||
|
||||
logger.LogInformation("Restoring specialization: {SpecializationId}", specializationId);
|
||||
|
||||
var specialization = _specializationStorageContract.GetElementById(specializationId)
|
||||
?? throw new ElementNotFoundException($"Specialization with ID {specializationId} not found");
|
||||
|
||||
if (specialization.IsActual)
|
||||
throw new ValidationException("Specialization is already active");
|
||||
|
||||
var updatedSpecialization = new Specialization(
|
||||
specialization.Id,
|
||||
specialization.SpecializationName,
|
||||
specialization.Salary,
|
||||
true,
|
||||
DateTime.UtcNow);
|
||||
|
||||
_specializationStorageContract.UpdElement(updatedSpecialization);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +1,154 @@
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Enums;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class WorkBusinessLogicContract(IWorkStorageContract _workStorageContract) : IWorkBusinessLogicContract
|
||||
internal class WorkBusinessLogicContract(IWorkStorageContract _workStorageContract, ILogger _logger) : IWorkBusinessLogicContract
|
||||
{
|
||||
private IWorkStorageContract workStorageContract = _workStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
public List<WorkDataModel> GetAllWorks()
|
||||
{
|
||||
return [];
|
||||
_logger.LogInformation("Fetching all works.");
|
||||
|
||||
var works = _workStorageContract.GetList();
|
||||
|
||||
if (works == null)
|
||||
{
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
_logger.LogInformation("Fetched {Count} works.", works.Count);
|
||||
return works;
|
||||
}
|
||||
|
||||
|
||||
public void InsertWork(WorkDataModel work)
|
||||
{
|
||||
_logger.LogInformation("InsertWork: {@work}", work);
|
||||
|
||||
if (work == null)
|
||||
throw new ArgumentNullException(nameof(work));
|
||||
|
||||
if(string.IsNullOrWhiteSpace(work.Description))
|
||||
{
|
||||
throw new ValidationException(nameof(work));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(work.Id, out _))
|
||||
{
|
||||
throw new ValidationException("Invalid work ID format.");
|
||||
}
|
||||
|
||||
var existingWork = _workStorageContract.GetElementById(work.Id);
|
||||
if (existingWork != null)
|
||||
throw new ElementExistsException($"Work", work.Id);
|
||||
|
||||
_workStorageContract.AddElement(work);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void UpdateWork(WorkDataModel work)
|
||||
{
|
||||
_logger.LogInformation("Updating work: {@work}", work);
|
||||
|
||||
if (work == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(work), "Work cannot be null.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(work.Description))
|
||||
{
|
||||
throw new ValidationException("Work description cannot be empty.");
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(work.Id, out _))
|
||||
{
|
||||
throw new ValidationException("Invalid work ID format.");
|
||||
}
|
||||
|
||||
var existingWork = _workStorageContract.GetElementById(work.Id);
|
||||
if (existingWork == null)
|
||||
{
|
||||
throw new ElementNotFoundException($"Work with ID {work.Id} not found.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_workStorageContract.UpdElement(work);
|
||||
_logger.LogInformation("Work successfully updated: {WorkId}", work.Id);
|
||||
}
|
||||
catch (Exception ex) when (!(ex is ElementNotFoundException))
|
||||
{
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void DeleteWork(string workId)
|
||||
{
|
||||
_logger.LogInformation("DeleteWork: {workId}", workId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(workId))
|
||||
throw new ArgumentNullException(nameof(workId));
|
||||
|
||||
if (!Guid.TryParse(workId, out _))
|
||||
throw new ValidationException("Invalid work ID format.");
|
||||
|
||||
var existingWork = _workStorageContract.GetElementById(workId);
|
||||
if (existingWork == null)
|
||||
throw new ElementNotFoundException($"Work with ID {workId} not found.");
|
||||
|
||||
try
|
||||
{
|
||||
_workStorageContract.DelElement(workId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
public WorkDataModel GetWorkByData(DateTime dataFrom, DateTime dataTo)
|
||||
{
|
||||
return new WorkDataModel("", TwoFromTheCasketContracts.Enums.TypeWork.Carpentry, "", DateTime.Now);
|
||||
_logger.LogInformation("Retrieving work data from {DataFrom} to {DataTo}", dataFrom, dataTo);
|
||||
|
||||
if (dataFrom >= dataTo)
|
||||
{
|
||||
throw new IncorrectDatesException(dataFrom, dataTo);
|
||||
}
|
||||
|
||||
var works = _workStorageContract.GetList(dataFrom, dataTo);
|
||||
|
||||
if (works == null)
|
||||
{
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
if (works.Count == 0)
|
||||
{
|
||||
throw new ElementNotFoundException($"No works found in the period from {dataFrom} to {dataTo}.");
|
||||
}
|
||||
|
||||
var latestWork = works.MaxBy(w => w.Date);
|
||||
|
||||
if (latestWork == null)
|
||||
{
|
||||
throw new ElementNotFoundException($"No work found in the given period.");
|
||||
}
|
||||
|
||||
_logger.LogInformation("Found work: {WorkDescription} (ID: {WorkId})", latestWork.Description, latestWork.Id);
|
||||
|
||||
return latestWork;
|
||||
}
|
||||
|
||||
public void InsertWork(WorkDataModel workDataModel)
|
||||
{
|
||||
}
|
||||
|
||||
public void UpdateWork(WorkDataModel workDataModel)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteWork(string id)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,165 @@
|
||||
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorageContract) : IWorkerBusinessLogicContract
|
||||
internal class WorkerBusinessLogicContract(IWorkerStorageContract _workerStorageContract, ILogger _logger) : IWorkerBusinessLogicContract
|
||||
{
|
||||
private IWorkerStorageContract workerStorageContract = _workerStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Retrieving all workers (onlyActive: {onlyActive})", onlyActive);
|
||||
var workers = workerStorageContract.GetList(onlyActive, null, null, null, null, null)
|
||||
?? throw new NullListException();
|
||||
return workers;
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Retrieving workers born between {fromDate} and {toDate}", fromDate, toDate);
|
||||
|
||||
if (fromDate >= toDate)
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
|
||||
var workers = workerStorageContract.GetList(onlyActive, null, fromDate, toDate, null, null)
|
||||
?? throw new NullListException();
|
||||
|
||||
return workers;
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Retrieving workers employed between {fromDate} and {toDate}", fromDate, toDate);
|
||||
|
||||
if (fromDate >= toDate)
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
|
||||
var workers = workerStorageContract.GetList(onlyActive, null, null, null, fromDate, toDate)
|
||||
?? throw new NullListException();
|
||||
|
||||
return workers;
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetWorkersBySpecialization(string specializationId, bool onlyActive = true)
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Retrieving workers by specialization ID: {specializationId}", specializationId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(specializationId))
|
||||
throw new ArgumentNullException(nameof(specializationId));
|
||||
|
||||
if (!Guid.TryParse(specializationId, out _))
|
||||
throw new ValidationException("Specialization ID is not a valid GUID.");
|
||||
|
||||
var workers = workerStorageContract.GetList(onlyActive, specializationId, null, null, null, null)
|
||||
?? throw new NullListException();
|
||||
|
||||
return workers;
|
||||
}
|
||||
|
||||
public WorkerDataModel GetWorkerByData(string data)
|
||||
{
|
||||
return new WorkerDataModel("","","", "", DateTime.Now.AddYears(-20));
|
||||
logger.LogInformation("Retrieving worker by data: {data}", data);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(data))
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
|
||||
WorkerDataModel? worker;
|
||||
if (Guid.TryParse(data, out _))
|
||||
{
|
||||
worker = workerStorageContract.GetElementById(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
worker = workerStorageContract.GetElementByFIO(data);
|
||||
}
|
||||
|
||||
return worker ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
if (workerDataModel == null)
|
||||
throw new ArgumentNullException(nameof(workerDataModel));
|
||||
|
||||
logger.LogInformation("Inserting new worker: {workerId}", workerDataModel.Id);
|
||||
|
||||
if (!Guid.TryParse(workerDataModel.Id, out _))
|
||||
throw new ValidationException("Worker ID is not a valid GUID.");
|
||||
|
||||
try
|
||||
{
|
||||
workerStorageContract.AddElement(workerDataModel);
|
||||
logger.LogDebug("Worker {workerId} successfully inserted.", workerDataModel.Id);
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
logger.LogError(ex, "Worker with ID {workerId} already exists.", workerDataModel.Id);
|
||||
throw;
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
logger.LogError(ex, "Storage error occurred while inserting worker {workerId}.", workerDataModel.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
if (workerDataModel == null)
|
||||
throw new ArgumentNullException(nameof(workerDataModel));
|
||||
|
||||
logger.LogInformation("Updating worker: {workerId}", workerDataModel.Id);
|
||||
|
||||
if (!Guid.TryParse(workerDataModel.Id, out _))
|
||||
throw new ValidationException("Worker ID is not a valid GUID.");
|
||||
|
||||
try
|
||||
{
|
||||
workerStorageContract.UpdElement(workerDataModel);
|
||||
logger.LogDebug("Worker {workerId} successfully updated.", workerDataModel.Id);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
logger.LogError(ex, "Worker with ID {workerId} not found.", workerDataModel.Id);
|
||||
throw;
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
logger.LogError(ex, "Storage error occurred while updating worker {workerId}.", workerDataModel.Id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteWorker(string id)
|
||||
{
|
||||
logger.LogInformation("Deleting worker: {workerId}", id);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(id))
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
|
||||
if (!Guid.TryParse(id, out _))
|
||||
throw new ValidationException("Worker ID is not a valid GUID.");
|
||||
|
||||
try
|
||||
{
|
||||
workerStorageContract.DelElement(id);
|
||||
logger.LogDebug("Worker {workerId} successfully deleted.", id);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
logger.LogError(ex, "Worker with ID {workerId} not found.", id);
|
||||
throw;
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
logger.LogError(ex, "Storage error occurred while deleting worker {workerId}.", id);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,149 @@
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TwoFromTheCasketContracts.BusinessLogicsContracts;
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
|
||||
namespace TwoFromTheCasketBusinessLogic.Implementation;
|
||||
|
||||
internal class WorkerComplitedWorkBusinessLogicContract(IWorkerComplitedWorkStorageContract _complitedWorkStorageContract) : IWorkerComplitedWorkBusinessLogicContract
|
||||
internal class WorkerComplitedWorkBusinessLogicContract(IWorkerComplitedWorkStorageContract _complitedWorkStorageContract,
|
||||
ILogger _logger) : IWorkerComplitedWorkBusinessLogicContract
|
||||
{
|
||||
private IWorkerComplitedWorkStorageContract complitedWorkStorageContract = _complitedWorkStorageContract;
|
||||
private ILogger logger = _logger;
|
||||
|
||||
public List<WorkerComplitedWorkDataModel> GetWorkerComplitedWorksByWorker(string workerId)
|
||||
public List<WorkerComplitedWorkDataModel> GetAllWorkerComplitedWorks()
|
||||
{
|
||||
return [];
|
||||
logger.LogInformation("Fetching all worker completed works.");
|
||||
|
||||
var result = complitedWorkStorageContract.GetList();
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("No worker completed works found.");
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetched {Count} worker completed works.", result.Count);
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<WorkerComplitedWorkDataModel> GetWorkerComplitedWorksByWork(string workId)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
logger.LogInformation("Fetching worker completed works by workId: {workId}", workId);
|
||||
|
||||
public void InsertWorkerComplitedWork(WorkerComplitedWorkDataModel workerComplitedWorkDataModel)
|
||||
if (string.IsNullOrWhiteSpace(workId))
|
||||
{
|
||||
logger.LogError("Work ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(workId));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(workId, out _))
|
||||
{
|
||||
logger.LogError("Invalid work ID format: {workId}", workId);
|
||||
throw new ValidationException("Invalid work ID format.");
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(complitedWorkId: workId);
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("No completed works found for work ID: {workId}", workId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetched {Count} worker completed works for workId: {workId}", result.Count, workId);
|
||||
return result;
|
||||
}
|
||||
public List<WorkerComplitedWorkDataModel> GetWorkerComplitedWorksByWorker(string workerId)
|
||||
{
|
||||
logger.LogInformation("Fetching worker completed works by workerId: {workerId}", workerId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(workerId))
|
||||
{
|
||||
logger.LogError("Worker ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(workerId, out _))
|
||||
{
|
||||
logger.LogError("Invalid worker ID format: {workerId}", workerId);
|
||||
throw new ValidationException("Invalid worker ID format.");
|
||||
}
|
||||
|
||||
var result = complitedWorkStorageContract.GetList(workerId: workerId);
|
||||
if (result is null)
|
||||
{
|
||||
logger.LogError("No completed works found for worker ID: {workerId}", workerId);
|
||||
throw new NullListException();
|
||||
}
|
||||
|
||||
logger.LogInformation("Fetched {Count} worker completed works for workerId: {workerId}", result.Count, workerId);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void UpdateWorkerComplitedWork(WorkerComplitedWorkDataModel workerComplitedWorkDataModel)
|
||||
public void InsertWorkerComplitedWork(WorkerComplitedWorkDataModel workerComplitedWork)
|
||||
{
|
||||
logger.LogInformation("Inserting new worker completed work: {workerComplitedWork}", workerComplitedWork);
|
||||
|
||||
if (workerComplitedWork is null)
|
||||
{
|
||||
logger.LogError("Worker completed work data is null.");
|
||||
throw new ArgumentNullException(nameof(workerComplitedWork));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(workerComplitedWork.WorkerId, out _))
|
||||
throw new ValidationException("Invalid worker ID format.");
|
||||
|
||||
if (!Guid.TryParse(workerComplitedWork.ComplitedWorkId, out _))
|
||||
throw new ValidationException("Invalid completed work ID format.");
|
||||
|
||||
if (workerComplitedWork.NumberOfWorkingHours <= 0)
|
||||
throw new ValidationException("Number of working hours must be greater than zero.");
|
||||
|
||||
complitedWorkStorageContract.AddElement(workerComplitedWork);
|
||||
_logger.LogInformation("Worker completed work inserted successfully: {workerComplitedWork}", workerComplitedWork);
|
||||
}
|
||||
|
||||
public void DeleteWorkerComplitedWork(string id)
|
||||
public void UpdateWorkerComplitedWork(WorkerComplitedWorkDataModel workerComplitedWork)
|
||||
{
|
||||
logger.LogInformation("Updating worker completed work: {workerComplitedWork}", workerComplitedWork);
|
||||
|
||||
if (workerComplitedWork is null)
|
||||
{
|
||||
logger.LogError("Worker completed work data is null.");
|
||||
throw new ArgumentNullException(nameof(workerComplitedWork));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(workerComplitedWork.WorkerId, out _))
|
||||
throw new ValidationException("Invalid worker ID format.");
|
||||
|
||||
if (!Guid.TryParse(workerComplitedWork.ComplitedWorkId, out _))
|
||||
throw new ValidationException("Invalid completed work ID format.");
|
||||
|
||||
if (workerComplitedWork.NumberOfWorkingHours <= 0)
|
||||
throw new ValidationException("Number of working hours must be greater than zero.");
|
||||
|
||||
complitedWorkStorageContract.UpdElement(workerComplitedWork);
|
||||
logger.LogInformation("Worker completed work updated successfully: {workerComplitedWork}", workerComplitedWork);
|
||||
}
|
||||
|
||||
public void DeleteWorkerComplitedWork(string workerComplitedWorkId)
|
||||
{
|
||||
logger.LogInformation("Deleting worker completed work: {workerComplitedWorkId}", workerComplitedWorkId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(workerComplitedWorkId))
|
||||
{
|
||||
logger.LogError("Worker completed work ID is null or empty.");
|
||||
throw new ArgumentNullException(nameof(workerComplitedWorkId));
|
||||
}
|
||||
|
||||
if (!Guid.TryParse(workerComplitedWorkId, out _))
|
||||
{
|
||||
logger.LogError("Invalid worker completed work ID format: {workerComplitedWorkId}", workerComplitedWorkId);
|
||||
throw new ValidationException("Invalid worker completed work ID format.");
|
||||
}
|
||||
|
||||
complitedWorkStorageContract.DelElement(workerComplitedWorkId);
|
||||
logger.LogInformation("Worker completed work deleted successfully: {workerComplitedWorkId}", workerComplitedWorkId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,4 +12,8 @@
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -4,11 +4,10 @@ using TwoFromTheCasketContracts.Infastructure;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class Specialization(string id, string specializationId, string specializationName, double salary,
|
||||
public class Specialization(string id, string specializationName, double salary,
|
||||
bool isActual, DateTime changeDate) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string SpecializationId { get; private set; } = specializationId;
|
||||
public string SpecializationName { get; private set; } = specializationName;
|
||||
public double Salary { get; private set; } = salary;
|
||||
public bool IsActual { get; private set; } = isActual;
|
||||
@@ -19,10 +18,6 @@ public class Specialization(string id, string specializationId, string specializ
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (SpecializationId.IsEmpty())
|
||||
throw new ValidationException("Field SpecializationId is empty");
|
||||
if (!SpecializationId.IsGuid())
|
||||
throw new ValidationException("The value in the field SpecializationId is not a unique identifier");
|
||||
if (SpecializationName.IsEmpty())
|
||||
throw new ValidationException("Field SpecializationName is empty");
|
||||
if (Salary <= 0)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace TwoFromTheCasketContracts.StorageContracts;
|
||||
public interface IComplitedWorkStorageContract
|
||||
{
|
||||
List<ComplitedWorkDataModel> GetList(DateTime? startTime, DateTime? endTime, string? RoomId, string? WorkId, string? WorkerId);
|
||||
List<ComplitedWorkDataModel> GetList(DateTime? startTime, DateTime? endTime, string? RoomId = null, string? WorkId = null, string? WorkerId = null);
|
||||
ComplitedWorkDataModel? GetElementById(string id);
|
||||
void AddElement(ComplitedWorkDataModel complitedWorkDataModel);
|
||||
void DelElement(string id);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Moq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,7 +20,7 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_complitedWorkStorageMock = new Mock<IComplitedWorkStorageContract>();
|
||||
_complitedWorkBusinessLogicContract = new ComplitedWorkBusinessLogicContract(_complitedWorkStorageMock.Object);
|
||||
_complitedWorkBusinessLogicContract = new ComplitedWorkBusinessLogicContract(_complitedWorkStorageMock.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@@ -28,57 +29,6 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
_complitedWorkStorageMock.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllComplitedWorks_ReturnListOfRecords_Test()
|
||||
{
|
||||
var listOriginal = new List<ComplitedWorkDataModel>
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List<WorkerComplitedWorkDataModel>()),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List<WorkerComplitedWorkDataModel>()),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List<WorkerComplitedWorkDataModel>())
|
||||
};
|
||||
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string?>(), It.IsAny<string?>(), It.IsAny<string?>())).Returns(listOriginal);
|
||||
|
||||
var list = _complitedWorkBusinessLogicContract.GetAllComplitedWorks();
|
||||
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(null, null, null, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllComplitedWorks_ReturnEmptyList_Test()
|
||||
{
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string?>(), It.IsAny<string?>(), It.IsAny<string?>())).Returns(new List<ComplitedWorkDataModel>());
|
||||
|
||||
var list = _complitedWorkBusinessLogicContract.GetAllComplitedWorks();
|
||||
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(null, null, null, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllComplitedWorks_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetAllComplitedWorks(), Throws.TypeOf<NullListException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(null, null, null, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllComplitedWorks_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string?>(), It.IsAny<string?>(), It.IsAny<string?>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetAllComplitedWorks(), Throws.TypeOf<StorageException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(null, null, null, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetComplitedWorksByPeriod_ReturnListOfRecords_Test()
|
||||
{
|
||||
@@ -157,49 +107,57 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
public void GetComplitedWorksByRoomByPeriod_ReturnListOfRecords_Test()
|
||||
{
|
||||
var roomId = Guid.NewGuid().ToString();
|
||||
var fromDate = DateTime.UtcNow.AddDays(-30);
|
||||
var fromDate = DateTime.UtcNow.AddMonths(-1);
|
||||
var toDate = DateTime.UtcNow;
|
||||
|
||||
var listOriginal = new List<ComplitedWorkDataModel>
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), roomId, new List<WorkerComplitedWorkDataModel>()),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), roomId, new List<WorkerComplitedWorkDataModel>())
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), roomId, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), roomId, [])
|
||||
};
|
||||
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, null, roomId, null)).Returns(listOriginal);
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, roomId, null, null)).Returns(listOriginal);
|
||||
|
||||
var list = _complitedWorkBusinessLogicContract.GetComplitedWorksByRoomByPeriod(roomId, fromDate, toDate);
|
||||
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
});
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, null, roomId, null), Times.Once);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, roomId, null, null), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetComplitedWorksByRoomByPeriod_ReturnEmptyList_Test()
|
||||
{
|
||||
var roomId = Guid.NewGuid().ToString();
|
||||
var fromDate = DateTime.UtcNow.AddDays(-30);
|
||||
var fromDate = DateTime.UtcNow.AddMonths(-1);
|
||||
var toDate = DateTime.UtcNow;
|
||||
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, null, roomId, null)).Returns(new List<ComplitedWorkDataModel>());
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, roomId, null, null)).Returns([]);
|
||||
|
||||
var list = _complitedWorkBusinessLogicContract.GetComplitedWorksByRoomByPeriod(roomId, fromDate, toDate);
|
||||
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
});
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, null, roomId, null), Times.Once);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, roomId, null, null), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetComplitedWorksByRoomByPeriod_RoomIdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByRoomByPeriod(null, DateTime.UtcNow.AddDays(-30), DateTime.UtcNow), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByRoomByPeriod(string.Empty, DateTime.UtcNow.AddDays(-30), DateTime.UtcNow), Throws.TypeOf<ArgumentNullException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), null, It.IsAny<string>(), null), Times.Never);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), null, null), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -207,7 +165,7 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
{
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByRoomByPeriod("invalid_id", DateTime.UtcNow.AddDays(-30), DateTime.UtcNow), Throws.TypeOf<ValidationException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), null, It.IsAny<string>(), null), Times.Never);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), null, null), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -219,7 +177,7 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByRoomByPeriod(roomId, date, date), Throws.TypeOf<IncorrectDatesException>());
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByRoomByPeriod(roomId, date, date.AddSeconds(-1)), Throws.TypeOf<IncorrectDatesException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), null, It.IsAny<string>(), null), Times.Never);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), null, null), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -231,7 +189,7 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByRoomByPeriod(roomId, fromDate, toDate), Throws.TypeOf<NullListException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, null, roomId, null), Times.Once);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, roomId, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -241,11 +199,11 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
var fromDate = DateTime.UtcNow.AddDays(-30);
|
||||
var toDate = DateTime.UtcNow;
|
||||
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, null, roomId, null)).Throws(new StorageException(new InvalidOperationException()));
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, roomId, null, null)).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByRoomByPeriod(roomId, fromDate, toDate), Throws.TypeOf<StorageException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, null, roomId, null), Times.Once);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, roomId, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -261,40 +219,45 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
new(Guid.NewGuid().ToString(), workTypeId, Guid.NewGuid().ToString(), new List<WorkerComplitedWorkDataModel>())
|
||||
};
|
||||
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, workTypeId, null, null)).Returns(listOriginal);
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, null, workTypeId, null)).Returns(listOriginal);
|
||||
|
||||
var list = _complitedWorkBusinessLogicContract.GetComplitedWorksByWorkTypeByPeriod(workTypeId, fromDate, toDate);
|
||||
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, workTypeId, null, null), Times.Once);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, null, workTypeId, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetComplitedWorksByWorkTypeByPeriod_ReturnEmptyList_Test()
|
||||
{
|
||||
var workTypeId = Guid.NewGuid().ToString();
|
||||
var workId = Guid.NewGuid().ToString();
|
||||
var fromDate = DateTime.UtcNow.AddDays(-30);
|
||||
var toDate = DateTime.UtcNow;
|
||||
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, workTypeId, null, null)).Returns(new List<ComplitedWorkDataModel>());
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, null, workId, null))
|
||||
.Returns(new List<ComplitedWorkDataModel>());
|
||||
|
||||
var list = _complitedWorkBusinessLogicContract.GetComplitedWorksByWorkTypeByPeriod(workTypeId, fromDate, toDate);
|
||||
var list = _complitedWorkBusinessLogicContract.GetComplitedWorksByWorkTypeByPeriod(workId, fromDate, toDate);
|
||||
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
});
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, workTypeId, null, null), Times.Once);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, null, workId, null), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetComplitedWorksByWorkTypeByPeriod_WorkTypeIdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByWorkTypeByPeriod(null, DateTime.UtcNow.AddDays(-30), DateTime.UtcNow), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByWorkTypeByPeriod(string.Empty, DateTime.UtcNow.AddDays(-30), DateTime.UtcNow), Throws.TypeOf<ArgumentNullException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), null, null), Times.Never);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), null, It.IsAny<string>(), null), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -302,7 +265,7 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
{
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByWorkTypeByPeriod("invalid_id", DateTime.UtcNow.AddDays(-30), DateTime.UtcNow), Throws.TypeOf<ValidationException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), null, null), Times.Never);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), null, It.IsAny<string>(), null), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -314,7 +277,7 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByWorkTypeByPeriod(workTypeId, date, date), Throws.TypeOf<IncorrectDatesException>());
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByWorkTypeByPeriod(workTypeId, date, date.AddSeconds(-1)), Throws.TypeOf<IncorrectDatesException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), null, null), Times.Never);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), null, It.IsAny<string>(), null), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -326,7 +289,7 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByWorkTypeByPeriod(workTypeId, fromDate, toDate), Throws.TypeOf<NullListException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, workTypeId, null, null), Times.Once);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, null, workTypeId, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -336,11 +299,11 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
var fromDate = DateTime.UtcNow.AddDays(-30);
|
||||
var toDate = DateTime.UtcNow;
|
||||
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, workTypeId, null, null)).Throws(new StorageException(new InvalidOperationException()));
|
||||
_complitedWorkStorageMock.Setup(x => x.GetList(fromDate, toDate, null, workTypeId, null)).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.GetComplitedWorksByWorkTypeByPeriod(workTypeId, fromDate, toDate), Throws.TypeOf<StorageException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, workTypeId, null, null), Times.Once);
|
||||
_complitedWorkStorageMock.Verify(x => x.GetList(fromDate, toDate, null, workTypeId, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -505,14 +468,6 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
_complitedWorkStorageMock.Verify(x => x.AddElement(It.IsAny<ComplitedWorkDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertComplitedWork_NullRecord_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _complitedWorkBusinessLogicContract.InsertComplitedWork(null), Throws.TypeOf<ArgumentNullException>());
|
||||
|
||||
_complitedWorkStorageMock.Verify(x => x.AddElement(It.IsAny<ComplitedWorkDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertComplitedWork_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketBusinessLogic.Implementation;
|
||||
using TwoFromTheCasketContracts.Enums;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
{
|
||||
@@ -21,7 +22,7 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
public void Setup()
|
||||
{
|
||||
_roomStorageMock = new Mock<IRoomStorageContract>();
|
||||
_roomBusinessLogic = new RoomBusinessLogicContract(_roomStorageMock.Object);
|
||||
_roomBusinessLogic = new RoomBusinessLogicContract(_roomStorageMock.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -109,10 +110,10 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
[Test]
|
||||
public void GetRoomsByOwner_ReturnsEmptyList()
|
||||
{
|
||||
var ownerId = Guid.NewGuid().ToString();
|
||||
_roomStorageMock.Setup(x => x.GetListByOwner(ownerId)).Returns(new List<RoomDataModel>());
|
||||
var ownerFIO = "John Doe";
|
||||
_roomStorageMock.Setup(x => x.GetListByOwner(ownerFIO)).Returns(new List<RoomDataModel>());
|
||||
|
||||
var result = _roomBusinessLogic.GetRoomsByOwner(ownerId);
|
||||
var result = _roomBusinessLogic.GetRoomsByOwner(ownerFIO);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -120,7 +121,7 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
Assert.That(result, Has.Count.EqualTo(0));
|
||||
});
|
||||
|
||||
_roomStorageMock.Verify(x => x.GetListByOwner(ownerId), Times.Once);
|
||||
_roomStorageMock.Verify(x => x.GetListByOwner(ownerFIO), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -132,18 +133,10 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
_roomStorageMock.Verify(x => x.GetListByOwner(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRoomsByOwner_OwnerIdIsNotGuid_ThrowsValidationException()
|
||||
{
|
||||
Assert.That(() => _roomBusinessLogic.GetRoomsByOwner("invalid-guid"), Throws.TypeOf<ValidationException>());
|
||||
|
||||
_roomStorageMock.Verify(x => x.GetListByOwner(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRoomsByOwner_StorageReturnsNull_ThrowsNullListException()
|
||||
{
|
||||
var ownerId = Guid.NewGuid().ToString();
|
||||
var ownerId = "John Doe";
|
||||
|
||||
Assert.That(() => _roomBusinessLogic.GetRoomsByOwner(ownerId), Throws.TypeOf<NullListException>());
|
||||
|
||||
@@ -153,12 +146,12 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
[Test]
|
||||
public void GetRoomsByOwner_StorageThrowsException_ThrowsStorageException()
|
||||
{
|
||||
var ownerId = Guid.NewGuid().ToString();
|
||||
_roomStorageMock.Setup(x => x.GetListByOwner(ownerId)).Throws(new StorageException(new InvalidOperationException()));
|
||||
var ownerFIO = "John Doe";
|
||||
_roomStorageMock.Setup(x => x.GetListByOwner(ownerFIO)).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _roomBusinessLogic.GetRoomsByOwner(ownerId), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _roomBusinessLogic.GetRoomsByOwner(ownerFIO), Throws.TypeOf<StorageException>());
|
||||
|
||||
_roomStorageMock.Verify(x => x.GetListByOwner(ownerId), Times.Once);
|
||||
_roomStorageMock.Verify(x => x.GetListByOwner(ownerFIO), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -362,13 +355,6 @@ namespace TwoFromTheCasketTests.BusinessLogicsContractsTests
|
||||
_roomStorageMock.Verify(x => x.UpdElement(It.IsAny<RoomDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateRoom_NullRecord_ThrowsArgumentNullException()
|
||||
{
|
||||
Assert.That(() => _roomBusinessLogic.UpdateRoom(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_roomStorageMock.Verify(x => x.UpdElement(It.IsAny<RoomDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateRoom_InvalidRecord_ThrowsValidationException()
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ using TwoFromTheCasketContracts.StorageContracts;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketBusinessLogic.Implementation;
|
||||
using TwoFromTheCasketContracts.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace TwoFromTheCasketTests.BusinessLogicsContractsTests;
|
||||
|
||||
@@ -21,7 +22,7 @@ public class RoomHistoryBusinessLogicContractTests
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_roomHistoryStorageMock = new Mock<IRoomHistoryStorageContract>();
|
||||
_roomHistoryBusinessLogic = new RoomHistoryBusinessLogicContract(_roomHistoryStorageMock.Object);
|
||||
_roomHistoryBusinessLogic = new RoomHistoryBusinessLogicContract(_roomHistoryStorageMock.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Moq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -32,7 +33,8 @@ public class SalaryBusinessLogicContractTests
|
||||
_salaryStorageMock.Object,
|
||||
_workerStorageMock.Object,
|
||||
_complitedWorkStorageMock.Object,
|
||||
_specializationStorageMock.Object);
|
||||
_specializationStorageMock.Object,
|
||||
new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@@ -256,7 +258,7 @@ public class SalaryBusinessLogicContractTests
|
||||
]);
|
||||
|
||||
_specializationStorageMock.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new Specialization(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Specialist", specializationSalary, true, DateTime.UtcNow));
|
||||
.Returns(new Specialization(Guid.NewGuid().ToString(), "Specialist", specializationSalary, true, DateTime.UtcNow));
|
||||
|
||||
_workerStorageMock.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new WorkerDataModel(workerId, "Test Worker", Guid.NewGuid().ToString(), "+7-777-777-77-77", DateTime.UtcNow.AddYears(-30))]);
|
||||
@@ -289,7 +291,7 @@ public class SalaryBusinessLogicContractTests
|
||||
).ToList());
|
||||
|
||||
_specializationStorageMock.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new Specialization(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Specialist", specializationSalary, true, DateTime.UtcNow));
|
||||
.Returns(new Specialization(Guid.NewGuid().ToString(), "Specialist", specializationSalary, true, DateTime.UtcNow));
|
||||
|
||||
_workerStorageMock.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns(workers);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Moq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -22,7 +23,7 @@ public class SpecializationBusinessLogicContractTests
|
||||
public void Setup()
|
||||
{
|
||||
_specializationStorageMock = new Mock<ISpecializationStorageContract>();
|
||||
_specializationBusinessLogic = new SpecializationBusinessLogicContract(_specializationStorageMock.Object);
|
||||
_specializationBusinessLogic = new SpecializationBusinessLogicContract(_specializationStorageMock.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -30,26 +31,23 @@ public class SpecializationBusinessLogicContractTests
|
||||
{
|
||||
var specializations = new List<Specialization>
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Specialization 1", 50000, true, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Specialization 2", 60000, false, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Specialization 3", 55000, true, DateTime.UtcNow)
|
||||
new(Guid.NewGuid().ToString(), "Specialization A", 1000, true, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(), "Specialization B", 2000, true, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(), "Specialization C", 3000, false, DateTime.UtcNow)
|
||||
};
|
||||
|
||||
_specializationStorageMock.Setup(x => x.GetList(It.IsAny<bool>())).Returns(specializations);
|
||||
|
||||
var actualList = _specializationBusinessLogic.GetAllSpecializations(true);
|
||||
var fullList = _specializationBusinessLogic.GetAllSpecializations(false);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(actualList, Is.Not.Null);
|
||||
Assert.That(fullList, Is.Not.Null);
|
||||
Assert.That(actualList, Is.EquivalentTo(specializations));
|
||||
Assert.That(fullList, Is.EquivalentTo(specializations));
|
||||
Assert.That(actualList.Count, Is.EqualTo(specializations.Count(s => s.IsActual)));
|
||||
Assert.That(actualList.All(s => s.IsActual), Is.True, "Not all specializations are active");
|
||||
});
|
||||
|
||||
_specializationStorageMock.Verify(x => x.GetList(true), Times.Once);
|
||||
_specializationStorageMock.Verify(x => x.GetList(false), Times.Once);
|
||||
_specializationStorageMock.Verify(x => x.GetList(It.IsAny<bool>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -93,77 +91,33 @@ public class SpecializationBusinessLogicContractTests
|
||||
_specializationStorageMock.Verify(x => x.GetList(It.IsAny<bool>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLatestSpecializationById_ReturnsLatestRecord_Test()
|
||||
{
|
||||
var specializationId = Guid.NewGuid().ToString();
|
||||
var latestSpecialization = new Specialization(Guid.NewGuid().ToString(), specializationId, "Latest Specialization", 70000, true, DateTime.UtcNow);
|
||||
|
||||
_specializationStorageMock.Setup(x => x.GetElementById(specializationId)).Returns(latestSpecialization);
|
||||
|
||||
var actualSpecialization = _specializationBusinessLogic.GetLatestSpecializationById(specializationId);
|
||||
|
||||
Assert.That(actualSpecialization, Is.Not.Null);
|
||||
Assert.That(actualSpecialization, Is.EqualTo(latestSpecialization));
|
||||
|
||||
_specializationStorageMock.Verify(x => x.GetElementById(specializationId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLatestSpecializationById_SpecializationIdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _specializationBusinessLogic.GetLatestSpecializationById(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _specializationBusinessLogic.GetLatestSpecializationById(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
|
||||
_specializationStorageMock.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLatestSpecializationById_SpecializationIdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _specializationBusinessLogic.GetLatestSpecializationById("invalid-id"), Throws.TypeOf<ValidationException>());
|
||||
|
||||
_specializationStorageMock.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLatestSpecializationById_NotFound_ThrowException_Test()
|
||||
{
|
||||
var specializationId = Guid.NewGuid().ToString();
|
||||
_specializationStorageMock.Setup(x => x.GetElementById(specializationId)).Returns((Specialization)null);
|
||||
|
||||
Assert.That(() => _specializationBusinessLogic.GetLatestSpecializationById(specializationId), Throws.TypeOf<ElementNotFoundException>());
|
||||
|
||||
_specializationStorageMock.Verify(x => x.GetElementById(specializationId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLatestSpecializationById_StorageThrowsException_ThrowException_Test()
|
||||
{
|
||||
var specializationId = Guid.NewGuid().ToString();
|
||||
_specializationStorageMock.Setup(x => x.GetElementById(specializationId)).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _specializationBusinessLogic.GetLatestSpecializationById(specializationId), Throws.TypeOf<StorageException>());
|
||||
|
||||
_specializationStorageMock.Verify(x => x.GetElementById(specializationId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLatestSpecializationByName_ReturnsLatestRecord_Test()
|
||||
{
|
||||
var specializationName = "Software Engineer";
|
||||
var latestSpecialization = new Specialization(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), specializationName, 75000, true, DateTime.UtcNow);
|
||||
var specializationName = "Specialist";
|
||||
var specializations = new List<Specialization>
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), "Specialist", 5000, true, DateTime.UtcNow.AddMonths(-2)),
|
||||
new(Guid.NewGuid().ToString(), "specialist", 6000, true, DateTime.UtcNow.AddMonths(-1)),
|
||||
new(Guid.NewGuid().ToString(), "Specialist", 7000, true, DateTime.UtcNow)
|
||||
};
|
||||
|
||||
_specializationStorageMock.Setup(x => x.GetElementByName(specializationName)).Returns(latestSpecialization);
|
||||
_specializationStorageMock.Setup(x => x.GetList(It.IsAny<bool>())).Returns(specializations);
|
||||
|
||||
var actualSpecialization = _specializationBusinessLogic.GetLatestSpecializationByName(specializationName);
|
||||
var latestSpecialization = _specializationBusinessLogic.GetLatestSpecializationByName(specializationName);
|
||||
|
||||
Assert.That(actualSpecialization, Is.Not.Null);
|
||||
Assert.That(actualSpecialization, Is.EqualTo(latestSpecialization));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(latestSpecialization, Is.Not.Null, "Specialization should not be null.");
|
||||
Assert.That(latestSpecialization.ChangeDate, Is.EqualTo(specializations.Max(s => s.ChangeDate)), "Should return the most recent specialization.");
|
||||
Assert.That(latestSpecialization.SpecializationName, Is.EqualTo(specializationName).IgnoreCase, "Name should match ignoring case.");
|
||||
});
|
||||
|
||||
_specializationStorageMock.Verify(x => x.GetElementByName(specializationName), Times.Once);
|
||||
_specializationStorageMock.Verify(x => x.GetList(It.IsAny<bool>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetLatestSpecializationByName_SpecializationNameIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
@@ -174,37 +128,42 @@ public class SpecializationBusinessLogicContractTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLatestSpecializationByName_NotFound_ThrowException_Test()
|
||||
public void GetLatestSpecializationByName_StorageThrowsException_ThrowException_Test()
|
||||
{
|
||||
var specializationName = "Non-Existent Specialization";
|
||||
_specializationStorageMock.Setup(x => x.GetElementByName(specializationName)).Returns((Specialization)null);
|
||||
var specializationName = "SpecializationName";
|
||||
|
||||
Assert.That(() => _specializationBusinessLogic.GetLatestSpecializationByName(specializationName), Throws.TypeOf<ElementNotFoundException>());
|
||||
_specializationStorageMock.Setup(x => x.GetList(It.IsAny<bool>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
_specializationStorageMock.Verify(x => x.GetElementByName(specializationName), Times.Once);
|
||||
Assert.That(() => _specializationBusinessLogic.GetLatestSpecializationByName(specializationName),
|
||||
Throws.TypeOf<StorageException>());
|
||||
|
||||
_specializationStorageMock.Verify(x => x.GetList(It.IsAny<bool>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetLatestSpecializationByName_StorageThrowsException_ThrowException_Test()
|
||||
public void GetLatestSpecializationByName_NotFound_ThrowException_Test()
|
||||
{
|
||||
var specializationName = "System Administrator";
|
||||
_specializationStorageMock.Setup(x => x.GetElementByName(specializationName)).Throws(new StorageException(new InvalidOperationException()));
|
||||
var specializationName = "NonExistentSpecialization";
|
||||
_specializationStorageMock.Setup(x => x.GetList(It.IsAny<bool>())).Returns(new List<Specialization>());
|
||||
|
||||
Assert.That(() => _specializationBusinessLogic.GetLatestSpecializationByName(specializationName), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _specializationBusinessLogic.GetLatestSpecializationByName(specializationName),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
|
||||
_specializationStorageMock.Verify(x => x.GetElementByName(specializationName), Times.Once);
|
||||
_specializationStorageMock.Verify(x => x.GetList(It.IsAny<bool>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void AddSpecialization_CorrectRecord_Test()
|
||||
{
|
||||
var flag = false;
|
||||
var specialization = new Specialization(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Software Engineer", 75000, true, DateTime.UtcNow);
|
||||
var specialization = new Specialization(Guid.NewGuid().ToString(), "Software Engineer", 75000, true, DateTime.UtcNow);
|
||||
|
||||
_specializationStorageMock.Setup(x => x.AddElement(It.IsAny<Specialization>()))
|
||||
.Callback((Specialization x) =>
|
||||
{
|
||||
flag = x.Id == specialization.Id && x.SpecializationId == specialization.SpecializationId &&
|
||||
flag = x.Id == specialization.Id &&
|
||||
x.SpecializationName == specialization.SpecializationName && x.Salary == specialization.Salary &&
|
||||
x.IsActual == specialization.IsActual && x.ChangeDate == specialization.ChangeDate;
|
||||
});
|
||||
@@ -221,36 +180,19 @@ public class SpecializationBusinessLogicContractTests
|
||||
_specializationStorageMock.Setup(x => x.AddElement(It.IsAny<Specialization>()))
|
||||
.Throws(new ElementExistsException("Specialization", "Specialization"));
|
||||
|
||||
Assert.That(() => _specializationBusinessLogic.AddSpecialization(new Specialization(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Software Engineer", 75000, true, DateTime.UtcNow)),
|
||||
Assert.That(() => _specializationBusinessLogic.AddSpecialization(new Specialization(Guid.NewGuid().ToString(), "Software Engineer", 75000, true, DateTime.UtcNow)),
|
||||
Throws.TypeOf<ElementExistsException>());
|
||||
|
||||
_specializationStorageMock.Verify(x => x.AddElement(It.IsAny<Specialization>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddSpecialization_NullRecord_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _specializationBusinessLogic.AddSpecialization(null), Throws.TypeOf<ArgumentNullException>());
|
||||
|
||||
_specializationStorageMock.Verify(x => x.AddElement(It.IsAny<Specialization>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddSpecialization_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _specializationBusinessLogic.AddSpecialization(new Specialization("id", "", "", -1000, true, DateTime.UtcNow)),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
|
||||
_specializationStorageMock.Verify(x => x.AddElement(It.IsAny<Specialization>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddSpecialization_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
_specializationStorageMock.Setup(x => x.AddElement(It.IsAny<Specialization>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _specializationBusinessLogic.AddSpecialization(new Specialization(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Software Engineer", 75000, true, DateTime.UtcNow)),
|
||||
Assert.That(() => _specializationBusinessLogic.AddSpecialization(new Specialization(Guid.NewGuid().ToString(), "Software Engineer", 75000, true, DateTime.UtcNow)),
|
||||
Throws.TypeOf<StorageException>());
|
||||
|
||||
_specializationStorageMock.Verify(x => x.AddElement(It.IsAny<Specialization>()), Times.Once);
|
||||
@@ -260,7 +202,7 @@ public class SpecializationBusinessLogicContractTests
|
||||
public void DeactivateSpecialization_CorrectRecord_Test()
|
||||
{
|
||||
var flag = false;
|
||||
var specialization = new Specialization(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Software Engineer", 75000, true, DateTime.UtcNow);
|
||||
var specialization = new Specialization(Guid.NewGuid().ToString(), "Software Engineer", 75000, true, DateTime.UtcNow);
|
||||
|
||||
_specializationStorageMock.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(specialization);
|
||||
@@ -327,7 +269,7 @@ public class SpecializationBusinessLogicContractTests
|
||||
public void RestoreSpecialization_CorrectRecord_Test()
|
||||
{
|
||||
var flag = false;
|
||||
var specialization = new Specialization(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Software Engineer", 75000, false, DateTime.UtcNow);
|
||||
var specialization = new Specialization(Guid.NewGuid().ToString(), "Software Engineer", 75000, false, DateTime.UtcNow);
|
||||
|
||||
_specializationStorageMock.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(specialization);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Moq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -22,7 +23,7 @@ internal class WorkBusinessLogicContractTests
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_workStorageMock = new Mock<IWorkStorageContract>();
|
||||
_workBusinessLogicContract = new WorkBusinessLogicContract(_workStorageMock.Object);
|
||||
_workBusinessLogicContract = new WorkBusinessLogicContract(_workStorageMock.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@@ -99,33 +100,75 @@ internal class WorkBusinessLogicContractTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWorkByData_ByDateRange_ReturnList_Test()
|
||||
public void GetWorkByData_ByDateRange_ReturnsLatestWork_Test()
|
||||
{
|
||||
var fromDate = DateTime.UtcNow.AddMonths(-1);
|
||||
var toDate = DateTime.UtcNow;
|
||||
var listOriginal = new List<WorkDataModel>
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), TypeWork.Carpentry, "Description 1", fromDate.AddDays(5)),
|
||||
new(Guid.NewGuid().ToString(), TypeWork.Plumbing, "Description 2", fromDate.AddDays(10)),
|
||||
};
|
||||
var expectedWork = new WorkDataModel(Guid.NewGuid().ToString(), TypeWork.Carpentry, "Latest Work", toDate.AddDays(-2));
|
||||
var works = new List<WorkDataModel>
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), TypeWork.Plumbing, "Older Work", fromDate.AddDays(5)),
|
||||
expectedWork
|
||||
};
|
||||
|
||||
_workStorageMock
|
||||
.Setup(x => x.GetList(fromDate, toDate))
|
||||
.Returns(listOriginal);
|
||||
|
||||
var list = _workBusinessLogicContract.GetWorkByData(fromDate, toDate);
|
||||
.Returns(works);
|
||||
var actualWork = _workBusinessLogicContract.GetWorkByData(fromDate, toDate);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
Assert.That(actualWork, Is.Not.Null);
|
||||
Assert.That(actualWork, Is.EqualTo(expectedWork));
|
||||
});
|
||||
|
||||
_workStorageMock.Verify(x => x.GetList(fromDate, toDate), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetWorkByData_ByDateRange_StorageThrowsError_ThrowException_Test()
|
||||
public void GetWorkByData_IncorrectDateRange_ThrowException_Test()
|
||||
{
|
||||
var fromDate = DateTime.UtcNow;
|
||||
var toDate = DateTime.UtcNow.AddDays(-1);
|
||||
|
||||
Assert.That(() => _workBusinessLogicContract.GetWorkByData(fromDate, toDate), Throws.TypeOf<IncorrectDatesException>());
|
||||
|
||||
_workStorageMock.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWorkByData_StorageReturnsNull_ThrowException_Test()
|
||||
{
|
||||
var fromDate = DateTime.UtcNow.AddMonths(-1);
|
||||
var toDate = DateTime.UtcNow;
|
||||
|
||||
_workStorageMock
|
||||
.Setup(x => x.GetList(fromDate, toDate))
|
||||
.Returns((List<WorkDataModel>)null);
|
||||
|
||||
Assert.That(() => _workBusinessLogicContract.GetWorkByData(fromDate, toDate), Throws.TypeOf<NullListException>());
|
||||
|
||||
_workStorageMock.Verify(x => x.GetList(fromDate, toDate), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWorkByData_NoWorksFound_ThrowException_Test()
|
||||
{
|
||||
var fromDate = DateTime.UtcNow.AddMonths(-1);
|
||||
var toDate = DateTime.UtcNow;
|
||||
|
||||
_workStorageMock
|
||||
.Setup(x => x.GetList(fromDate, toDate))
|
||||
.Returns(new List<WorkDataModel>());
|
||||
|
||||
Assert.That(() => _workBusinessLogicContract.GetWorkByData(fromDate, toDate), Throws.TypeOf<ElementNotFoundException>());
|
||||
|
||||
_workStorageMock.Verify(x => x.GetList(fromDate, toDate), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWorkByData_StorageThrowsError_ThrowException_Test()
|
||||
{
|
||||
var fromDate = DateTime.UtcNow.AddMonths(-1);
|
||||
var toDate = DateTime.UtcNow;
|
||||
@@ -139,6 +182,7 @@ internal class WorkBusinessLogicContractTests
|
||||
_workStorageMock.Verify(x => x.GetList(fromDate, toDate), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void GetAllWorks_ByDateRange_FromDateGreaterThanToDate_ThrowException_Test()
|
||||
{
|
||||
@@ -209,16 +253,6 @@ internal class WorkBusinessLogicContractTests
|
||||
_workStorageMock.Verify(x => x.AddElement(It.IsAny<WorkDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWork_EndDateInFuture_ThrowException_Test()
|
||||
{
|
||||
var work = new WorkDataModel(Guid.NewGuid().ToString(), TypeWork.Carpentry, "Future job", DateTime.UtcNow.AddDays(10));
|
||||
|
||||
Assert.That(() => _workBusinessLogicContract.InsertWork(work), Throws.TypeOf<ValidationException>());
|
||||
|
||||
_workStorageMock.Verify(x => x.AddElement(It.IsAny<WorkDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWork_StorageThrowsError_ThrowException_Test()
|
||||
{
|
||||
@@ -235,21 +269,21 @@ internal class WorkBusinessLogicContractTests
|
||||
[Test]
|
||||
public void UpdateWork_CorrectRecord_Test()
|
||||
{
|
||||
var flag = false;
|
||||
var work = new WorkDataModel(Guid.NewGuid().ToString(), TypeWork.Carpentry, "Updated description", DateTime.UtcNow);
|
||||
var workId = Guid.NewGuid().ToString();
|
||||
var existingWork = new WorkDataModel(workId, TypeWork.Carpentry, "Old Description", DateTime.UtcNow.AddDays(-10));
|
||||
var updatedWork = new WorkDataModel(workId, TypeWork.Carpentry, "Updated Description", DateTime.UtcNow.AddDays(-5));
|
||||
|
||||
_workStorageMock.Setup(x => x.UpdElement(It.IsAny<WorkDataModel>()))
|
||||
.Callback((WorkDataModel x) =>
|
||||
{
|
||||
flag = x.Id == work.Id && x.Type == work.Type && x.Description == work.Description && x.Date == work.Date;
|
||||
});
|
||||
_workStorageMock
|
||||
.Setup(x => x.GetElementById(workId))
|
||||
.Returns(existingWork);
|
||||
|
||||
_workBusinessLogicContract.UpdateWork(work);
|
||||
_workBusinessLogicContract.UpdateWork(updatedWork);
|
||||
|
||||
_workStorageMock.Verify(x => x.UpdElement(It.IsAny<WorkDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
_workStorageMock.Verify(x => x.GetElementById(workId), Times.Once);
|
||||
_workStorageMock.Verify(x => x.UpdElement(updatedWork), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void UpdateWork_RecordWithIncorrectId_ThrowException_Test()
|
||||
{
|
||||
@@ -260,7 +294,7 @@ internal class WorkBusinessLogicContractTests
|
||||
|
||||
Assert.That(() => _workBusinessLogicContract.UpdateWork(work), Throws.TypeOf<ElementNotFoundException>());
|
||||
|
||||
_workStorageMock.Verify(x => x.UpdElement(It.IsAny<WorkDataModel>()), Times.Once);
|
||||
_workStorageMock.Verify(x => x.UpdElement(It.IsAny<WorkDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -291,57 +325,56 @@ internal class WorkBusinessLogicContractTests
|
||||
_workStorageMock.Verify(x => x.UpdElement(It.IsAny<WorkDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWork_EndDateInFuture_ThrowException_Test()
|
||||
{
|
||||
var work = new WorkDataModel(Guid.NewGuid().ToString(), TypeWork.Carpentry, "Future update", DateTime.UtcNow.AddDays(10));
|
||||
|
||||
Assert.That(() => _workBusinessLogicContract.UpdateWork(work), Throws.TypeOf<ValidationException>());
|
||||
|
||||
_workStorageMock.Verify(x => x.UpdElement(It.IsAny<WorkDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWork_StorageThrowsError_ThrowException_Test()
|
||||
{
|
||||
var work = new WorkDataModel(Guid.NewGuid().ToString(), TypeWork.Carpentry, "Storage error simulation", DateTime.UtcNow);
|
||||
var workId = Guid.NewGuid().ToString();
|
||||
var existingWork = new WorkDataModel(workId, TypeWork.Carpentry, "Existing Description", DateTime.UtcNow.AddDays(-10));
|
||||
var updatedWork = new WorkDataModel(workId, TypeWork.Carpentry, "Updated Description", DateTime.UtcNow.AddDays(-5));
|
||||
|
||||
_workStorageMock.Setup(x => x.UpdElement(It.IsAny<WorkDataModel>()))
|
||||
_workStorageMock
|
||||
.Setup(x => x.GetElementById(workId))
|
||||
.Returns(existingWork);
|
||||
|
||||
_workStorageMock
|
||||
.Setup(x => x.UpdElement(updatedWork))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _workBusinessLogicContract.UpdateWork(work), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _workBusinessLogicContract.UpdateWork(updatedWork), Throws.TypeOf<StorageException>());
|
||||
|
||||
_workStorageMock.Verify(x => x.UpdElement(It.IsAny<WorkDataModel>()), Times.Once);
|
||||
_workStorageMock.Verify(x => x.GetElementById(workId), Times.Once);
|
||||
_workStorageMock.Verify(x => x.UpdElement(updatedWork), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void DeleteWork_CorrectRecord_Test()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
var workId = Guid.NewGuid().ToString();
|
||||
var work = new WorkDataModel(workId, TypeWork.Electrical, "Fixing the roof", DateTime.UtcNow);
|
||||
|
||||
_workStorageMock.Setup(x => x.DelElement(It.Is<string>(x => x == id)))
|
||||
.Callback(() => { flag = true; });
|
||||
_workStorageMock.Setup(x => x.GetElementById(workId)).Returns(work);
|
||||
|
||||
_workBusinessLogicContract.DeleteWork(id);
|
||||
_workBusinessLogicContract.DeleteWork(workId);
|
||||
|
||||
_workStorageMock.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
_workStorageMock.Verify(x => x.GetElementById(workId), Times.Once);
|
||||
_workStorageMock.Verify(x => x.DelElement(workId), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void DeleteWork_RecordWithIncorrectId_ThrowException_Test()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var incorrectWorkId = Guid.NewGuid().ToString();
|
||||
|
||||
_workStorageMock.Setup(x => x.DelElement(It.Is<string>(x => x != id)))
|
||||
.Throws(new ElementNotFoundException(id));
|
||||
_workStorageMock.Setup(x => x.GetElementById(incorrectWorkId)).Returns((WorkDataModel)null);
|
||||
|
||||
Assert.That(() => _workBusinessLogicContract.DeleteWork(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
Assert.That(() => _workBusinessLogicContract.DeleteWork(incorrectWorkId), Throws.TypeOf<ElementNotFoundException>());
|
||||
|
||||
_workStorageMock.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
_workStorageMock.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void DeleteWork_IdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
@@ -362,11 +395,15 @@ internal class WorkBusinessLogicContractTests
|
||||
[Test]
|
||||
public void DeleteWork_StorageThrowsError_ThrowException_Test()
|
||||
{
|
||||
_workStorageMock.Setup(x => x.DelElement(It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
var workId = Guid.NewGuid().ToString();
|
||||
var workData = new WorkDataModel(workId, TypeWork.Electrical, "Test Work", DateTime.UtcNow.AddDays(-10));
|
||||
|
||||
Assert.That(() => _workBusinessLogicContract.DeleteWork(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_workStorageMock.Setup(x => x.GetElementById(workId)).Returns(workData);
|
||||
_workStorageMock.Setup(x => x.DelElement(workId)).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
_workStorageMock.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
Assert.That(() => _workBusinessLogicContract.DeleteWork(workId), Throws.TypeOf<StorageException>());
|
||||
|
||||
_workStorageMock.Verify(x => x.DelElement(workId), Times.Once);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using Moq;
|
||||
using TwoFromTheCasketContracts.StorageContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace TwoFromTheCasketTests.BusinessLogicsContractsTests;
|
||||
|
||||
@@ -17,7 +18,7 @@ internal class WorkerBusinessLogicContractTests
|
||||
{
|
||||
_workerStorageContract = new Mock<IWorkerStorageContract>();
|
||||
_workerBusinessLogicContract = new WorkerBusinessLogicContract(
|
||||
_workerStorageContract.Object
|
||||
_workerStorageContract.Object, new Mock<ILogger>().Object
|
||||
);
|
||||
}
|
||||
|
||||
@@ -408,7 +409,7 @@ internal class WorkerBusinessLogicContractTests
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.FIO, Is.EqualTo(fio));
|
||||
|
||||
_workerStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
_workerStorageContract.Verify(x => x.GetElementByFIO(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Moq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -21,7 +22,7 @@ public class WorkerComplitedWorkBusinessLogicContractTests
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_workerComplitedWorkStorageMock = new Mock<IWorkerComplitedWorkStorageContract>();
|
||||
_workerComplitedWorkBusinessLogicContract = new WorkerComplitedWorkBusinessLogicContract(_workerComplitedWorkStorageMock.Object);
|
||||
_workerComplitedWorkBusinessLogicContract = new WorkerComplitedWorkBusinessLogicContract(_workerComplitedWorkStorageMock.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
|
||||
@@ -9,48 +9,32 @@ internal class SpecializationDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var specialization = CreateDataModel(null, Guid.NewGuid().ToString(), "Engineer", 60000, true, DateTime.UtcNow);
|
||||
var specialization = CreateDataModel(null, "Engineer", 60000, true, DateTime.UtcNow);
|
||||
Assert.That(() => specialization.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
specialization = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "Engineer", 60000, true, DateTime.UtcNow);
|
||||
specialization = CreateDataModel(string.Empty, "Engineer", 60000, true, DateTime.UtcNow);
|
||||
Assert.That(() => specialization.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var specialization = CreateDataModel("not-a-guid", Guid.NewGuid().ToString(), "Engineer", 60000, true, DateTime.UtcNow);
|
||||
var specialization = CreateDataModel("not-a-guid", "Engineer", 60000, true, DateTime.UtcNow);
|
||||
Assert.That(() => specialization.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpecializationIdIsNullOrEmptyTest()
|
||||
{
|
||||
var specialization = CreateDataModel(Guid.NewGuid().ToString(), null, "Engineer", 60000, true, DateTime.UtcNow);
|
||||
Assert.That(() => specialization.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
specialization = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "Engineer", 60000, true, DateTime.UtcNow);
|
||||
Assert.That(() => specialization.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpecializationIdIsNotGuidTest()
|
||||
{
|
||||
var specialization = CreateDataModel(Guid.NewGuid().ToString(), "not-a-guid", "Engineer", 60000, true, DateTime.UtcNow);
|
||||
Assert.That(() => specialization.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SpecializationNameIsEmptyTest()
|
||||
{
|
||||
var specialization = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, 60000, true, DateTime.UtcNow);
|
||||
var specialization = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 60000, true, DateTime.UtcNow);
|
||||
Assert.That(() => specialization.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SalaryIsNegativeOrZeroTest()
|
||||
{
|
||||
var specialization = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Engineer", 0, true, DateTime.UtcNow);
|
||||
var specialization = CreateDataModel(Guid.NewGuid().ToString(), "Engineer", 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => specialization.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -64,13 +48,12 @@ internal class SpecializationDataModelTests
|
||||
var isActual = true;
|
||||
var changeDate = DateTime.UtcNow;
|
||||
|
||||
var specialization = CreateDataModel(id, specializationId, specializationName, salary, isActual, changeDate);
|
||||
var specialization = CreateDataModel(id, specializationName, salary, isActual, changeDate);
|
||||
Assert.That(() => specialization.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(specialization.Id, Is.EqualTo(id));
|
||||
Assert.That(specialization.SpecializationId, Is.EqualTo(specializationId));
|
||||
Assert.That(specialization.SpecializationName, Is.EqualTo(specializationName));
|
||||
Assert.That(specialization.Salary, Is.EqualTo(salary));
|
||||
Assert.That(specialization.IsActual, Is.EqualTo(isActual));
|
||||
@@ -78,6 +61,6 @@ internal class SpecializationDataModelTests
|
||||
});
|
||||
}
|
||||
|
||||
private static Specialization CreateDataModel(string? id, string? specializationId, string specializationName, double salary, bool isActual, DateTime changeDate)
|
||||
=> new(id, specializationId, specializationName, salary, isActual, changeDate);
|
||||
private static Specialization CreateDataModel(string? id, string specializationName, double salary, bool isActual, DateTime changeDate)
|
||||
=> new(id, specializationName, salary, isActual, changeDate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user