Ejemplo n.º 1
0
        public void Setup()
        {
            _addressPatchService = Substitute.For <AddressPatchService>();
            _addressPatch        = Substitute.For <AddressPatch>();

            _json = JsonConvert.SerializeObject(_addressPatch);
        }
Ejemplo n.º 2
0
        public void AddressPatchServiceTests_CheckAddress5IsUpdated_WhenPatchIsCalled()
        {
            var addressPatch = new AddressPatch {
                Address5 = "Address 5"
            };

            var patchedAddress = _addressPatchService.Patch(_json, addressPatch);

            var address = JsonConvert.DeserializeObject <Models.Address>(patchedAddress);

            // Assert
            Assert.AreEqual("Address 5", address.Address5);
        }
Ejemplo n.º 3
0
        public void AddressPatchServiceTests_CheckLastModifiedTouchpointIdIsUpdated_WhenPatchIsCalled()
        {
            var addressPatch = new AddressPatch {
                LastModifiedTouchpointId = "0000000111"
            };

            var patchedAddress = _addressPatchService.Patch(_json, addressPatch);

            var address = JsonConvert.DeserializeObject <Models.Address>(patchedAddress);

            // Assert
            Assert.AreEqual("0000000111", address.LastModifiedTouchpointId);
        }
Ejemplo n.º 4
0
        public void AddressPatchServiceTests_CheckLastModifiedDateIsUpdated_WhenPatchIsCalled()
        {
            var addressPatch = new AddressPatch {
                LastModifiedDate = DateTime.MaxValue
            };

            var patchedAddress = _addressPatchService.Patch(_json, addressPatch);

            var address = JsonConvert.DeserializeObject <Models.Address>(patchedAddress);

            // Assert
            Assert.AreEqual(DateTime.MaxValue, address.LastModifiedDate);
        }
Ejemplo n.º 5
0
        public void AddressPatchServiceTests_CheckLatitudeIsUpdated_WhenPatchIsCalled()
        {
            var addressPatch = new AddressPatch {
                Latitude = (decimal?)147.3494
            };

            var patchedAddress = _addressPatchService.Patch(_json, addressPatch);

            var address = JsonConvert.DeserializeObject <Models.Address>(patchedAddress);

            // Assert
            Assert.AreEqual((decimal?)147.3494, address.Latitude);
        }
Ejemplo n.º 6
0
        public void AddressPatchServiceTests_CheckAlternativePostCodeIsUpdated_WhenPatchIsCalled()
        {
            var addressPatch = new AddressPatch {
                AlternativePostCode = "CV1 1VC"
            };

            var patchedAddress = _addressPatchService.Patch(_json, addressPatch);

            var address = JsonConvert.DeserializeObject <Models.Address>(patchedAddress);

            // Assert
            Assert.AreEqual("CV1 1VC", address.AlternativePostCode);
        }
Ejemplo n.º 7
0
        public string PatchResource(string addressJson, AddressPatch addressPatch)
        {
            if (string.IsNullOrEmpty(addressJson))
            {
                return(null);
            }

            if (addressPatch == null)
            {
                return(null);
            }

            addressPatch.SetDefaultValues();

            return(_addressPatchService.Patch(addressJson, addressPatch));
        }
        public string Patch(string addressJson, AddressPatch addressPatch)
        {
            if (string.IsNullOrEmpty(addressJson))
            {
                return(null);
            }

            var obj = JObject.Parse(addressJson);

            if (!string.IsNullOrEmpty(addressPatch.Address1))
            {
                JsonHelper.UpdatePropertyValue(obj["Address1"], addressPatch.Address1);
            }

            if (!string.IsNullOrEmpty(addressPatch.Address2))
            {
                JsonHelper.UpdatePropertyValue(obj["Address2"], addressPatch.Address2);
            }

            if (!string.IsNullOrEmpty(addressPatch.Address3))
            {
                JsonHelper.UpdatePropertyValue(obj["Address3"], addressPatch.Address3);
            }

            if (!string.IsNullOrEmpty(addressPatch.Address4))
            {
                JsonHelper.UpdatePropertyValue(obj["Address4"], addressPatch.Address4);
            }

            if (!string.IsNullOrEmpty(addressPatch.Address5))
            {
                JsonHelper.UpdatePropertyValue(obj["Address5"], addressPatch.Address5);
            }

            if (!string.IsNullOrEmpty(addressPatch.PostCode))
            {
                JsonHelper.UpdatePropertyValue(obj["PostCode"], addressPatch.PostCode);
            }

            if (!string.IsNullOrEmpty(addressPatch.AlternativePostCode))
            {
                JsonHelper.UpdatePropertyValue(obj["AlternativePostCode"], addressPatch.AlternativePostCode);
            }

            if (addressPatch.Longitude.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["Longitude"], addressPatch.Longitude);
            }

            if (addressPatch.Latitude.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["Latitude"], addressPatch.Latitude);
            }

            if (addressPatch.EffectiveFrom.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["EffectiveFrom"], addressPatch.EffectiveFrom);
            }

            if (addressPatch.EffectiveTo.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["EffectiveTo"], addressPatch.EffectiveTo);
            }

            if (addressPatch.LastModifiedDate.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["LastModifiedDate"], addressPatch.LastModifiedDate);
            }

            if (!string.IsNullOrEmpty(addressPatch.LastModifiedTouchpointId))
            {
                JsonHelper.UpdatePropertyValue(obj["LastModifiedTouchpointId"], addressPatch.LastModifiedTouchpointId);
            }

            return(obj.ToString());
        }