mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Finished MediaAttachments
the functionality and tests are completed
This commit is contained in:
@@ -100,4 +100,149 @@ public class MediaAttachmentsTests
|
||||
// Act & Assert
|
||||
Assert.ThrowsAsync<NotFoundByKeyException<Guid>>(async () => await attachmentsRepository.GetAllByMessageId(_fixture.Create<Guid>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Given_ValidAttachmentsId_When_FindByIdAsync_Then_Returns_Attachment()
|
||||
{
|
||||
// Arrange
|
||||
var attachment = _fixture.Create<MediaAttachments>();
|
||||
|
||||
await using var context = new GovorDbContext(_options);
|
||||
var attachmentsRepository = new MediaAttachmentsRepository(context, _validator);
|
||||
|
||||
context.MediaAttachments.Add(attachment);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
var result = await attachmentsRepository.FindByIdAsync(attachment.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.Not.Null);
|
||||
Assert.That(result, Is.EqualTo(attachment));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Given_InvalidAttachmentsId_When_FindByIdAsync_Should_Throw_NotFoundByKeyException()
|
||||
{
|
||||
// Arrange
|
||||
await using var context = new GovorDbContext(_options);
|
||||
var attachmentsRepository = new MediaAttachmentsRepository(context, _validator);
|
||||
|
||||
// Act & Assert
|
||||
Assert.ThrowsAsync<NotFoundByKeyException<Guid>>(async () => await attachmentsRepository.FindByIdAsync(_fixture.Create<Guid>()));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task Given_ValidAttachments_When_AddAsync_Then_AttachmentsAdded()
|
||||
{
|
||||
// Arrange
|
||||
var attachments = _fixture.Create<MediaAttachments>();
|
||||
|
||||
await using var context = new GovorDbContext(_options);
|
||||
var messagesRepository = new MediaAttachmentsRepository(context, _validator);
|
||||
|
||||
// Act
|
||||
await messagesRepository.AddAsync(attachments);
|
||||
|
||||
// Assert
|
||||
Assert.That(context.MediaAttachments.Count, Is.EqualTo(1));
|
||||
Assert.That(context.MediaAttachments.First(), Is.EqualTo(attachments));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Given_InvalidAttachments_When_AddAsync_Should_Throw_AdditionException()
|
||||
{
|
||||
// Arrange
|
||||
await using var context = new GovorDbContext(_options);
|
||||
var repository = new MediaAttachmentsRepository(context, _validator);
|
||||
|
||||
// Act & Assert
|
||||
Assert.ThrowsAsync<AdditionException>(async () => await repository.AddAsync(default));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Given_ExistAttachment_When_Exist_Then_ReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
var attachments = _fixture.Create<MediaAttachments>();
|
||||
|
||||
await using var context = new GovorDbContext(_options);
|
||||
var repository = new MediaAttachmentsRepository(context, _validator);
|
||||
|
||||
context.MediaAttachments.Add(attachments);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
var result = repository.Exist(attachments);
|
||||
var result2 = repository.Exist(attachments.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.True);
|
||||
Assert.That(result2, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Given_NotExistMessage_When_Exist_Then_ReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
var attachments = _fixture.Create<MediaAttachments>();
|
||||
|
||||
await using var context = new GovorDbContext(_options);
|
||||
var repository = new MediaAttachmentsRepository(context, _validator);
|
||||
|
||||
|
||||
// Act
|
||||
var result = repository.Exist(attachments);
|
||||
var result2 = repository.Exist(attachments.Id);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.False);
|
||||
Assert.That(result2, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Given_NotEqualMessage_When_Exist_Then_ReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
var attachments = _fixture.Create<MediaAttachments>();
|
||||
var attachments2 = _fixture.Create<MediaAttachments>();
|
||||
attachments2.Id = attachments.Id;
|
||||
|
||||
await using var context = new GovorDbContext(_options);
|
||||
var repository = new MediaAttachmentsRepository(context, _validator);
|
||||
|
||||
context.MediaAttachments.Add(attachments);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
// Act
|
||||
var result = repository.Exist(attachments2);
|
||||
|
||||
// Assert
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Given_InvalidMessage_When_Exist_Should_Throw_InvalidObjectException()
|
||||
{
|
||||
// Arrange
|
||||
var attachments = _fixture.Create<MediaAttachments>();
|
||||
attachments.MessageId = Guid.Empty;
|
||||
|
||||
await using var context = new GovorDbContext(_options);
|
||||
var repository = new MediaAttachmentsRepository(context, _validator);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<InvalidObjectException<MediaAttachments>>(() => repository.Exist(attachments));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Given_NullMessage_When_Exist_Should_Throw_InvalidObjectException()
|
||||
{
|
||||
using var context = new GovorDbContext(_options);
|
||||
var repository = new MediaAttachmentsRepository(context, _validator);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<InvalidObjectException<MediaAttachments>>(() => repository.Exist(default(MediaAttachments)));
|
||||
}
|
||||
}
|
||||
@@ -292,7 +292,7 @@ public class MessagesRepositoryTests
|
||||
var messagesRepository = new MessagesRepository(context, _messageValidator);
|
||||
|
||||
// Act
|
||||
messagesRepository.AddAsync(message);
|
||||
await messagesRepository.AddAsync(message);
|
||||
|
||||
// Assert
|
||||
Assert.That(context.Messages.Count, Is.EqualTo(1));
|
||||
|
||||
Reference in New Issue
Block a user