Exemplo n.º 1
0
        public async Task FormResponseService_AddFormResponseInvalid_ResultInvalid()
        {
            //arrange
            FormBuild        formBuild = new FormBuild("Teste", DateTime.Now);
            IntFieldBuilder  intField  = new IntFieldBuilder("value_test", 5, 10, true);
            TextFieldBuilder textField = new TextFieldBuilder("text", isRequired: true);

            formBuild.AddField(textField);
            formBuild.AddField(intField);

            FormResponse formResponse = new FormResponse(formBuild);

            IntFieldResponse intResponse = new IntFieldResponse(intField);

            intResponse.SetValue(11);

            TextFieldResponse textResponse = new TextFieldResponse(textField);

            formResponse.AddField(intResponse);
            formResponse.AddField(textResponse);

            //act
            ValidationResult result = await _service.AddAsync(formResponse);

            //assert
            Assert.False(result.IsValid, "Formulário não está válido");
        }
Exemplo n.º 2
0
        public void FormResponseService_UpdateFormResponseValid_ResultValid()
        {
            //arrange
            FormBuild        formBuild = new FormBuild("Teste", DateTime.Now);
            IntFieldBuilder  intField  = new IntFieldBuilder("value_test", 5, 10, true);
            TextFieldBuilder textField = new TextFieldBuilder("text");

            formBuild.AddField(textField);
            formBuild.AddField(intField);

            FormResponse formResponse = new FormResponse(formBuild);

            IntFieldResponse intResponse = new IntFieldResponse(intField);

            intResponse.SetValue(10);

            TextFieldResponse textResponse = new TextFieldResponse(textField);

            textResponse.SetValue("valid");

            formResponse.AddField(intResponse);
            formResponse.AddField(textResponse);

            _repository.Update(formResponse);

            //act
            ValidationResult result = _service.Update(formResponse);

            //assert
            Assert.True(result.IsValid, "Formulário não está válido");
        }
        public async Task FormResponseRepository_RespondFormMultiplesFields_Success()
        {
            //arrange
            FormBuild        formBuild = new FormBuild("Test", DateTime.Now);
            IntFieldBuilder  intField  = new IntFieldBuilder("age", 5, 10, true);
            TextFieldBuilder textField = new TextFieldBuilder("name");

            formBuild.AddField(intField);
            formBuild.AddField(textField);

            FormResponse formResponse = new FormResponse(formBuild);

            IntFieldResponse intFieldResponse = new IntFieldResponse(intField);

            intFieldResponse.SetValue(10);
            formResponse.AddField(intFieldResponse);

            TextFieldResponse textFieldResponse = new TextFieldResponse(textField);

            textFieldResponse.SetValue("Maria");
            formResponse.AddField(textFieldResponse);

            //act
            await _repository.AddAsync(formResponse);

            await _unitOfWork.SaveChangesAsync();

            //assert
            Assert.True(intFieldResponse.Id > 0);
        }
        public async Task FormResponseRepository_RespondForm_Success()
        {
            //arrange
            IFormBuildRepository buildRepository = new FormBuildRepository(_dbContext);
            FormBuild            formBuild       = new FormBuild("Teste", DateTime.Now);
            IntFieldBuilder      intField        = new IntFieldBuilder("value_test", 5, 10, true);

            formBuild.AddField(intField);
            await buildRepository.AddAsync(formBuild);

            await _unitOfWork.SaveChangesAsync();

            FormResponse     formResponse     = new FormResponse(formBuild);
            IntFieldResponse intFieldResponse = new IntFieldResponse(intField);

            intFieldResponse.SetValue(10);
            formResponse.AddField(intFieldResponse);

            //act
            await _repository.AddAsync(formResponse);

            await _unitOfWork.SaveChangesAsync();

            //assert
            Assert.True(intFieldResponse.Id > 0);
        }
        public async Task FormResponseRepository_DeleteFormResponse_Success()
        {
            //arrange
            FormBuild       formBuild = new FormBuild("Teste", DateTime.Now);
            IntFieldBuilder intField  = new IntFieldBuilder("value_test", 5, 10, true);

            formBuild.AddField(intField);

            FormResponse     formResponse     = new FormResponse(formBuild);
            IntFieldResponse intFieldResponse = new IntFieldResponse(intField);

            intFieldResponse.SetValue(10);
            formResponse.AddField(intFieldResponse);

            await _repository.AddAsync(formResponse);

            await _unitOfWork.SaveChangesAsync();

            int formResponseId = formResponse.Id;

            //act
            await _repository.RemoveAsync(formResponseId);

            await _unitOfWork.SaveChangesAsync();

            FormResponse formResponseNotFound = await _dbContext.FormResponses.FindAsync(formResponseId);

            //assert
            Assert.Null(formResponseNotFound);
        }
        public async Task FormBuildRepository_AddTwoFields_Success()
        {
            //arrange
            FormBuild        formBuild = new FormBuild("Test", DateTime.Now.AddDays(10));
            IntFieldBuilder  intField  = new IntFieldBuilder("value_test", 5, 10, true);
            TextFieldBuilder textField = new TextFieldBuilder("name", 10, 20, true, "Your name");

            formBuild.AddField(intField);
            formBuild.AddField(textField);
            await _repository.AddAsync(formBuild);

            //act
            await _unitOfWork.SaveChangesAsync();

            FormBuild formSaved = await _dbContext.FormBuilds.FindAsync(formBuild.Id);

            //assert
            Assert.NotNull(formSaved);
            Assert.True(formSaved.Fields.Count == 2);
        }
