using Chat.Domain.Entities; using FluentAssertions; using System; using Xunit; namespace Chat.Tests; public class ConversationTests { [Fact] public void Test_CanCreateConversationWithDefaultValues() { // Arrange & Act var conversation = new Conversation(); // Assert conversation.Should().NotBeNull(); conversation.Id.Should().BeEmpty(); conversation.Participant1Id.Should().BeEmpty(); conversation.Participant2Id.Should().BeEmpty(); conversation.CreatedAt.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromSeconds(1)); conversation.LastMessageId.Should().BeNull(); conversation.UnreadCount1.Should().Be(0); conversation.UnreadCount2.Should().Be(0); } [Fact] public void Test_CanCreateConversationWithAllProperties() { // Arrange var id = Guid.NewGuid(); var participant1Id = Guid.NewGuid(); var participant2Id = Guid.NewGuid(); var createdAt = DateTime.UtcNow.AddHours(-1); var lastMessageId = Guid.NewGuid(); var lastMessageAt = DateTime.UtcNow; var unreadCount1 = 5; var unreadCount2 = 2; // Act var conversation = new Conversation { Id = id, Participant1Id = participant1Id, Participant2Id = participant2Id, CreatedAt = createdAt, LastMessageId = lastMessageId, LastMessageAt = lastMessageAt, UnreadCount1 = unreadCount1, UnreadCount2 = unreadCount2 }; // Assert conversation.Id.Should().Be(id); conversation.Participant1Id.Should().Be(participant1Id); conversation.Participant2Id.Should().Be(participant2Id); conversation.CreatedAt.Should().Be(createdAt); conversation.LastMessageId.Should().Be(lastMessageId); conversation.LastMessageAt.Should().Be(lastMessageAt); conversation.UnreadCount1.Should().Be(unreadCount1); conversation.UnreadCount2.Should().Be(unreadCount2); } [Fact] public void Test_ConversationPropertiesAreCorrectlySet() { // Arrange var conversation = new Conversation(); // Act conversation.Id = Guid.NewGuid(); conversation.Participant1Id = Guid.NewGuid(); conversation.Participant2Id = Guid.NewGuid(); conversation.CreatedAt = DateTime.UtcNow; conversation.LastMessageId = Guid.NewGuid(); conversation.LastMessageAt = DateTime.UtcNow; conversation.UnreadCount1 = 10; conversation.UnreadCount2 = 7; // Assert conversation.Id.Should().NotBeEmpty(); conversation.Participant1Id.Should().NotBeEmpty(); conversation.Participant2Id.Should().NotBeEmpty(); conversation.CreatedAt.Should().BeAfter(DateTime.MinValue); conversation.LastMessageId.Should().NotBeNull(); conversation.LastMessageAt.Should().BeAfter(DateTime.MinValue); conversation.UnreadCount1.Should().Be(10); conversation.UnreadCount2.Should().Be(7); } [Fact] public void Test_LastMessageIdCanBeNullable() { // Arrange var conversation = new Conversation(); var messageId = Guid.NewGuid(); // Act conversation.LastMessageId = messageId; // Assert conversation.LastMessageId.Should().NotBeNull(); conversation.LastMessageId.Should().Be(messageId); // Act - set to null conversation.LastMessageId = null; // Assert conversation.LastMessageId.Should().BeNull(); } [Fact] public void Test_CreatedAtDefaultsToCurrentTime() { // Arrange & Act var beforeCreation = DateTime.UtcNow; var conversation = new Conversation(); var afterCreation = DateTime.UtcNow; // Assert conversation.CreatedAt.Should().BeOnOrBefore(afterCreation); conversation.CreatedAt.Should().BeOnOrAfter(beforeCreation); } [Fact] public void Test_UnreadCountsDefaultToZero() { // Arrange & Act var conversation = new Conversation(); // Assert conversation.UnreadCount1.Should().Be(0); conversation.UnreadCount2.Should().Be(0); } }