From 99b49144ef3c1dd3fa87279b6feca93370fcc9ae Mon Sep 17 00:00:00 2001 From: Vanderlan Gomes da Silva Date: Thu, 1 Feb 2024 17:15:42 -0300 Subject: [PATCH] test --- .../UnitOfWork/UnitOfWorkTestsTests.cs | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/tests/Orion.Test/Integration/UnitOfWork/UnitOfWorkTestsTests.cs b/tests/Orion.Test/Integration/UnitOfWork/UnitOfWorkTestsTests.cs index e2e8e6f..fcfff17 100644 --- a/tests/Orion.Test/Integration/UnitOfWork/UnitOfWorkTestsTests.cs +++ b/tests/Orion.Test/Integration/UnitOfWork/UnitOfWorkTestsTests.cs @@ -1,51 +1,51 @@ -//using System.Threading.Tasks; -//using Microsoft.EntityFrameworkCore; -//using Microsoft.Extensions.DependencyInjection; -//using Orion.Domain.Core.Repositories.UnitOfWork; -//using Orion.Test.Integration.Setup; -//using Orion.Test.Shared.Faker; -//using Xunit; - -//namespace Orion.Test.Integration.UnitOfWork; - -//public class UnitOfWorkTests (IntegrationTestsFixture fixture) : IntegrationTestsBootstrapper(fixture) -//{ -// [Fact] -// public async Task CommitAsync_WithUniqueIndexViolation_ThrowsDbUpdateException() -// { -// // arrange -// using var scope = ServiceProvider.CreateScope(); -// var unitOfWork = scope.ServiceProvider.GetService(); - -// var user = UserFaker.Get(); -// var user2 = UserFaker.Get(); - -// user2.Email = user.Email; - -// await unitOfWork.UserRepository.AddAsync(user); -// await unitOfWork.UserRepository.AddAsync(user2); - -// // act & assert -// await Assert.ThrowsAsync(() => unitOfWork.CommitAsync()); -// } - -// [Fact] -// public async Task CommitAsync_WithValidInsert_SaveRegistry() -// { -// // arrange -// using var scope = ServiceProvider.CreateScope(); -// var unitOfWork = scope.ServiceProvider.GetService(); - -// var validUser = UserFaker.Get(); - -// // act -// await unitOfWork.UserRepository.AddAsync(validUser); - -// Assert.Equal(0, validUser.UserId); - -// // act -// await unitOfWork.CommitAsync(); - -// Assert.NotEqual(0, validUser.UserId); -// } -//} \ No newline at end of file +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Orion.Domain.Core.Repositories.UnitOfWork; +using Orion.Test.Integration.Setup; +using Orion.Test.Shared.Faker; +using Xunit; + +namespace Orion.Test.Integration.UnitOfWork; + +public class UnitOfWorkTests(IntegrationTestsFixture fixture) : IntegrationTestsBootstrapper(fixture) +{ + [Fact] + public async Task CommitAsync_WithUniqueIndexViolation_ThrowsDbUpdateException() + { + // arrange + using var scope = ServiceProvider.CreateScope(); + var unitOfWork = scope.ServiceProvider.GetService(); + + var user = UserFaker.Get(); + var user2 = UserFaker.Get(); + + user2.Email = user.Email; + + await unitOfWork.UserRepository.AddAsync(user); + await unitOfWork.UserRepository.AddAsync(user2); + + // act & assert + await Assert.ThrowsAsync(() => unitOfWork.CommitAsync()); + } + + //[Fact] + //public async Task CommitAsync_WithValidInsert_SaveRegistry() + //{ + // // arrange + // using var scope = ServiceProvider.CreateScope(); + // var unitOfWork = scope.ServiceProvider.GetService(); + + // var validUser = UserFaker.Get(); + + // // act + // await unitOfWork.UserRepository.AddAsync(validUser); + + // Assert.Equal(0, validUser.UserId); + + // // act + // await unitOfWork.CommitAsync(); + + // Assert.NotEqual(0, validUser.UserId); + //} +} \ No newline at end of file