Exemple #1
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");
        }
Exemple #2
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");
        }
        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);
        }
Exemple #6
0
        public void IntField_MinValue_ResultFalse(int value)
        {
            //arrange
            IntFieldBuilder  intField      = new IntFieldBuilder("value_test", minValue: 2);
            IntFieldResponse fieldResponse = new IntFieldResponse(intField);

            fieldResponse.SetValue(value);

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

            //assert
            Assert.False(result.IsValid, "Regras do MinValue não estão ok.");
        }
Exemple #7
0
        public void IntField_IsRequiresTrue_ResultTrue(int value)
        {
            //arrange
            IntFieldBuilder  intField      = new IntFieldBuilder("value_test", isRequired: true);
            IntFieldResponse fieldResponse = new IntFieldResponse(intField);

            fieldResponse.SetValue(value);

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

            //assert
            Assert.True(result.IsValid, "Regras do isRequired não estão ok.");
        }
Exemple #8
0
        public void TextField_CreateNewField_ResultTrue(int value)
        {
            //arrange
            IntFieldBuilder  intField      = new IntFieldBuilder("value_test", 5, 10, true);
            IntFieldResponse fieldResponse = new IntFieldResponse(intField);

            fieldResponse.SetValue(value);

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

            //assert
            Assert.True(result.IsValid, "Regras do MinValue não estão ok.");
        }
Exemple #9
0
        public void IntField_Success()
        {
            //arrange
            IntFieldBuilder  intField      = new IntFieldBuilder("idade", 10, 20, false);
            IntFieldResponse fieldResponse = new IntFieldResponse(intField);

            fieldResponse.SetValue(12);

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

            //assert
            Assert.True(result.IsValid, "Regras não estão ok.");
        }
        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);
        }
Exemple #11
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");
        }