61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using PuferFishContracts.DataModels;
|
|
using PuferFishContracts.Exceptions;
|
|
|
|
namespace PuferFishTests.DataModelsTests;
|
|
|
|
[TestFixture]
|
|
internal class PointsDataModelTests
|
|
{
|
|
[Test]
|
|
public void WorkerIdIsEmptyTest()
|
|
{
|
|
var points = CreateDataModel(null, DateTime.Now, 10);
|
|
Assert.That(() => points.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
points = CreateDataModel(string.Empty, DateTime.Now, 10);
|
|
Assert.That(() => points.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
[Test]
|
|
public void WorkerIdIsNotGuidTest()
|
|
{
|
|
var points = CreateDataModel("workerId", DateTime.Now, 10);
|
|
Assert.That(() => points.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
[Test]
|
|
public void PriceIsLessOrZeroTest()
|
|
{
|
|
var points = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now,
|
|
0);
|
|
Assert.That(() => points.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
points = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -
|
|
10);
|
|
Assert.That(() => points.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
[Test]
|
|
public void AllFieldsIsCorrectTest()
|
|
{
|
|
var buyerId = Guid.NewGuid().ToString();
|
|
var pointsDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
|
var buyerPoints = 10;
|
|
var points = CreateDataModel(buyerId, pointsDate, buyerPoints);
|
|
Assert.That(() => points.Validate(), Throws.Nothing);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(points.BuyerId, Is.EqualTo(buyerId));
|
|
Assert.That(points.PointsDate, Is.EqualTo(pointsDate));
|
|
Assert.That(points.Points, Is.EqualTo(buyerPoints));
|
|
});
|
|
}
|
|
private static PointsDataModel CreateDataModel(string? buyerId, DateTime
|
|
pointsDate, double buyerPoints) => new(buyerId, pointsDate, buyerPoints);
|
|
}
|