public void Setup()
        {
            _jsonHelper           = Substitute.For <JsonHelper>();
            _customerPatchService = Substitute.For <CustomerPatchService>();
            _customerPatch        = Substitute.For <CustomerPatch>();

            _json = JsonConvert.SerializeObject(_customerPatch);
        }
        public void CustomerPatchServiceTests_CheckDateOfRegistrationIsUpdated_WhenPatchIsCalled()
        {
            var customerPatch = new CustomerPatch {
                DateOfRegistration = DateTime.MaxValue
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual(DateTime.MaxValue, patchedCustomer.DateOfRegistration);
        }
        public void CustomerPatchServiceTests_CheckUniqueLearnerNumberIsUpdated_WhenPatchIsCalled()
        {
            var customerPatch = new CustomerPatch {
                UniqueLearnerNumber = "0000000111"
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual("0000000111", patchedCustomer.UniqueLearnerNumber);
        }
        public void CustomerPatchServiceTests_CheckLastModifiedDatesUpdated_WhenPatchIsCalled()
        {
            var customerPatch = new CustomerPatch {
                LastModifiedDate = DateTime.MaxValue
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual(DateTime.MaxValue, patchedCustomer.LastModifiedDate);
        }
        public void CustomerPatchServiceTests_CheckIntroducedByAdditionalInfoIsUpdated_WhenPatchIsCalled()
        {
            var customerPatch = new CustomerPatch {
                IntroducedByAdditionalInfo = "More Info"
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual("More Info", patchedCustomer.IntroducedByAdditionalInfo);
        }
        public void CustomerPatchServiceTests_CheckIntroducedByIsUpdated_WhenPatchIsCalled()
        {
            var customerPatch = new CustomerPatch {
                IntroducedBy = IntroducedBy.NotProvided
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual(IntroducedBy.NotProvided, patchedCustomer.IntroducedBy);
        }
        public void CustomerPatchServiceTests_CheckReasonForTerminationIsUpdated_WhenPatchIsCalled()
        {
            var customerPatch = new CustomerPatch {
                ReasonForTermination = ReasonForTermination.Duplicate
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual(ReasonForTermination.Duplicate, patchedCustomer.ReasonForTermination);
        }
        public void CustomerPatchServiceTests_CheckOptInMarketResearchIsUpdated_WhenPatchIsCalled()
        {
            var customerPatch = new CustomerPatch {
                OptInMarketResearch = true
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual(true, patchedCustomer.OptInMarketResearch);
        }
        public void CustomerPatchServiceTests_CheckTitleIsUpdated_WhenPatchIsCalled()
        {
            var customerPatch = new CustomerPatch {
                Title = Title.Dr
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual(Title.Dr, patchedCustomer.Title);
        }
        public void CustomerPatchServiceTests_CheckLastModifiedTouchpointIdIsUpdated_WhenPatchIsCalled()
        {
            var customerPatch = new CustomerPatch {
                LastModifiedTouchpointId = "0000000111"
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual("0000000111", patchedCustomer.LastModifiedTouchpointId);
        }
        public void CustomerPatchServiceTests_CheckGenderIsUpdated_WhenPatchIsCalled()
        {
            var customerPatch = new CustomerPatch {
                Gender = Gender.NotApplicable
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual(Gender.NotApplicable, patchedCustomer.Gender);
        }
        public void CustomerPatchServiceTests_CheckFamilyNameIsUpdated_WhenPatchIsCalled()
        {
            var familyName    = "Smith";
            var customerPatch = new CustomerPatch {
                FamilyName = familyName
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual(familyName, patchedCustomer.FamilyName);
        }
        public void CustomerPatchServiceTests_CheckGivenNameIsUpdated_WhenPatchIsCalled()
        {
            var givenName     = "John";
            var customerPatch = new CustomerPatch {
                GivenName = givenName
            };

            var customer = _customerPatchService.Patch(_json, customerPatch);

            var patchedCustomer = JsonConvert.DeserializeObject <Models.Customer>(customer);

            // Assert
            Assert.AreEqual(givenName, patchedCustomer.GivenName);
        }
Example #14
0
        public string PatchResource(string customerJson, CustomerPatch customerPatch)
        {
            if (string.IsNullOrEmpty(customerJson))
            {
                return(null);
            }

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

            customerPatch.SetDefaultValues();

            return(_customerPatchService.Patch(customerJson, customerPatch));
        }
        public static async Task SendPatchMessageAsync(CustomerPatch customerPatch, Guid customerId, string reqUrl)
        {
            var tokenProvider    = TokenProvider.CreateSharedAccessSignatureTokenProvider(KeyName, AccessKey);
            var messagingFactory = MessagingFactory.Create(BaseAddress, tokenProvider);
            var sender           = messagingFactory.CreateMessageSender(QueueName);
            var messageModel     = new MessageModel
            {
                TitleMessage     = "Customer record modification for {" + customerId + "} at " + DateTime.UtcNow,
                CustomerGuid     = customerId,
                LastModifiedDate = customerPatch.LastModifiedDate,
                URL           = reqUrl,
                IsNewCustomer = false,
                TouchpointId  = customerPatch.LastModifiedTouchpointId
            };

            var msg = new BrokeredMessage(new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(messageModel))))
            {
                ContentType = "application/json",
                MessageId   = customerId + " " + DateTime.UtcNow
            };

            //msg.ForcePersistence = true; Required when we save message to cosmos
            await sender.SendAsync(msg);
        }
Example #16
0
 public async Task SendToServiceBusQueueAsync(CustomerPatch customerPatch, Guid customerId, string reqUrl)
 {
     await ServiceBusClient.SendPatchMessageAsync(customerPatch, customerId, reqUrl);
 }
        public string Patch(string customerJson, CustomerPatch customerPatch)
        {
            if (string.IsNullOrEmpty(customerJson))
            {
                return(null);
            }

            var obj = JObject.Parse(customerJson);

            if (customerPatch.DateOfRegistration.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["DateOfRegistration"], customerPatch.DateOfRegistration);
            }

            if (customerPatch.Title.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["Title"], customerPatch.Title);
            }

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

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

            if (customerPatch.DateofBirth.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["DateofBirth"], customerPatch.DateofBirth);
            }

            if (customerPatch.Gender.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["Gender"], customerPatch.Gender);
            }

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

            if (customerPatch.OptInUserResearch.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["OptInUserResearch"], customerPatch.OptInUserResearch);
            }

            if (customerPatch.OptInMarketResearch.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["OptInMarketResearch"], customerPatch.OptInMarketResearch);
            }

            if (customerPatch.DateOfTermination.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["DateOfTermination"], customerPatch.DateOfTermination);
            }

            if (customerPatch.ReasonForTermination.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["ReasonForTermination"], customerPatch.ReasonForTermination);
            }

            if (customerPatch.IntroducedBy.HasValue)
            {
                JsonHelper.UpdatePropertyValue(obj["IntroducedBy"], customerPatch.IntroducedBy);
            }

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

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

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

            return(obj.ToString());
        }