コード例 #1
0
        /// <summary>
        /// Creates the test contact in the HubSpot sandbox if necessary
        /// </summary>
        /// <returns></returns>
        public async Task <CanonicalContact> CreateTestContact()
        {
            var logger = new Mock <ILogger>();
            var log    = logger.Object;

            // Ensure only one thread can enter this code at a time.
            await semaphoreSlim.WaitAsync();

            try
            {
                if (this.contact == null)
                {
                    const bool installationRecordexists = true;
                    var        adapter = new HubspotAdapter();

                    var contactResult = await adapter.CreateHubspotContactAsync(
                        this.TestContactEmailAddress,
                        "Autocreated",
                        "TestUser",
                        "Auto",
                        "08 123456789",
                        "Unit Test 1",
                        "CrmUpdateHandler St",
                        "Test City",
                        "WA",
                        "6000",
                        "Ready To Engage",
                        installationRecordexists,
                        log,
                        true);

                    if (contactResult.StatusCode == System.Net.HttpStatusCode.Conflict)
                    {
                        // Contact already exists - so just use that one
                        contactResult = await adapter.RetrieveHubspotContactByEmailAddr(this.TestContactEmailAddress, false, log, isTest : true);
                    }

                    if (contactResult.StatusCode != System.Net.HttpStatusCode.OK)
                    {
                        log.LogError($"Error {contactResult.StatusCode} creating HubSpot contact: {contactResult.ErrorMessage}");
                        throw new Exception(contactResult.ErrorMessage);
                    }

                    this.contact = contactResult.Payload;
                }

                return(this.contact);
            }
            finally
            {
                //When the task is ready, release the semaphore. It is vital to ALWAYS release the semaphore when we are ready, or else we will end up with a Semaphore that is forever locked.
                //This is why it is important to do the Release within a try...finally clause; program execution may crash or take a different path, this way you are guaranteed execution
                semaphoreSlim.Release();
            }
        }
コード例 #2
0
        public async Task verify_that_new_contact_with_no_mortgage_is_stored_correctly()
        {
            var updateReviewQ = new Mock <IAsyncCollector <string> >();

            var hubspotAdapter = new Mock <IHubSpotAdapter>();   // See note below; I'd rather mock the HttpClient and use a real HubSpotAdapter here.

            var data = new CanonicalContact("012345")
            {
                email     = "*****@*****.**",
                firstName = "aa",
                lastName  = "Postman",
                phone     = "867 5309"
            };

            var desiredResult = new HubSpotContactResult(data);

            // Set up a retval that the mock HubSpotAdapter might return
            hubspotAdapter.Setup(p => p.CreateHubspotContactAsync(
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <string>(),
                                     It.IsAny <bool>(),
                                     It.IsAny <ILogger>(),
                                     It.IsAny <bool>()))
            .ReturnsAsync(desiredResult);

            // Load in the JSON body of a typical create-crm request
            var filePath = @".\\TestData\\NewContactNoMortgage.json";
            var body     = File.ReadAllText(filePath, Encoding.UTF8);
            var query    = new Dictionary <string, StringValues>(); // If we want to test query params, put them here.
            //query.Add("messageId", "ABC123");
            var simulatedHttpRequest = this.HttpRequestSetup(query, body);

            var contactCreator = new CrmContactCreator(hubspotAdapter.Object);

            // Create the contact, with a mock error queue
            var result = await contactCreator.CreateNewContact(simulatedHttpRequest, _errorQueue, updateReviewQ.Object, _installationQueue, _logger);

            // TODO: Review these tests in the light of the new dependency-injection capabilities.

            Assert.IsType <OkObjectResult>(result);
            Assert.Single(_installationQueue.Items);

            // TODO: more assertions...
        }
コード例 #3
0
        public void New_Contact_Generates_FullNames_Correctly()
        {
            var contact = new CanonicalContact("1234")
            {
                firstName = "Jack",
                lastName  = "Mack"
            };

            var newContactPayload = new NewContactPayload(contact);

            Assert.Equal("Jack.Mack", newContactPayload.fullNamePeriodSeparated);
            Assert.Equal("Jack Mack", newContactPayload.fullName);
        }
コード例 #4
0
        public void Updated_Contact_Generates_FullNames_Correctly()
        {
            var contact = new CanonicalContact("1234")
            {
                firstName = "Jack",
                lastName  = "Mack"
            };

            Assert.Equal("Jack.Mack", contact.fullNamePeriodSeparated);
            Assert.Equal("Jack Mack", contact.fullName);

            contact.lastName = string.Empty;
            Assert.Equal("Jack", contact.fullNamePeriodSeparated);
            Assert.Equal("Jack", contact.fullName);

            contact.firstName = string.Empty;
            contact.lastName  = "Foo";
            Assert.Equal("Foo", contact.fullNamePeriodSeparated);
            Assert.Equal("Foo", contact.fullName);
        }
コード例 #5
0
        public void UpdatedContactPayload_ZeroPads_Vid()
        {
            var payload = new CanonicalContact("1234");

            Assert.Equal("001234", payload.contactId);
        }