示例#1
0
        public IActionResult Left([FromBody] DiffLeft diffLeft)
        {
            try
            {
                diffLeft.Validate();

                if (diffLeft.isValid)
                {
                    diffLeft = (DiffLeft)Binary.BinaryToString(diffLeft);
                }
                else
                {
                    return(BadRequest(Validate.FormatObservationInclude(diffLeft)));
                }

                _storage.Left = diffLeft;
                _diffLeftRepository.Incluid(diffLeft);

                return(Ok(Validate.FormatObservationInclude(diffLeft)));
            }
            catch (Exception ex)
            {
                return(UnprocessableEntity(Validate.FormatError(ex.ToString())));
            }
        }
示例#2
0
        public async Task GetStoreResultOk()
        {
            // PostLeft
            DiffLeft diffLeft = new DiffLeft("01010100 01100101 01110011 01110100 01100101 00100000 01101100 01100101 01100110 01110100");
            string   jsonLeft = JsonConvert.SerializeObject(diffLeft);

            var sendLeft     = new StringContent(jsonLeft, Encoding.UTF8, "application/json");
            var responseLeft = await _testContext.Client.PostAsync("/v1/diff/left", sendLeft);

            responseLeft.EnsureSuccessStatusCode();
            responseLeft.StatusCode.CompareTo(HttpStatusCode.OK);

            //PostRight
            DiffRight diffRight = new DiffRight("01010100 01100101 01110011 01110100 01100101 00100000 01110010 01101001 01100111 01101000 01110100");
            string    jsonRight = JsonConvert.SerializeObject(diffRight);

            var sendRight     = new StringContent(jsonRight, Encoding.UTF8, "application/json");
            var responseRight = await _testContext.Client.PostAsync("/v1/diff/right", sendRight);

            responseRight.EnsureSuccessStatusCode();
            responseRight.StatusCode.CompareTo(HttpStatusCode.OK);

            // GetStoreResult
            var response = await _testContext.Client.GetAsync("/v1/diff");

            response.EnsureSuccessStatusCode();
            response.StatusCode.CompareTo(HttpStatusCode.OK);

            string   result      = response.Content.ReadAsStringAsync().Result;
            Response objResponse = JsonConvert.DeserializeObject <Response>(result);

            Assert.True(objResponse != null);
        }
示例#3
0
        public void BinaryToString()
        {
            string   expected = "Funcionou";
            DiffLeft diff     = new DiffLeft("01000110 01110101 01101110 01100011 01101001 01101111 01101110 01101111 01110101");

            Diff result = Binary.BinaryToString(diff);

            Assert.True(expected == result.Value);
        }
示例#4
0
        public async Task PostLeftValueBadRequest()
        {
            DiffLeft diffLeft = new DiffLeft(null);
            string   json     = JsonConvert.SerializeObject(diffLeft);

            var send     = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await _testContext.Client.PostAsync("/v1/diff/left", send);

            response.StatusCode.CompareTo(HttpStatusCode.BadRequest);
        }
示例#5
0
        public async Task PostLeftValueOk()
        {
            DiffLeft diffLeft = new DiffLeft("01010100 01100101 01110011 01110100 01100101 00100000 01101100 01100101 01100110 01110100");
            string   json     = JsonConvert.SerializeObject(diffLeft);

            var send     = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await _testContext.Client.PostAsync("/v1/diff/left", send);

            response.EnsureSuccessStatusCode();
            response.StatusCode.CompareTo(HttpStatusCode.OK);
        }
示例#6
0
        public void VerifyDiff()
        {
            string expected = "{\"Errors\":[],\"Observations\":[\"Tamanho do valor 'left' é idêntico ao tamanho do valor 'right'.\"]}";

            DiffLeft  diffLeft  = new DiffLeft("01010110 01100001 01101100 01110101 01100101 00100000 01001111 01101110 01100101");
            DiffRight diffRight = new DiffRight("01010110 01100001 01101100 01110101 01100101 00100000 01010100 01110111 01101111");

            Response result  = Validate.VerifyDiff(diffLeft, diffRight);
            string   compare = JsonConvert.SerializeObject(result);

            Assert.True(expected.Equals(compare));
        }
