Example #1
0
        public async void RaceLogin_Should_Call_IApiRequestProvider_CreatePostRequest()
        {
            _requestProvider.CreatePostRequest(Arg.Any <string>(), Arg.Any <Dictionary <string, string> >(), Arg.Any <MazebotLoginRequest>(), Arg.Any <Dictionary <string, string> >());

            var request = new MazebotLoginRequest();
            await _client.RaceLogin(request);

            _requestProvider.Received(1).CreatePostRequest($"{_noopsUrl}/mazebot/race/start", Arg.Any <Dictionary <string, string> >(), request, Arg.Any <Dictionary <string, string> >());
        }
        public async Task <SecurityResponse> SignUp(SecurityRequest details)
        {
            var url     = $"{_endpoint}:signUp";
            var content = CreateAuthenticationRequest(details);

            var request  = _requestProvider.CreatePostRequest(url, content, queries: _defaultQuery);
            var response = await _apiClient.Send <SecurityResponse>(request);

            return(response);
        }
        public async Task <IEnumerable <RemarkDetails> > GetRemarks()
        {
            var url     = $"{_endpoint}:runQuery";
            var content = CreateGetRemarksRequest();

            var request  = _requestProvider.CreatePostRequest(url, content, headers: _defaultHeader);
            var response = await _apiClient.Send(request, async resp =>
            {
                var body = await resp.Content.ReadAsStringAsync();
                var obj  = JArray.Parse(body);
                return(GetRemarkDetailsArrayResponse(obj));
            });

            return(response);
        }
        public async Task <MazebotLoginResponse> RaceLogin(MazebotLoginRequest login)
        {
            var url = $"{_apiUrl}/mazebot/race/start";

            try
            {
                var request = _requestProvider.CreatePostRequest(url, content: login);

                var response = await _client.SendAsync(request, async r =>
                {
                    r.EnsureSuccessStatusCode();
                    var content = await r.Content.ReadAsStringAsync();
                    return(JsonConvert.DeserializeAnonymousType(content, new MazebotLoginResponse()));
                });

                return(response);
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"An error has occurred while trying to call the mazebot API {url}.");
                return(null);
            }
        }
        public async void GetRemarks_Should_Call_IApiRequestProvider_CreatePostRequest()
        {
            JObject content = null;
            Dictionary <string, string> header = null;

            _requestProvider.CreatePostRequest(Arg.Any <string>(), Arg.Do <JObject>(a => content = a), headers: Arg.Do <Dictionary <string, string> >(a => header = a));

            await _repository.GetRemarks();

            _requestProvider.Received(1).CreatePostRequest($"{_firebaseDatabase}/projects/{_firebaseProjectId}/databases/(default)/documents:runQuery", Arg.Any <JObject>(), headers: Arg.Any <Dictionary <string, string> >());

            content.Should().ContainKey("structuredQuery");
            content.SelectToken("structuredQuery").Value <JObject>().Should().ContainKey("select");
            content.SelectToken("structuredQuery.select").Value <JObject>().Should().ContainKey("fields");
            content.SelectToken("structuredQuery.select.fields").Value <JArray>().Should().HaveCount(4);
            content.SelectToken("structuredQuery.select.fields[0]").Value <JObject>().Should().ContainKey("fieldPath");
            content.SelectToken("structuredQuery.select.fields[0].fieldPath").Value <string>().Should().Be("lat");
            content.SelectToken("structuredQuery.select.fields[1]").Value <JObject>().Should().ContainKey("fieldPath");
            content.SelectToken("structuredQuery.select.fields[1].fieldPath").Value <string>().Should().Be("lng");
            content.SelectToken("structuredQuery.select.fields[2]").Value <JObject>().Should().ContainKey("fieldPath");
            content.SelectToken("structuredQuery.select.fields[2].fieldPath").Value <string>().Should().Be("remark");
            content.SelectToken("structuredQuery.select.fields[3]").Value <JObject>().Should().ContainKey("fieldPath");
            content.SelectToken("structuredQuery.select.fields[3].fieldPath").Value <string>().Should().Be("email");
            content.SelectToken("structuredQuery").Value <JObject>().Should().ContainKey("from");
            content.SelectToken("structuredQuery.from").Value <JArray>().Should().HaveCount(1);
            content.SelectToken("structuredQuery.from[0]").Value <JObject>().Should().ContainKey("collectionId");
            content.SelectToken("structuredQuery.from[0].collectionId").Value <string>().Should().Be("remarks");
            content.SelectToken("structuredQuery").Value <JObject>().Should().ContainKey("orderBy");
            content.SelectToken("structuredQuery.orderBy").Value <JArray>().Should().HaveCount(1);
            content.SelectToken("structuredQuery.orderBy[0]").Value <JObject>().Should().ContainKey("field");
            content.SelectToken("structuredQuery.orderBy[0].field").Value <JObject>().Should().ContainKey("fieldPath");
            content.SelectToken("structuredQuery.orderBy[0].field.fieldPath").Value <string>().Should().Be("email");

            header.Should().ContainKey("Authorization");
            header["Authorization"].Should().Be(_requestAuthorisation);
        }
        public async void SignUp_Should_Call_IApiRequestProvider_CreatePostRequest()
        {
            JObject content = null;
            Dictionary <string, string> query = null;

            _requestProvider.CreatePostRequest(Arg.Any <string>(), Arg.Do <JObject>(a => content = a), Arg.Any <Dictionary <string, string> >(), Arg.Do <Dictionary <string, string> >(a => query = a), Arg.Any <Func <JObject, HttpContent> >());

            var request = new SecurityRequest
            {
                Email    = "email",
                Password = "******"
            };
            await _provider.SignUp(request);

            _requestProvider.Received(1).CreatePostRequest($"{_firebaseAuthEndpoint}/accounts:signUp", Arg.Any <JObject>(), Arg.Any <Dictionary <string, string> >(), Arg.Any <Dictionary <string, string> >(), null);

            content.Value <string>("email").Should().Be(request.Email);
            content.Value <string>("password").Should().Be(request.Password);
            content.Value <bool>("returnSecureToken").Should().BeTrue();

            query.Should().ContainKey("key");
            query["key"].Should().Be(_firebaseApiKey);
        }
Example #7
0
 public void CreatePostRequest_Should_Set_HttpMethod_Correctly()
 {
     _provider.CreatePostRequest("https://google.com", 123).Method.Should().Be(HttpMethod.Post);
 }