Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
861dea9dbf | ||
|
1ebb95b7b1 |
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.9.34701.34
|
VisualStudioVersion = 17.9.34701.34
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectricalRepairServiceContract", "ElectricalRepairServiceContract\ElectricalRepairServiceContract.csproj", "{2D09B01A-09E9-4538-83F9-C26AB93A9D63}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectricalRepairServiceContract", "ElectricalRepairServiceContract\ElectricalRepairServiceContract.csproj", "{2D09B01A-09E9-4538-83F9-C26AB93A9D63}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectricalRepairServiceTests", "ElectricalRepairServiceTests\ElectricalRepairServiceTests.csproj", "{37C14277-69C3-4C2F-8D51-B594A5D4183F}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -15,6 +17,10 @@ Global
|
|||||||
{2D09B01A-09E9-4538-83F9-C26AB93A9D63}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{2D09B01A-09E9-4538-83F9-C26AB93A9D63}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2D09B01A-09E9-4538-83F9-C26AB93A9D63}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{2D09B01A-09E9-4538-83F9-C26AB93A9D63}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{2D09B01A-09E9-4538-83F9-C26AB93A9D63}.Release|Any CPU.Build.0 = Release|Any CPU
|
{2D09B01A-09E9-4538-83F9-C26AB93A9D63}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{37C14277-69C3-4C2F-8D51-B594A5D4183F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{37C14277-69C3-4C2F-8D51-B594A5D4183F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{37C14277-69C3-4C2F-8D51-B594A5D4183F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{37C14277-69C3-4C2F-8D51-B594A5D4183F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
namespace ElectricalRepairServiceContract
|
|
||||||
{
|
|
||||||
public class Class1
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,35 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using ElectricalRepairServiceContract.Extensions;
|
||||||
|
using ElectricalRepairServiceContract.Interfaces;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.DataModels
|
||||||
|
{
|
||||||
|
public class ClientDataModel : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; }
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public string Email { get; private set; }
|
||||||
|
|
||||||
|
public ClientDataModel(string id, string name, string email)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Name = name;
|
||||||
|
Email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field DetailsId is empty");
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field DetailsId is not a unique identifier");
|
||||||
|
if (Name.IsEmpty())
|
||||||
|
throw new ValidationException("Field Description is empty");
|
||||||
|
if (Email.IsEmpty())
|
||||||
|
throw new ValidationException("Field Cost is empty");
|
||||||
|
if (!Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$"))
|
||||||
|
throw new ValidationException("Field Cost is not a valid email address");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using ElectricalRepairServiceContract.Extensions;
|
||||||
|
using ElectricalRepairServiceContract.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.DataModels
|
||||||
|
{
|
||||||
|
public class DetailsDataModel : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; }
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public int Count { get; private set; }
|
||||||
|
public int OldCount { get; private set; }
|
||||||
|
|
||||||
|
public DateTime UpdateDate { get; private set; }
|
||||||
|
|
||||||
|
public DetailsDataModel(string id, string name, int count, int oldCount, DateTime updateDate)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Name = name;
|
||||||
|
Count = count;
|
||||||
|
OldCount = oldCount;
|
||||||
|
UpdateDate = updateDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
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 (Name.IsEmpty())
|
||||||
|
throw new ValidationException("Field Description is empty");
|
||||||
|
if (Count < 0)
|
||||||
|
throw new ValidationException("The count must be positive");
|
||||||
|
if (OldCount < 0)
|
||||||
|
throw new ValidationException("The count must be positive");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using ElectricalRepairServiceContract.Extensions;
|
||||||
|
using ElectricalRepairServiceContract.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.DataModels
|
||||||
|
{
|
||||||
|
public class DetailsUseDataModel : IValidation
|
||||||
|
{
|
||||||
|
public string DetailsId { get; private set; }
|
||||||
|
public string RequestId { get; private set; }
|
||||||
|
public int Count { get; private set; }
|
||||||
|
|
||||||
|
public DetailsUseDataModel(string detailsId, string requestId, int count)
|
||||||
|
{
|
||||||
|
DetailsId = detailsId;
|
||||||
|
RequestId = requestId;
|
||||||
|
Count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (DetailsId.IsEmpty())
|
||||||
|
throw new ValidationException("Field DetailsId is empty");
|
||||||
|
if (!DetailsId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field DetailsId is not a unique identifier");
|
||||||
|
if (RequestId.IsEmpty())
|
||||||
|
throw new ValidationException("Field RequestId is empty");
|
||||||
|
if (!RequestId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field RequestId is not a unique identifier");
|
||||||
|
if (Count <= 0)
|
||||||
|
throw new ValidationException("The count must be positive");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using ElectricalRepairServiceContract.Extensions;
|
||||||
|
using ElectricalRepairServiceContract.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.DataModels
|
||||||
|
{
|
||||||
|
public class EmploeeDataModel : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; }
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public string PostId { get; private set; }
|
||||||
|
|
||||||
|
public EmploeeDataModel(string id, string name, string postId)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Name = name;
|
||||||
|
PostId = postId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
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 (Name.IsEmpty())
|
||||||
|
throw new ValidationException("Field Name is empty");
|
||||||
|
if (PostId.IsEmpty())
|
||||||
|
throw new ValidationException("Field PostId is empty");
|
||||||
|
if (!PostId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
using ElectricalRepairServiceContract.Enums;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using ElectricalRepairServiceContract.Extensions;
|
||||||
|
using ElectricalRepairServiceContract.Interfaces;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.DataModels
|
||||||
|
{
|
||||||
|
public class PostDataModel : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; }
|
||||||
|
public PostType PostType { get; private set; }
|
||||||
|
|
||||||
|
public string Description { get; private set; }
|
||||||
|
|
||||||
|
public bool IsActual { get; private set; }
|
||||||
|
public DateTime ChangeDate { get; private set; }
|
||||||
|
|
||||||
|
public PostDataModel(string id, PostType name, bool isActual, DateTime changeDate, string description)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
PostType = name;
|
||||||
|
IsActual = isActual;
|
||||||
|
ChangeDate = changeDate;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
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 (Description.IsEmpty())
|
||||||
|
throw new ValidationException("Field Description is empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
using ElectricalRepairServiceContract.Enums;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using ElectricalRepairServiceContract.Extensions;
|
||||||
|
using ElectricalRepairServiceContract.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.DataModels
|
||||||
|
{
|
||||||
|
public class RequestDataModel : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; }
|
||||||
|
public string Description { get; private set; }
|
||||||
|
public int Cost { get; private set; }
|
||||||
|
public DateTime DateComplete { get; private set; }
|
||||||
|
public RequestType RequestType { get; private set; }
|
||||||
|
public string EmploeeId { get; private set; }
|
||||||
|
public string? ClientId { get; private set; }
|
||||||
|
public List<DetailsUseDataModel>? DetailsUse { get; private set; }
|
||||||
|
|
||||||
|
public RequestDataModel(string id, RequestType requestType, string? description, int cost,
|
||||||
|
DateTime dateComplete, string emploeeId, string? clientId, List<DetailsUseDataModel>? detailsUses)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Description = description;
|
||||||
|
RequestType = requestType;
|
||||||
|
Cost = cost;
|
||||||
|
DateComplete = dateComplete;
|
||||||
|
EmploeeId = emploeeId;
|
||||||
|
ClientId = clientId;
|
||||||
|
DetailsUse = detailsUses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
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 (EmploeeId.IsEmpty())
|
||||||
|
throw new ValidationException("Field EmploeeId is empty");
|
||||||
|
if (!EmploeeId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field EmploeeId is not a unique identifier");
|
||||||
|
|
||||||
|
if (!ClientId?.IsGuid() ?? false)
|
||||||
|
throw new ValidationException("The value in the field ClientId is not a unique identifier");
|
||||||
|
|
||||||
|
if (Description.IsEmpty())
|
||||||
|
throw new ValidationException("Field Description is empty");
|
||||||
|
|
||||||
|
if (DetailsUse?.Count == 0)
|
||||||
|
throw new ValidationException("The request must include detailsUses");
|
||||||
|
if (Cost < 0)
|
||||||
|
throw new ValidationException("The count must be positive");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
using ElectricalRepairServiceContract.Enums;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using ElectricalRepairServiceContract.Extensions;
|
||||||
|
using ElectricalRepairServiceContract.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.DataModels
|
||||||
|
{
|
||||||
|
public class SalaryDataModel : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; }
|
||||||
|
public SalaryType SalaryType { get; private set; }
|
||||||
|
public int Amount { get; private set; }
|
||||||
|
public string EmploeeId { get; private set; }
|
||||||
|
public DateTime Date { get; private set; }
|
||||||
|
|
||||||
|
public SalaryDataModel(string id, string postId, SalaryType type, int amount, DateTime date)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
SalaryType = type;
|
||||||
|
Amount = amount;
|
||||||
|
EmploeeId = postId;
|
||||||
|
Date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
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 (EmploeeId.IsEmpty())
|
||||||
|
throw new ValidationException("Field EmploeeId is empty");
|
||||||
|
if (!EmploeeId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field EmploeeId is not a unique identifier");
|
||||||
|
if (Amount < 0)
|
||||||
|
throw new ValidationException("The amount must be positive");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.Enums
|
||||||
|
{
|
||||||
|
public enum PostType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Manager = 1,
|
||||||
|
Worker = 2,
|
||||||
|
Admin = 3
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.Enums
|
||||||
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum RequestType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Repair = 1,
|
||||||
|
Buy = 4,
|
||||||
|
Refund = 8
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.Enums
|
||||||
|
{
|
||||||
|
public enum SalaryType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Salary = 1,
|
||||||
|
Fine = 2,
|
||||||
|
Bonus = 3
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.Exceptions
|
||||||
|
{
|
||||||
|
public class ValidationException(string message) : Exception(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
namespace ElectricalRepairServiceContract.Extensions;
|
||||||
|
|
||||||
|
public static class StringExtensions
|
||||||
|
{
|
||||||
|
|
||||||
|
public static bool IsEmpty(this string str)
|
||||||
|
{
|
||||||
|
return string.IsNullOrWhiteSpace(str);
|
||||||
|
}
|
||||||
|
public static bool IsGuid(this string str)
|
||||||
|
{
|
||||||
|
return Guid.TryParse(str, out _);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceContract.Interfaces
|
||||||
|
{
|
||||||
|
internal interface IValidation
|
||||||
|
{
|
||||||
|
void Validate();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
using ElectricalRepairServiceContract.DataModels;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceTests.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class ClientDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var client = CreateDataModel(null, "fio", "email");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
client = CreateDataModel(string.Empty, "fio", "email");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuid()
|
||||||
|
{
|
||||||
|
var client = CreateDataModel("id", "fio", "email");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void NameIsNullOrEmptty()
|
||||||
|
{
|
||||||
|
var client = CreateDataModel(Guid.NewGuid().ToString(), null, "email");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "email");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmailIsNUllOrEmpty()
|
||||||
|
{
|
||||||
|
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", null);
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty);
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmailInvalid()
|
||||||
|
{
|
||||||
|
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "null");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsCorrect()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var fio = "fio";
|
||||||
|
var email = "some@gmail.com";
|
||||||
|
var client = CreateDataModel(id, fio, email);
|
||||||
|
Assert.That(client.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(client.Name, Is.EqualTo(fio));
|
||||||
|
Assert.That(client.Email, Is.EqualTo(email));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ClientDataModel CreateDataModel(string id, string name, string email)
|
||||||
|
=> new ClientDataModel(id, name, email);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
using ElectricalRepairServiceContract.DataModels;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceTests.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class DetailsDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var details = CreateDataModel(null, "name", 1, 1, DateTime.Now);
|
||||||
|
Assert.That(() => details.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
details = CreateDataModel(string.Empty, "name", 1, 1, DateTime.Now);
|
||||||
|
Assert.That(() => details.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var details = CreateDataModel("invalid-id", "name", 1, 1, DateTime.Now);
|
||||||
|
Assert.That(() => details.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void NameIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var details = CreateDataModel(Guid.NewGuid().ToString(), null, 1, 1, DateTime.Now);
|
||||||
|
Assert.That(() => details.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
details = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1, 1, DateTime.Now);
|
||||||
|
Assert.That(() => details.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsNegativeTest()
|
||||||
|
{
|
||||||
|
var details = CreateDataModel(Guid.NewGuid().ToString(), "name", -1, 10, DateTime.Now);
|
||||||
|
Assert.That(() => details.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void OldCountIsNegativeTest()
|
||||||
|
{
|
||||||
|
var details = CreateDataModel(Guid.NewGuid().ToString(), "name", 10, -1, DateTime.Now);
|
||||||
|
Assert.That(() => details.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var name = "ValidName";
|
||||||
|
var count = 10;
|
||||||
|
var oldCount = 10;
|
||||||
|
var dateTime = DateTime.Now;
|
||||||
|
|
||||||
|
var details = CreateDataModel(id, name, count, oldCount, dateTime);
|
||||||
|
|
||||||
|
Assert.That(details.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(details.Name, Is.EqualTo(name));
|
||||||
|
Assert.That(details.Count, Is.EqualTo(count));
|
||||||
|
Assert.That(details.OldCount, Is.EqualTo(oldCount));
|
||||||
|
Assert.That(details.UpdateDate, Is.EqualTo(dateTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
private DetailsDataModel CreateDataModel(string id, string name, int count, int oldCount, DateTime dateTime)
|
||||||
|
=> new DetailsDataModel(id, name, count, oldCount, dateTime);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
using ElectricalRepairServiceContract.DataModels;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceTests.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class DetailsUseDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void DetailsIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var detailsUse = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => detailsUse.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
detailsUse = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => detailsUse.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DetailsIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var detailsUse = CreateDataModel("invalid-id", Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => detailsUse.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void RequestIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var detailsUse = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||||
|
Assert.That(() => detailsUse.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
detailsUse = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||||
|
Assert.That(() => detailsUse.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void RequestIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var detailsUse = CreateDataModel(Guid.NewGuid().ToString(), "invalid-id", 1);
|
||||||
|
Assert.That(() => detailsUse.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsZeroOrNegativeTest()
|
||||||
|
{
|
||||||
|
var detailsUse = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
||||||
|
Assert.That(() => detailsUse.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
detailsUse = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => detailsUse.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsCorrectTest()
|
||||||
|
{
|
||||||
|
var detailsId = Guid.NewGuid().ToString();
|
||||||
|
var requestId = Guid.NewGuid().ToString();
|
||||||
|
var count = 10;
|
||||||
|
|
||||||
|
var detailsUse = CreateDataModel(detailsId, requestId, count);
|
||||||
|
|
||||||
|
Assert.That(detailsUse.DetailsId, Is.EqualTo(detailsId));
|
||||||
|
Assert.That(detailsUse.RequestId, Is.EqualTo(requestId));
|
||||||
|
Assert.That(detailsUse.Count, Is.EqualTo(count));
|
||||||
|
}
|
||||||
|
|
||||||
|
private DetailsUseDataModel CreateDataModel(string detailsId, string requestId, int count)
|
||||||
|
=> new DetailsUseDataModel(detailsId, requestId, count);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
using ElectricalRepairServiceContract.DataModels;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceTests.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class EmploeeDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var employee = CreateDataModel(null, "ValidName", Guid.NewGuid().ToString());
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
employee = CreateDataModel(string.Empty, "ValidName", Guid.NewGuid().ToString());
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var employee = CreateDataModel("invalid-id", "ValidName", Guid.NewGuid().ToString());
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void NameIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var employee = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString());
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString());
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var employee = CreateDataModel(Guid.NewGuid().ToString(), "ValidName", null);
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
employee = CreateDataModel(Guid.NewGuid().ToString(), "ValidName", string.Empty);
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var employee = CreateDataModel(Guid.NewGuid().ToString(), "ValidName", "invalid-post-id");
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var name = "ValidName";
|
||||||
|
var postId = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
|
var employee = CreateDataModel(id, name, postId);
|
||||||
|
|
||||||
|
Assert.That(employee.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(employee.Name, Is.EqualTo(name));
|
||||||
|
Assert.That(employee.PostId, Is.EqualTo(postId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private EmploeeDataModel CreateDataModel(string id, string name, string postId)
|
||||||
|
=> new EmploeeDataModel(id, name, postId);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
using ElectricalRepairServiceContract.DataModels;
|
||||||
|
using ElectricalRepairServiceContract.Enums;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceTests.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class PostDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(null, PostType.Manager, true, DateTime.Now, "Valid description");
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
post = CreateDataModel(string.Empty, PostType.Manager, true, DateTime.Now, "Valid description");
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel("invalid-id", PostType.Manager, true, DateTime.Now, "Valid description");
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DescriptionIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), PostType.Manager, true, DateTime.Now, null);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
post = CreateDataModel(Guid.NewGuid().ToString(), PostType.Manager, true, DateTime.Now, string.Empty);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var postType = PostType.Manager;
|
||||||
|
var isActual = true;
|
||||||
|
var changeDate = DateTime.Now;
|
||||||
|
var description = "Responsible for managing the team";
|
||||||
|
|
||||||
|
var post = CreateDataModel(id, postType, isActual, changeDate, description);
|
||||||
|
|
||||||
|
Assert.That(post.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(post.PostType, Is.EqualTo(postType));
|
||||||
|
Assert.That(post.IsActual, Is.EqualTo(isActual));
|
||||||
|
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
|
||||||
|
Assert.That(post.Description, Is.EqualTo(description));
|
||||||
|
}
|
||||||
|
|
||||||
|
private PostDataModel CreateDataModel(string id, PostType postType, bool isActual, DateTime changeDate, string description)
|
||||||
|
=> new PostDataModel(id, postType, isActual, changeDate, description);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
using ElectricalRepairServiceContract.DataModels;
|
||||||
|
using ElectricalRepairServiceContract.Enums;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceTests.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class RequestDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var request = CreateDataModel(null, RequestType.Repair, "Description", 1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List<DetailsUseDataModel>());
|
||||||
|
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
request = CreateDataModel(string.Empty, RequestType.Repair, "Description", 1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List<DetailsUseDataModel>());
|
||||||
|
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var request = CreateDataModel("invalid-id", RequestType.Repair, "Description", 1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List<DetailsUseDataModel>());
|
||||||
|
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmploeeIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", 1000, DateTime.Now, null, Guid.NewGuid().ToString(), new List<DetailsUseDataModel>());
|
||||||
|
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", 1000, DateTime.Now, string.Empty, Guid.NewGuid().ToString(), new List<DetailsUseDataModel>());
|
||||||
|
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmploeeIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", 1000, DateTime.Now, "invalid-id", Guid.NewGuid().ToString(), new List<DetailsUseDataModel>());
|
||||||
|
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ClientIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", 1000, DateTime.Now, Guid.NewGuid().ToString(), "invalid-client-id", new List<DetailsUseDataModel>());
|
||||||
|
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CostIsNegativeTest()
|
||||||
|
{
|
||||||
|
var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", -1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List<DetailsUseDataModel>());
|
||||||
|
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DescriptionIsEmptyTest()
|
||||||
|
{
|
||||||
|
var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, string.Empty, 1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List<DetailsUseDataModel>());
|
||||||
|
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DetailsUseIsEmptyTest()
|
||||||
|
{
|
||||||
|
var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", 1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List<DetailsUseDataModel>());
|
||||||
|
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var requestType = RequestType.Repair;
|
||||||
|
var description = "Valid description";
|
||||||
|
var cost = 1500;
|
||||||
|
var dateComplete = DateTime.Now;
|
||||||
|
var emploeeId = Guid.NewGuid().ToString();
|
||||||
|
var clientId = Guid.NewGuid().ToString();
|
||||||
|
var detailsUses = new List<DetailsUseDataModel>
|
||||||
|
{
|
||||||
|
new DetailsUseDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10)
|
||||||
|
};
|
||||||
|
|
||||||
|
var request = CreateDataModel(id, requestType, description, cost, dateComplete, emploeeId, clientId, detailsUses);
|
||||||
|
|
||||||
|
Assert.That(request.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(request.RequestType, Is.EqualTo(requestType));
|
||||||
|
Assert.That(request.Description, Is.EqualTo(description));
|
||||||
|
Assert.That(request.Cost, Is.EqualTo(cost));
|
||||||
|
Assert.That(request.DateComplete, Is.EqualTo(dateComplete));
|
||||||
|
Assert.That(request.EmploeeId, Is.EqualTo(emploeeId));
|
||||||
|
Assert.That(request.ClientId, Is.EqualTo(clientId));
|
||||||
|
Assert.That(request.DetailsUse, Is.EqualTo(detailsUses));
|
||||||
|
}
|
||||||
|
|
||||||
|
private RequestDataModel CreateDataModel(string id, RequestType requestType, string? description, int cost, DateTime dateComplete, string emploeeId, string? clientId, List<DetailsUseDataModel>? detailsUses)
|
||||||
|
=> new RequestDataModel(id, requestType, description, cost, dateComplete, emploeeId, clientId, detailsUses);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
using ElectricalRepairServiceContract.DataModels;
|
||||||
|
using ElectricalRepairServiceContract.Enums;
|
||||||
|
using ElectricalRepairServiceContract.Exceptions;
|
||||||
|
|
||||||
|
namespace ElectricalRepairServiceTests.DataModelsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
internal class SalaryDataModelTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel(null, SalaryType.Salary, 1000, Guid.NewGuid().ToString(), DateTime.Now);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
salary = CreateDataModel(string.Empty, SalaryType.Salary, 1000, Guid.NewGuid().ToString(), DateTime.Now);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel("invalid-id", SalaryType.Salary, 1000, Guid.NewGuid().ToString(), DateTime.Now);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmploeeIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel(Guid.NewGuid().ToString(), SalaryType.Salary, 1000, null, DateTime.Now);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
salary = CreateDataModel(Guid.NewGuid().ToString(), SalaryType.Salary, 1000, string.Empty, DateTime.Now);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmploeeIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel(Guid.NewGuid().ToString(), SalaryType.Salary, 1000, "invalid-id", DateTime.Now);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AmountIsNegativeTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel(Guid.NewGuid().ToString(), SalaryType.Salary, -1000, Guid.NewGuid().ToString(), DateTime.Now);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var salaryType = SalaryType.Salary;
|
||||||
|
var amount = 1500;
|
||||||
|
var emploeeId = Guid.NewGuid().ToString();
|
||||||
|
var date = DateTime.Now;
|
||||||
|
|
||||||
|
var salary = CreateDataModel(id, salaryType, amount, emploeeId, date);
|
||||||
|
|
||||||
|
Assert.That(salary.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(salary.SalaryType, Is.EqualTo(salaryType));
|
||||||
|
Assert.That(salary.Amount, Is.EqualTo(amount));
|
||||||
|
Assert.That(salary.EmploeeId, Is.EqualTo(emploeeId));
|
||||||
|
Assert.That(salary.Date, Is.EqualTo(date));
|
||||||
|
}
|
||||||
|
|
||||||
|
private SalaryDataModel CreateDataModel(string id, SalaryType salaryType, int amount, string emploeeId, DateTime date)
|
||||||
|
=> new SalaryDataModel(id, emploeeId, salaryType, amount, date);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.4">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||||
|
<PackageReference Include="NUnit" Version="4.3.2" />
|
||||||
|
<PackageReference Include="NUnit.Analyzers" Version="4.6.0">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ElectricalRepairServiceContract\ElectricalRepairServiceContract.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="NUnit.Framework" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user