Beispiel #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");
        }
        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);
        }
Beispiel #3
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_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);
        }
Beispiel #6
0
 private void ValidateMaxValue()
 {
     RuleFor(p => p.Value)
     .Must((response, value) =>
     {
         IntFieldBuilder fieldBuilder = response.GetFieldBuilder();
         return(value <= fieldBuilder?.MaxValue.Value);
     })
     .When(p => p.FieldBuild != null && p.GetFieldBuilder()?.MaxValue != null)
     .WithMessage("Max value is required.");
 }
Beispiel #7
0
        public void IntField_IsRequiresTrue_ResultFalse()
        {
            //arrange
            IntFieldBuilder  intField      = new IntFieldBuilder("value_test", isRequired: true);
            IntFieldResponse fieldResponse = new IntFieldResponse(intField);

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

            //assert
            Assert.False(result.IsValid, "Regras do IsRequires não estão ok.");
        }
Beispiel #8
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.");
        }
Beispiel #9
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.");
        }
Beispiel #10
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 FormBuildRepository_AddOneFields_Success()
        {
            //arrange
            FormBuild       formBuild = new FormBuild("Test", DateTime.Now.AddDays(10));
            IntFieldBuilder intField  = new IntFieldBuilder("value_test", 5, 10, true);

            formBuild.AddField(intField);
            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 == 1);
        }
        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);
        }
Beispiel #13
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");
        }