Exemplo n.º 7
0
        public void FormResponse_AddNewIndex_ResultTrue()
        {
            //arrange
            FormBuild        formBuild = new FormBuild("Teste", DateTime.Now);
            TextFieldBuilder textField = new TextFieldBuilder("text");

            formBuild.AddField(textField);

            FormResponse      formResponse      = new FormResponse(formBuild);
            TextFieldResponse textFieldResponse = new TextFieldResponse(textField);

            textFieldResponse.SetValue("valid");

            //act
            bool indexAdd = formResponse.AddField(textFieldResponse);

            //assert
            Assert.True(indexAdd);
        }
        public async Task FormResponseRepository_UpdateValueResponse_Success()
        {
            //arrange
            FormBuild       formBuild = new FormBuild("Teste", DateTime.Now);
            IntFieldBuilder intField  = new IntFieldBuilder("value_test", 5, 10, true);

            formBuild.AddField(intField);

            FormResponse     formResponse     = new FormResponse(formBuild);
            IntFieldResponse intFieldResponse = new IntFieldResponse(intField);

            intFieldResponse.SetValue(10);
            formResponse.AddField(intFieldResponse);

            await _repository.AddAsync(formResponse);

            await _unitOfWork.SaveChangesAsync();

            int setNewValue = 5;

            //act
            FormResponse formResponseFound = await _dbContext.FormResponses.FindAsync(formResponse.Id);

            IntFieldResponse intFieldResponseFound = null;

            if (formResponseFound != null && formResponseFound.Fields?.Count > 0)
            {
                intFieldResponseFound = formResponseFound.Fields.First() as IntFieldResponse;
                intFieldResponseFound.SetValue(setNewValue);
                await _unitOfWork.SaveChangesAsync();

                formResponseFound = await _dbContext.FormResponses.FindAsync(formResponse.Id);

                intFieldResponseFound = formResponseFound.Fields.First() as IntFieldResponse;
            }

            //assert
            Assert.NotNull(formResponseFound);
            Assert.True(formResponseFound.Fields?.Count == formResponse.Fields?.Count);
            Assert.True(intFieldResponseFound.Value == setNewValue);
        }
Exemplo n.º 9
0
        public void FormResponse_AddFiledInvalid_ResultFalse()
        {
            //arrange
            FormBuild       formBuild = new FormBuild("Teste", DateTime.Now);
            IntFieldBuilder intField  = new IntFieldBuilder("value_test", 5, 10, true);

            formBuild.AddField(intField);

            FormResponse     formResponse     = new FormResponse(formBuild);
            IntFieldResponse intFieldResponse = new IntFieldResponse(intField);

            //set value invalid
            intFieldResponse.SetValue(11);

            formResponse.AddField(intFieldResponse);

            //act
            ValidationResult result = formResponse.Validate();

            //assert
            Assert.False(result.IsValid, "Formulário não está válido");
        }