Example #1
0
 public async Task <RemarkDetails> AddRemark(string email, AddRemarkRequest request)
 {
     return(await _repository.AddRemark(new RemarkDetails
     {
         Email = email,
         Latitude = request.Latitude,
         Longitude = request.Longitude,
         Remark = request.Remark
     }));
 }
        public async void AddRemark_Should_Call_IRemarksRepository_AddRemark()
        {
            var email   = "email";
            var request = new AddRemarkRequest
            {
                Latitude  = 123,
                Longitude = 456,
                Remark    = "remarks"
            };

            RemarkDetails arg = null;
            await _repository.AddRemark(Arg.Do <RemarkDetails>(a => arg = a));

            await _service.AddRemark(email, request);

            await _repository.Received(1).AddRemark(Arg.Any <RemarkDetails>());

            arg.Email.Should().Be(email);
            arg.Latitude.Should().Be(request.Latitude);
            arg.Longitude.Should().Be(request.Longitude);
            arg.Remark.Should().Be(request.Remark);
        }
        public async void AddRemark_Should_Call_IApiRequestProvider_CreatePostRequest()
        {
            JObject content = null;
            Dictionary <string, string> header = null;
            Dictionary <string, string> query  = null;

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

            var details = new RemarkDetails
            {
                Latitude  = 123,
                Longitude = 456,
                Remark    = "remarks",
                Email     = "email"
            };
            await _repository.AddRemark(details);

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

            content.Should().ContainKey("fields");
            content.SelectToken("fields").Value <JObject>().Should().ContainKey("lat");
            content.SelectToken("fields.lat").Value <JObject>().Should().ContainKey("doubleValue");
            content.SelectToken("fields.lat.doubleValue").Value <double>().Should().Be(details.Latitude);
            content.SelectToken("fields").Value <JObject>().Should().ContainKey("lng");
            content.SelectToken("fields.lng").Value <JObject>().Should().ContainKey("doubleValue");
            content.SelectToken("fields.lng.doubleValue").Value <double>().Should().Be(details.Longitude);
            content.SelectToken("fields").Value <JObject>().Should().ContainKey("remark");
            content.SelectToken("fields.remark").Value <JObject>().Should().ContainKey("stringValue");
            content.SelectToken("fields.remark.stringValue").Value <string>().Should().Be(details.Remark);
            content.SelectToken("fields").Value <JObject>().Should().ContainKey("email");
            content.SelectToken("fields.email").Value <JObject>().Should().ContainKey("stringValue");
            content.SelectToken("fields.email.stringValue").Value <string>().Should().Be(details.Email);

            header.Should().ContainKey("Authorization");
            header["Authorization"].Should().Be(_requestAuthorisation);

            query.Should().ContainKey("key");
            query["key"].Should().Be(_firebaseApiKey);
        }