private async Task <StatusConfigResponse> Register()
        {
            var registrationInfoRequest = new RegistrationInfoRequest(_userRepository.UserInfo.Id);

            Console.WriteLine($"registrationInfoRequest:\n{JsonConvert.SerializeObject(registrationInfoRequest, Formatting.Indented)}\n");
            StatusConfigResponse registrationInfoResponse = await _onboardingApi.Register(registrationInfoRequest).ConfigureAwait(false);

            Console.WriteLine($"registrationInfoResponse:\n {JsonConvert.SerializeObject(registrationInfoResponse, Formatting.Indented)}");
            Console.WriteLine();
            ApplyConfigurationFromServer(registrationInfoResponse.Config);
            _userRepository.IsRegistered = true;
            return(registrationInfoResponse);
        }
Exemple #2
0
        public async void ShouldGetRegistrationByFilter(
            string testName, string fromAsString, string toAsString, string[] inDateAStrings, DateTime[] expectInDates
            )
        {
            //given
            var indates = inDateAStrings.Select(DateTime.Parse).ToArray();

            var taskGrant = _tgBuilder
                            .Create(DateTime.Parse(fromAsString), DateTime.Parse(toAsString))
                            .WithAutoTaskAndTask()
                            .WithPlaces(indates)
                            .Build();

            var filter = new Filter
            {
                From      = DateTime.Parse(fromAsString),
                To        = DateTime.Parse(toAsString),
                OtmGuid   = taskGrant.Otm.TaskGuid,
                OtmCipher = "ПТП-101-2000-100",
                IssType   = IssType.Phone,
                IssValue  = "334-22-33",
                User      = "******",
                Password  = "******"
            };

            var expect = _converter.Convert(filter, taskGrant.AutoTask.places.Where(x => expectInDates.Contains(x.InDate)).Select(x => new Place
            {
                Cid    = x.Cid,
                InDate = x.InDate,
                Lac    = x.Lac,
                MCC    = x.MCC,
                MNC    = x.MNC
            }).ToArray());


            var request = new RegistrationInfoRequest
            {
                QueryParamsHashCode = _decoder.EncryptDecrypt(JsonConvert.SerializeObject(filter))
            };

            //when
            var actual = await _magAdapterClient.GetAllRegistrationsByParamsAsync(request);

            //then
            actual.Should().BeEquivalentTo(expect);
        }
Exemple #3
0
        public IActionResult RegistrationInfo([FromBody] RegistrationInfoRequest request)
        {
            try
            {
                var response = _scenario.GetRegistrationInfo(request);

                return(Ok(response));
            }
            catch (NotFoundParmsException)
            {
                return(new StatusCodeResult((int)HttpStatusCode.UnprocessableEntity));
            }
            catch (Exception)
            {
                return(StatusCode((int)HttpStatusCode.NotFound));
            }
        }
Exemple #4
0
        public async void SholdThrowNotFoundParmsExceptionWhenIncorretQueryParamsHashCode(string queryParamsHashCode)
        {
            var request = new RegistrationInfoRequest
            {
                QueryParamsHashCode = queryParamsHashCode
            };

            //when
            Action act = () =>
            {
                var task = _magAdapterClient.GetAllRegistrationsByParamsAsync(request);
                _ = task.Result;
            };

            //then
            act.Should().Throw <NotFoundParmsException>();
        }
        public void ShouldReturnResponce()
        {
            //Given
            var jsonString = "{\"filter\":\"value\"}";

            var request = new RegistrationInfoRequest
            {
                QueryParamsHashCode = "anyString"
            };

            var filter = new Filter
            {
                From      = DateTime.Parse("2021-01-12 12:00:55.033"),
                To        = DateTime.Parse("2021-01-12 12:00:55.033"),
                IssValue  = "333-22-44",
                IssType   = Mag.VisualizationLocation.Adapter.IssType.Phone,
                OtmCipher = "ПТП-2020",
                OtmGuid   = Guid.Parse("93f12ddf-ba74-46ea-b739-319622d331d5"),
                Password  = "******",
                User      = "******"
            };
            var places = new Place[9];
            var expect = new RegistrationInfoResponse();

            _mockDecoder
            .Setup(x => x.EncryptDecrypt(request.QueryParamsHashCode))
            .Returns(jsonString);

            _mockJsonSerealizer
            .Setup(x => x.Serealaze <Filter>(jsonString))
            .Returns(filter);

            _mockMtb.Setup(x => x.GetPlaces(filter)).Returns(places);
            _mockRegistrationInfoResponse.Setup(x => x.Convert(filter, places)).Returns(expect);

            var actual = _target.GetRegistrationInfo(request);

            actual.Should().BeEquivalentTo(expect);
        }
Exemple #6
0
        public RegistrationInfoResponse GetRegistrationInfo(RegistrationInfoRequest request)
        {
            if (request == null || string.IsNullOrWhiteSpace(request.QueryParamsHashCode))
            {
                _logger.Error("Неверный фильтр");
                throw new NotFoundParmsException();
            }

            Filter filter;

            try
            {
                var decodeRequest = _decoder.EncryptDecrypt(request.QueryParamsHashCode);
                filter = _serealizer.Serealaze <Filter>(decodeRequest);
            }
            catch (Exception exception)
            {
                _logger.Error("Ошибка получения фильра", exception);
                throw new NotFoundParmsException();
            }

            if (!filter.IsCorrectFilter())
            {
                _logger.Error("Не корректный фильр");
                throw new NotFoundParmsException();
            }

            try
            {
                var places = _mtbContext.GetPlaces(filter);
                return(_registrationInfoResponseConverter.Convert(filter, places));
            }
            catch (Exception e)
            {
                _logger.Error("Ошибка получения данных", e);
                throw e;
            }
        }
        public async Task <RegistrationInfoResponse> GetAllRegistrationsByParamsAsync(RegistrationInfoRequest request)
        {
            var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");

            var response = await _httpClient.PostAsync("api/Place/RegistrationInfo", content);

            if (!response.IsSuccessStatusCode)
            {
                if (response.StatusCode == HttpStatusCode.UnprocessableEntity) //422 Unprocessable Entity («необрабатываемый экземпляр»);
                {
                    throw new NotFoundParmsException();
                }
                else
                {
                    throw new Exception();
                }
            }

            var result = await ConvertResponse <RegistrationInfoResponse>(response);

            return(result);
        }
Exemple #8
0
 public void ShouldResponceDecrypt(RegistrationInfoRequest request, RegistrationInfoResponse response)
 {
     var decoder = new Decoder();
     var encrypt = decoder.EncryptDecrypt(request.QueryParamsHashCode);
 }