예제 #1
0
        public async Task Deve_Buscar_Todos_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");

            var provider = services.BuildServiceProvider();
            ITestServiceApplication serviceApplication = provider.GetRequiredService <ITestServiceApplication>();

            //When
            await serviceApplication.InsertAsync(model);

            await serviceApplication.InsertAsync(model);

            await serviceApplication.InsertAsync(model);

            var modelResult = await serviceApplication.GetAllAsync();

            //Then
            modelResult.Invalid.Should().BeFalse();
            modelResult.Notifications.Should().HaveCount(0);

            modelResult.DataList.Should().HaveCount(3);
            modelResult.DataList.Where(w => w.Nome.Equals(model.Nome)).Should().HaveCount(3);
            modelResult.DataList.Where(w => w.Contato.Equals(model.Contato)).Should().HaveCount(3);
        }
예제 #2
0
        public async Task Deve_Inserir_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");

            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().BeFalse();
            modelResult.Notifications.Should().HaveCount(0);

            entity.DataList.Should().HaveCount(1);
            entity.DataList.Single().Id.Should().NotBeEmpty();
            entity.DataList.Single().Nome.Should().Be(model.Nome);
            entity.DataList.Single().Contato.Should().Be(model.Contato);
            entity.DataList.Single().Ativo.Should().Be("Inativo");
        }
예제 #3
0
        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_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");
        }
        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();
        }