public async Task Deve_Buscar_Por_Id_Pelo_Repositorio() { //Given var services = new ServiceCollection(); var entity = new TestEntity( new NomeValueObject("Weslley", "Carneiro") , new EmailValueObject("*****@*****.**")); services.AddLogging(); services.AddContext <TestContext>(new ContextOptionsBuilder()); services.AddRepository <ITestReadRepository, TestReadRepository>("Optsol.Components.Test.Utils"); var provider = services.BuildServiceProvider(); IUnitOfWork unitOfWork = provider.GetRequiredService <IUnitOfWork>(); ITestReadRepository readRepository = provider.GetRequiredService <ITestReadRepository>(); ITestWriteRepository writeRepository = provider.GetRequiredService <ITestWriteRepository>(); await writeRepository.InsertAsync(entity); await unitOfWork.CommitAsync(); //When var entityResult = await readRepository.GetByIdAsync(entity.Id); //Then entityResult.Should().NotBeNull(); entityResult.Nome.ToString().Should().Be(entity.Nome.ToString()); entityResult.Email.ToString().Should().Be(entity.Email.ToString()); }
public async Task Deve_Testar_A_Configuracao_Do_Servico() { //Given var services = new ServiceCollection(); var entity = new TestEntity( new NomeValueObject("Weslley", "Carneiro") , new EmailValueObject("*****@*****.**")); services.AddLogging(); services.AddAutoMapper(typeof(TestViewModel)); services.AddContext <TestContext>(new ContextOptionsBuilder()); services.AddRepository <ITestReadRepository, TestReadRepository>("Optsol.Components.Test.Utils"); services.AddApplicationServices <ITestServiceApplication, TestServiceApplication>("Optsol.Components.Test.Utils"); var provider = services.BuildServiceProvider(); ITestWriteRepository writeRepository = provider.GetRequiredService <ITestWriteRepository>(); IUnitOfWork unitOfWork = provider.GetRequiredService <IUnitOfWork>(); ITestServiceApplication serviceApplication = provider.GetRequiredService <ITestServiceApplication>(); //When await writeRepository.InsertAsync(entity); await unitOfWork.CommitAsync(); var modelResult = await serviceApplication.GetAllAsync(); //Then modelResult.DataList.Should().HaveCount(1); modelResult.DataList.First().Nome.Should().Be(entity.Nome.ToString()); modelResult.DataList.First().Contato.Should().Be(entity.Email.ToString()); }