From 843ee6d2e15244e5c2d6691710453b20b6ed43d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 18 Oct 2021 17:23:45 +0300 Subject: [PATCH] Added tests --- .../EventRegistrationRepository_Tests.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/EventHub.Domain.Tests/Events/Registrations/EventRegistrationRepository_Tests.cs diff --git a/test/EventHub.Domain.Tests/Events/Registrations/EventRegistrationRepository_Tests.cs b/test/EventHub.Domain.Tests/Events/Registrations/EventRegistrationRepository_Tests.cs new file mode 100644 index 0000000..77956a5 --- /dev/null +++ b/test/EventHub.Domain.Tests/Events/Registrations/EventRegistrationRepository_Tests.cs @@ -0,0 +1,66 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Shouldly; +using Volo.Abp.Domain.Repositories; +using Xunit; + +namespace EventHub.Events.Registrations +{ + public class EventRegistrationRepository_Tests : EventHubDomainTestBase + { + private readonly IEventRegistrationRepository _repository; + private readonly EventHubTestData _testData; + + public EventRegistrationRepository_Tests() + { + _repository = GetRequiredService(); + _testData = GetRequiredService(); + } + + [Fact] + public async Task Exists_Should_Return_False_If_Not_Registered() + { + var exists = await _repository.ExistsAsync( + _testData.AbpMicroservicesFutureEventId, + _testData.UserJohnId); + exists.ShouldBeFalse(); + + await _repository.InsertAsync( + new EventRegistration( + Guid.NewGuid(), + _testData.AbpMicroservicesFutureEventId, + _testData.UserJohnId)); + } + + [Fact] + public async Task Exists_Should_Return_True_If_Registered() + { + await _repository.InsertAsync( + new EventRegistration( + Guid.NewGuid(), + _testData.AbpMicroservicesFutureEventId, + _testData.UserJohnId)); + + var exists = await _repository.ExistsAsync( + _testData.AbpMicroservicesFutureEventId, + _testData.UserJohnId); + exists.ShouldBeTrue(); + } + + [Fact] + public async Task Test_With_Uow() + { + await WithUnitOfWorkAsync(async () => + { + var queryable = await _repository.GetQueryableAsync(); + var exists = await queryable.Where( + x => x.EventId == _testData.AbpMicroservicesFutureEventId && + x.UserId == _testData.UserJohnId + ).FirstOrDefaultAsync(); + exists.ShouldBeNull(); + }); + } + } +} \ No newline at end of file