public async Task Deve_Remover_Registro_Pelo_Id_Pelo_Servico() { //Given InsertTestViewModel model = new InsertTestViewModel(); model.Nome = "Weslley Carneiro"; model.Contato = "*****@*****.**"; var services = new ServiceCollection(); services.AddLogging(); services.AddAutoMapper(typeof(TestViewModel)); services.AddContext <TestContext>(new ContextOptionsBuilder()); services.AddApplicationServices <ITestServiceApplication, TestServiceApplication>("Optsol.Components.Test.Utils"); var provider = services.BuildServiceProvider(); ITestServiceApplication serviceApplication = provider.GetRequiredService <ITestServiceApplication>(); await serviceApplication.InsertAsync(model); var data = (await serviceApplication.GetAllAsync()).DataList.Single(); //When var modelResult = await serviceApplication.DeleteAsync(data.Id); //Then var entity = await serviceApplication.GetAllAsync(); modelResult.Invalid.Should().BeFalse(); modelResult.Notifications.Should().HaveCount(0); entity.DataList.Should().HaveCount(0); }
public async Task Deve_Remover_Registro_Pelo_Id_Pelo_Servico() { //Given InsertTestViewModel model = new InsertTestViewModel(); model.Nome = "Weslley Carneiro"; model.Contato = "*****@*****.**"; var services = new ServiceCollection(); services.AddLogging(); services.AddAutoMapper(typeof(TestViewModel)); services.AddDomainNotifications(); services.AddContext <Context>(options => { options .EnabledInMemory() .EnabledLogging(); }); services.AddApplications <ITestServiceApplication, TestServiceApplication>("Optsol.Components.Test.Utils"); services.AddServices(); var provider = services.BuildServiceProvider(); ITestServiceApplication serviceApplication = provider.GetRequiredService <ITestServiceApplication>(); IApiControllerBase <TestEntity, TestViewModel, TestViewModel, InsertTestViewModel, UpdateTestViewModel, TestSearchDto> controllerBase = new ApiControllerBase <TestEntity, TestViewModel, TestViewModel, InsertTestViewModel, UpdateTestViewModel, TestSearchDto>( provider.GetRequiredService <ILoggerFactory>(), provider.GetRequiredService <IBaseServiceApplication <TestEntity> >(), provider.GetRequiredService <IResponseFactory>()); await serviceApplication.InsertAsync <InsertTestViewModel, InsertTestViewModel>(model); var entity = (await serviceApplication.GetAllAsync <TestViewModel>()).FirstOrDefault(); //When var actionResult = await controllerBase.DeleteAsync(entity.Id); //Then ((OkObjectResult)actionResult).StatusCode.Should().NotBeNull(); ((OkObjectResult)actionResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var resultObj = JsonConvert.DeserializeObject <Response>(((OkObjectResult)actionResult).Value.ToJson()); resultObj.Should().NotBeNull(); resultObj.Success.Should().BeTrue(); resultObj.Failure.Should().BeFalse(); resultObj.Messages.Should().BeEmpty(); (await serviceApplication.GetAllAsync <TestViewModel>()).Should().BeEmpty(); }
public async Task Nao_Deve_Inserir_Registro_Pelo_Servico() { //Given InsertTestViewModel model = new InsertTestViewModel(); model.Nome = ""; model.Contato = "weslley.carneiro"; var services = new ServiceCollection(); services.AddLogging(); services.AddAutoMapper(typeof(TestViewModel)); services.AddContext <TestContext>(new ContextOptionsBuilder()); services.AddApplicationServices <ITestServiceApplication, TestServiceApplication>("Optsol.Components.Test.Utils"); var provider = services.BuildServiceProvider(); ITestServiceApplication serviceApplication = provider.GetRequiredService <ITestServiceApplication>(); //When var modelResult = await serviceApplication.InsertAsync(model); //Then var entity = await serviceApplication.GetAllAsync(); modelResult.Invalid.Should().BeTrue(); modelResult.Notifications.Should().HaveCount(3); }
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()); }
public async Task Deve_Atualizar_Registro_Pelo_Servico() { //Given InsertTestViewModel model = new InsertTestViewModel(); model.Nome = "Weslley Carneiro"; model.Contato = "*****@*****.**"; var services = new ServiceCollection(); services.AddLogging(); services.AddAutoMapper(typeof(TestViewModel)); services.AddContext <TestContext>(new ContextOptionsBuilder()); services.AddApplicationServices <ITestServiceApplication, TestServiceApplication>("Optsol.Components.Test.Utils"); services.AddAServices(); var provider = services.BuildServiceProvider(); ITestServiceApplication serviceApplication = provider.GetRequiredService <ITestServiceApplication>(); IApiControllerBase <TestEntity, TestViewModel, TestViewModel, InsertTestViewModel, UpdateTestViewModel> controllerBase = new ApiControllerBase <TestEntity, TestViewModel, TestViewModel, InsertTestViewModel, UpdateTestViewModel>( provider.GetRequiredService <ILogger <ApiControllerBase <TestEntity, TestViewModel, TestViewModel, InsertTestViewModel, UpdateTestViewModel> > >(), provider.GetRequiredService <IBaseServiceApplication <TestEntity, TestViewModel, TestViewModel, InsertTestViewModel, UpdateTestViewModel> >(), provider.GetRequiredService <IResponseFactory>()); await serviceApplication.InsertAsync(model); var data = (await serviceApplication.GetAllAsync()).DataList.Single(); var updateModel = new UpdateTestViewModel(); updateModel.Id = data.Id; updateModel.Nome = $"Weslley Alterado"; updateModel.Contato = model.Contato; //When var actionResult = await controllerBase.UpdateAsync(updateModel); //Then ((OkObjectResult)actionResult).StatusCode.Should().NotBeNull(); ((OkObjectResult)actionResult).StatusCode.Should().Be((int)HttpStatusCode.OK); var resultObj = JsonConvert.DeserializeObject <Response>(((OkObjectResult)actionResult).Value.ToJson()); resultObj.Should().NotBeNull(); resultObj.Success.Should().BeTrue(); resultObj.Failure.Should().BeFalse(); resultObj.Messages.Should().BeEmpty(); var resultService = await serviceApplication.GetByIdAsync(updateModel.Id); resultService.Data.Should().NotBeNull(); resultService.Data.Id.Should().NotBeEmpty(); resultService.Data.Nome.Should().Be(updateModel.Nome); resultService.Data.Contato.Should().Be(updateModel.Contato); resultService.Data.Ativo.Should().Be("Inativo"); }