first commit

This commit is contained in:
2026-02-26 14:04:18 +07:00
parent 57ac80a666
commit 4b7236493f
92 changed files with 4999 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
using FluentAssertions;
using MyNewProjectName.Domain.Common;
namespace MyNewProjectName.UnitTest.Domain;
public class BaseEntityTests
{
private class TestEntity : BaseEntity { }
private class TestDomainEvent : IDomainEvent
{
public DateTime OccurredOn { get; } = DateTime.UtcNow;
}
[Fact]
public void AddDomainEvent_ShouldAddEventToCollection()
{
// Arrange
var entity = new TestEntity();
var domainEvent = new TestDomainEvent();
// Act
entity.AddDomainEvent(domainEvent);
// Assert
entity.DomainEvents.Should().Contain(domainEvent);
entity.DomainEvents.Should().HaveCount(1);
}
[Fact]
public void RemoveDomainEvent_ShouldRemoveEventFromCollection()
{
// Arrange
var entity = new TestEntity();
var domainEvent = new TestDomainEvent();
entity.AddDomainEvent(domainEvent);
// Act
entity.RemoveDomainEvent(domainEvent);
// Assert
entity.DomainEvents.Should().BeEmpty();
}
[Fact]
public void ClearDomainEvents_ShouldRemoveAllEvents()
{
// Arrange
var entity = new TestEntity();
entity.AddDomainEvent(new TestDomainEvent());
entity.AddDomainEvent(new TestDomainEvent());
// Act
entity.ClearDomainEvents();
// Assert
entity.DomainEvents.Should().BeEmpty();
}
}

View File

@@ -0,0 +1,60 @@
using FluentAssertions;
using MyNewProjectName.Domain.ValueObjects;
namespace MyNewProjectName.UnitTest.Domain;
public class ValueObjectTests
{
private class TestValueObject : ValueObject
{
public string Value1 { get; }
public int Value2 { get; }
public TestValueObject(string value1, int value2)
{
Value1 = value1;
Value2 = value2;
}
protected override IEnumerable<object?> GetEqualityComponents()
{
yield return Value1;
yield return Value2;
}
}
[Fact]
public void ValueObjects_WithSameValues_ShouldBeEqual()
{
// Arrange
var vo1 = new TestValueObject("test", 123);
var vo2 = new TestValueObject("test", 123);
// Act & Assert
vo1.Should().Be(vo2);
(vo1 == vo2).Should().BeTrue();
}
[Fact]
public void ValueObjects_WithDifferentValues_ShouldNotBeEqual()
{
// Arrange
var vo1 = new TestValueObject("test", 123);
var vo2 = new TestValueObject("test", 456);
// Act & Assert
vo1.Should().NotBe(vo2);
(vo1 != vo2).Should().BeTrue();
}
[Fact]
public void GetHashCode_ShouldBeSameForEqualObjects()
{
// Arrange
var vo1 = new TestValueObject("test", 123);
var vo2 = new TestValueObject("test", 123);
// Act & Assert
vo1.GetHashCode().Should().Be(vo2.GetHashCode());
}
}