示例#7
0
        /// <summary>
        /// Padroniza o formato de saída da aplicação, valida e compara os valores com o intuito de
        /// recuperar os valores diferentes
        /// </summary>
        /// <param name="diffLeft">Objeto que contem os valores para validação</param>
        /// <param name="diffRight">Objeto que contem os valores para validação</param>
        /// <returns>Retorna um objeto Response que contém os erros e as observações</returns>
        public static Response VerifyDiff(DiffLeft diffLeft, DiffRight diffRight)
        {
            List <string> errors       = new List <string>();
            List <string> observations = new List <string>();

            if (diffLeft == null)
            {
                diffLeft = new DiffLeft();
                diffLeft.Validate();
            }

            if (diffRight == null)
            {
                diffRight = new DiffRight();
                diffRight.Validate();
            }

            if (diffLeft.isValid && diffRight.isValid)
            {
                string leftValue  = diffLeft.Value.ToLower();
                string rightValue = diffRight.Value.ToLower();

                if (leftValue.Equals(rightValue))
                {
                    observations.Add("Valor 'left' é idêntico ao valor 'right'.");
                }
                else
                {
                    if (leftValue.Length == rightValue.Length)
                    {
                        observations.Add("Tamanho do valor 'left' é idêntico ao tamanho do valor 'right'.");
                    }

                    char[] leftChar  = leftValue.ToCharArray();
                    char[] rightChar = rightValue.ToCharArray();

                    var differences = leftChar.Except(rightChar);
                    foreach (var diff in differences)
                    {
                        observations.Add(string.Format("O valor '{0}' não está presente em ambos.", diff));
                    }
                }

                return(new Response(errors, observations));
            }
            else
            {
                errors.AddRange(diffLeft.GetValidationMessage);
                errors.AddRange(diffRight.GetValidationMessage);

                return(new Response(errors));
            }
        }
示例#8
0
        public void FormatObservationInclude()
        {
            string expected = "{\"Errors\":[],\"Observations\":[\"Valor Teste adicionado com sucesso.\"]}";

            DiffLeft diffLeft = new DiffLeft("Teste");

            diffLeft.Validate();

            Response result  = Validate.FormatObservationInclude(diffLeft);
            string   compare = JsonConvert.SerializeObject(result);

            Assert.True(expected.Equals(compare));
        }
示例#9
0
        public IActionResult DbRemoveLeft([FromQuery] long id)
        {
            try
            {
                DiffLeft diffLeft = _diffLeftRepository.GetbyId(id);
                _diffLeftRepository.Remove(diffLeft);

                return(Ok(Validate.FormatObservationRemove(diffLeft)));
            }
            catch (Exception ex)
            {
                return(UnprocessableEntity(Validate.FormatError(ex.ToString())));
            }
        }
示例#10
0
        public IActionResult DbResult([FromQuery] long leftId, [FromQuery] long rightId)
        {
            try
            {
                DiffLeft  diffLeft  = _diffLeftRepository.GetbyId(leftId);
                DiffRight diffRight = _diffRightRepository.GetbyId(rightId);

                return(Ok(Validate.VerifyDiff(diffLeft, diffRight)));
            }
            catch (Exception ex)
            {
                return(UnprocessableEntity(Validate.FormatError(ex.ToString())));
            }
        }
示例#11
0
        public void VerifyDiffReturnErrors()
        {
            string expected = "{\"Errors\":[\"Atributo 'value' é obrigatório.\",\"Atributo 'value' é obrigatório.\"],\"Observations\":[]}";

            DiffLeft diffLeft = new DiffLeft();

            diffLeft.Validate();

            DiffRight diffRight = new DiffRight();

            diffRight.Validate();

            Response result  = Validate.VerifyDiff(diffLeft, diffRight);
            string   compare = JsonConvert.SerializeObject(result);

            Assert.True(expected.Equals(compare));
        }