Example #1
0
 public InsertContactResult AddContact()
 {
     var contact = GetCompleteContact();
     var proxy = new ContactProxy();
     var response = proxy.InsertContact(contact);
     return response.DataObject;
 }
        public void ShouldAddNewContactAndUpdateCompanyAndContactManager()
        {
            var contactAggregateProxy = new ContactAggregateProxy();
            var contactProxy = new ContactProxy();
            var companyProxy = new CompanyProxy();

            var companyDetail = GetCompany();
            var companyResponse = companyProxy.InsertCompany(companyDetail);

            var contactManager = GetContact();

            var contactManagerResponse = contactProxy.InsertContact(contactManager);
            var contactAggregate = GetNewContactAggregate();
            contactAggregate.Company.Id = companyResponse.DataObject.InsertedCompanyId;
            contactAggregate.Company.LastUpdatedId = companyResponse.DataObject.LastUpdatedId;
            contactAggregate.ContactManager.Id = contactManagerResponse.DataObject.InsertedContactId;
            contactAggregate.ContactManager.LastUpdatedId = contactManagerResponse.DataObject.LastUpdatedId;

            var contactAggregateResponse = contactAggregateProxy.InsertContactAggregate(contactAggregate);
            Assert.IsTrue(contactAggregateResponse.IsSuccessfull, "Contact aggregate with new contact and updated company and contact manager failed");
            Assert.IsNotNull(contactAggregateResponse.DataObject);
            Assert.IsTrue(contactAggregateResponse.DataObject.CompanyId > 0, "Invalid CompanyId returned from InsertContactAggregate when updating company");
            Assert.IsTrue(contactAggregateResponse.DataObject.CompanyLastUpdatedId.Length > 0, "Invalid CompanyLastUpdatedId returned from InsertContactAggregate when updating company");
            Assert.IsTrue(contactAggregateResponse.DataObject.ContactManagerId > 0, "Invalid ContactManagerId returned from InsertContactAggregate when updating contact manager");
            Assert.IsTrue(contactAggregateResponse.DataObject.ContactManagerLastUpdatedId.Length > 0, "Invalid ContactManagerLastUpdatedId returned from InsertContactAggregate when updating contact manager");

            var dbContactAggregate =
                contactAggregateProxy.GetContactAggregate(contactAggregateResponse.DataObject.InsertedContactId);
            Assert.IsTrue(dbContactAggregate.IsSuccessfull);
            Assert.IsNotNull(dbContactAggregate.DataObject);
            Assert.IsNotNull(dbContactAggregate.DataObject.ContactManager.Id);
            Assert.IsNotNull(dbContactAggregate.DataObject.Company.Id);
            Assert.AreEqual(companyResponse.DataObject.InsertedCompanyId, dbContactAggregate.DataObject.Company.Id.Value, "Existing company not attached to contact aggregate");
            Assert.AreEqual(contactManagerResponse.DataObject.InsertedContactId, dbContactAggregate.DataObject.ContactManager.Id.Value, "Existing contact (manager) not attached to contact aggregate");

            var dbContactManager = contactProxy.GetContact(dbContactAggregate.DataObject.ContactManager.Id.Value);
            Assert.IsTrue(dbContactManager.IsSuccessfull);
            Assert.IsNotNull(dbContactManager.DataObject);

            AssertContactManager(dbContactAggregate.DataObject.ContactManager, dbContactManager.DataObject);
            Assert.AreEqual(dbContactAggregate.DataObject.ContactManager.LastUpdatedId,
                dbContactManager.DataObject.LastUpdatedId, "LastUpdatedId not updated for contact manager");

            var dbCompany = companyProxy.GetCompany(dbContactAggregate.DataObject.Company.Id.Value);
            Assert.IsTrue(dbCompany.IsSuccessfull);
            Assert.IsNotNull(dbCompany.DataObject);

            AssertCompany(dbContactAggregate.DataObject.Company, dbCompany.DataObject);
            Assert.AreEqual(dbContactAggregate.DataObject.Company.LastUpdatedId, dbCompany.DataObject.LastUpdatedId,
                "LastUpdatedId not updated for company");
        }
Example #3
0
        public void IndexedContactShouldMatchEntityData()
        {
            var searchProxy = new SearchProxy();
            var contactHelper = new ContactHelper();

            var contactResponse = contactHelper.AddContact();
            Thread.Sleep(2000);
            var contact = new ContactProxy().GetContact(contactResponse.InsertedContactId).DataObject;

            var searchResults = searchProxy.Search(contact.EmailAddress, SearchScope.Contacts, 1, 10);
            Assert.IsNotNull(searchResults.DataObject);
            Assert.IsTrue(searchResults.DataObject.Contacts.Count > 0);

            var indexedContact = searchResults.DataObject.Contacts.First(x => ReplaceEm(x.ContactEmail) == contact.EmailAddress);
            Assert.IsNotNull(indexedContact);
            Assert.AreEqual(contact.GivenName + " " + contact.FamilyName, ReplaceEm(indexedContact.Name));
            Assert.AreEqual(contact.MobilePhone, indexedContact.MobilePhone);
            Assert.AreEqual(contact.PrimaryPhone, indexedContact.MainPhone);
            Assert.AreEqual(contact.Id, indexedContact.Id);
            Assert.AreEqual("Contact", indexedContact.EntityType);
            Assert.AreEqual(contact.CompanyId ?? 0, indexedContact.CompanyId);
            Assert.AreEqual(contact.TwitterId, indexedContact.TwitterId);
        }
        public void UpdateCompleteContact()
        {
            var contact = GetMinimalContact();

            var proxy = new ContactProxy();
            var insertResponse = proxy.InsertContact(contact);

            Assert.IsTrue(insertResponse.IsSuccessfull);
            Assert.IsTrue(insertResponse.DataObject.InsertedContactId > 0);

            var insertedContact = proxy.GetContact(insertResponse.DataObject.InsertedContactId);
            insertedContact.DataObject.GivenName = "Jack";
            insertedContact.DataObject.PostalAddress.City = "Potts Point";

            var tags = new List<string>();
            tags.Add("Banana");
            tags.Add("Pear");
            insertedContact.DataObject.Tags = tags;

            var updateResponse = proxy.UpdateContact(insertedContact.DataObject, insertResponse.DataObject.InsertedContactId);

            Assert.IsTrue(updateResponse.IsSuccessfull);
            //System.Threading.Thread.Sleep(1000);
            var updatedContact = proxy.GetContact(updateResponse.DataObject.UpdatedContactId);

            Assert.AreEqual(insertedContact.DataObject.GivenName, updatedContact.DataObject.GivenName);
            Assert.IsNotNull(updatedContact.DataObject.PostalAddress);
            Assert.AreEqual(insertedContact.DataObject.PostalAddress.City, updatedContact.DataObject.PostalAddress.City);
        }
        public void ModifyingContactsIsBooleanFieldsShouldNotAffectOtherIsBooleanFields()
        {
            var contactsProxy = new ContactsProxy();

            //Find Test contact to obtain their Id.
            var contactsResponse = AssertContactProxy(contactsProxy, givenName: "carl", familyName: "o'neil", contactId: "GLD879");

            Assert.IsTrue(contactsResponse.DataObject.Contacts.Count >= 1, "Incorrect number of contacts found.");

            var proxy = new ContactProxy();

            var testId = contactsResponse.DataObject.Contacts[0].Id;
            var response = proxy.GetContact(testId.Value);
            Assert.IsNotNull(response);
            Assert.IsTrue(response.IsSuccessfull);
            Assert.IsNotNull(response.DataObject);

            // Now Modify the IsCustomer, IsContractor, IsSupplier, Is... fields and ensure setting one does not clear the other
            var testContact = response.DataObject;
            testContact.IsContractor = true;
            testContact.IsCustomer = true;
            testContact.IsPartner = true;
            testContact.IsSupplier = true;
            var updateResponse = proxy.UpdateContact(testContact, testContact.Id.Value);
            Assert.IsNotNull(updateResponse);
            Assert.IsTrue(updateResponse.IsSuccessfull);

            var updatedResponse1 = proxy.GetContact(testContact.Id.Value);
            Assert.IsTrue(updatedResponse1.IsSuccessfull);
            Assert.AreEqual(testContact.IsContractor, updatedResponse1.DataObject.IsContractor);
            Assert.AreEqual(testContact.IsCustomer, updatedResponse1.DataObject.IsCustomer);
            Assert.AreEqual(testContact.IsPartner, updatedResponse1.DataObject.IsPartner);
            Assert.AreEqual(testContact.IsSupplier, updatedResponse1.DataObject.IsSupplier);

            testContact.LastUpdatedId = updateResponse.DataObject.LastUpdatedId;
            testContact.IsSupplier = false;
            testContact.IsPartner = false;
            var updateResponse2 = proxy.UpdateContact(testContact, testContact.Id.Value);
            Assert.IsNotNull(updateResponse2);
            Assert.IsTrue(updateResponse2.IsSuccessfull);

            var updatedResponse2 = proxy.GetContact(testContact.Id.Value);
            Assert.IsTrue(updatedResponse2.IsSuccessfull);
            Assert.AreEqual(testContact.IsContractor, updatedResponse2.DataObject.IsContractor);
            Assert.AreEqual(testContact.IsCustomer, updatedResponse2.DataObject.IsCustomer);
            Assert.AreEqual(testContact.IsPartner, updatedResponse2.DataObject.IsPartner);
            Assert.AreEqual(testContact.IsSupplier, updatedResponse2.DataObject.IsSupplier);
        }
        public void InsertContactWithoutAddressDoesNotFail()
        {
            var contact = new Contact()
            {
                GivenName = "John",
                FamilyName = "Cook",
                EmailAddress = "*****@*****.**",
                HomePhone = "0211114444"
            };

            var proxy = new ContactProxy();
            var response = proxy.InsertContact(contact);

            Assert.IsTrue(response.IsSuccessfull);
            Assert.IsTrue(response.DataObject.InsertedContactId > 0);

            System.Threading.Thread.Sleep(1000); // Tags are saved through messagequeue, give time to be processed
            var insertedContact = proxy.GetContact(response.DataObject.InsertedContactId);
            Assert.IsNotNull(insertedContact.DataObject);
            Assert.AreEqual(contact.EmailAddress, insertedContact.DataObject.EmailAddress);
        }
        public void InsertCompleteContact()
        {
            var contact = GetCompleteContact();

            var proxy = new ContactProxy();
            var response = proxy.InsertContact(contact);

            Assert.IsTrue(response.IsSuccessfull);
            Assert.IsTrue(response.DataObject.InsertedContactId > 0);

            System.Threading.Thread.Sleep(1000); // Tags are saved through messagequeue, give time to be processed
            var insertedContact = proxy.GetContact(response.DataObject.InsertedContactId);
            Assert.IsNotNull(insertedContact.DataObject);

            Assert.AreEqual(contact.DirectDepositDetails.AcceptDirectDeposit, insertedContact.DataObject.DirectDepositDetails.AcceptDirectDeposit);
            Assert.AreEqual(contact.ChequeDetails.AcceptCheque, insertedContact.DataObject.ChequeDetails.AcceptCheque);
            Assert.AreEqual(contact.AutoSendStatement.HasValue, insertedContact.DataObject.AutoSendStatement.HasValue);
            Assert.AreEqual(contact.BpayDetails.BillerCode, insertedContact.DataObject.BpayDetails.BillerCode);
            Assert.AreEqual(contact.BpayDetails.CRN, insertedContact.DataObject.BpayDetails.CRN);
            Assert.AreEqual(contact.ChequeDetails.ChequePayableTo, insertedContact.DataObject.ChequeDetails.ChequePayableTo);
            Assert.AreEqual(contact.ContactId, insertedContact.DataObject.ContactId);
            Assert.AreEqual(contact.ContactManagerId, insertedContact.DataObject.ContactManagerId);
            Assert.AreEqual(contact.CustomField1, insertedContact.DataObject.CustomField1);
            Assert.AreEqual(contact.CustomField2, insertedContact.DataObject.CustomField2);
            Assert.AreEqual(contact.DefaultPurchaseDiscount, insertedContact.DataObject.DefaultPurchaseDiscount);
            Assert.AreEqual(contact.DefaultSaleDiscount, insertedContact.DataObject.DefaultSaleDiscount);
            Assert.AreEqual(contact.DirectDepositDetails.AccountBSB, insertedContact.DataObject.DirectDepositDetails.AccountBSB);
            Assert.AreEqual(contact.DirectDepositDetails.AccountName, insertedContact.DataObject.DirectDepositDetails.AccountName);
            Assert.AreEqual(contact.DirectDepositDetails.AccountNumber, insertedContact.DataObject.DirectDepositDetails.AccountNumber);
            Assert.AreEqual(contact.EmailAddress, insertedContact.DataObject.EmailAddress);
            Assert.AreEqual(contact.FamilyName, insertedContact.DataObject.FamilyName);
            Assert.AreEqual(contact.Fax, insertedContact.DataObject.Fax);
            Assert.AreEqual(contact.GivenName, insertedContact.DataObject.GivenName);
            Assert.AreEqual(contact.HomePhone, insertedContact.DataObject.HomePhone);
            Assert.AreEqual(contact.IsActive, insertedContact.DataObject.IsActive);
            Assert.AreEqual(contact.IsContractor, insertedContact.DataObject.IsContractor);
            Assert.AreEqual(contact.IsCustomer, insertedContact.DataObject.IsCustomer);
            Assert.AreEqual(contact.IsPartner, insertedContact.DataObject.IsPartner);
            Assert.AreEqual(contact.IsSupplier, insertedContact.DataObject.IsSupplier);
            Assert.AreEqual(contact.LinkedInProfile, insertedContact.DataObject.LinkedInProfile);
            Assert.AreEqual(contact.MiddleInitials, insertedContact.DataObject.MiddleInitials);
            Assert.AreEqual(contact.MobilePhone, insertedContact.DataObject.MobilePhone);
            Assert.AreEqual(contact.CompanyId, insertedContact.DataObject.CompanyId);
            Assert.AreEqual(contact.PositionTitle, insertedContact.DataObject.PositionTitle);
            Assert.IsNotNull(contact.OtherAddress);
            Assert.AreEqual(contact.OtherAddress.City, insertedContact.DataObject.OtherAddress.City);
            Assert.AreEqual(contact.OtherAddress.Country, insertedContact.DataObject.OtherAddress.Country);
            Assert.AreEqual(contact.OtherAddress.Postcode, insertedContact.DataObject.OtherAddress.Postcode);
            Assert.AreEqual(contact.OtherAddress.State, insertedContact.DataObject.OtherAddress.State);
            Assert.AreEqual(contact.OtherAddress.Street, insertedContact.DataObject.OtherAddress.Street);
            Assert.AreEqual(contact.PostalAddress.City, insertedContact.DataObject.PostalAddress.City);
            Assert.AreEqual(contact.PostalAddress.Country, insertedContact.DataObject.PostalAddress.Country);
            Assert.AreEqual(contact.PostalAddress.Postcode, insertedContact.DataObject.PostalAddress.Postcode);
            Assert.AreEqual(contact.PostalAddress.State, insertedContact.DataObject.PostalAddress.State);
            Assert.AreEqual(contact.PostalAddress.Street, insertedContact.DataObject.PostalAddress.Street);
            Assert.AreEqual(contact.PrimaryPhone, insertedContact.DataObject.PrimaryPhone);
            Assert.IsNotNull(insertedContact.DataObject.PurchaseTradingTerms);
            Assert.AreEqual(contact.PurchaseTradingTerms.TradingTermsInterval, insertedContact.DataObject.PurchaseTradingTerms.TradingTermsInterval);
            Assert.AreEqual(contact.PurchaseTradingTerms.TradingTermsIntervalType, insertedContact.DataObject.PurchaseTradingTerms.TradingTermsIntervalType);
            Assert.AreEqual(contact.PurchaseTradingTerms.TradingTermsType, insertedContact.DataObject.PurchaseTradingTerms.TradingTermsType);
            Assert.IsNotNull(insertedContact.DataObject.SaleTradingTerms);
            Assert.AreEqual(contact.SaleTradingTerms.TradingTermsInterval, insertedContact.DataObject.SaleTradingTerms.TradingTermsInterval);
            Assert.AreEqual(contact.SaleTradingTerms.TradingTermsIntervalType, insertedContact.DataObject.SaleTradingTerms.TradingTermsIntervalType);
            Assert.AreEqual(contact.SaleTradingTerms.TradingTermsType, insertedContact.DataObject.SaleTradingTerms.TradingTermsType);
            Assert.AreEqual(contact.Salutation, insertedContact.DataObject.Salutation);
            Assert.AreEqual(contact.SkypeId, insertedContact.DataObject.SkypeId);
            Assert.AreEqual(contact.TwitterId, insertedContact.DataObject.TwitterId);
            Assert.AreEqual(contact.WebsiteUrl, insertedContact.DataObject.WebsiteUrl);
        }
        public void GetSingleContactWithContactId()
        {
            var contactsProxy = new ContactsProxy();

            //Find Test contact to obtain their Id.
            var contactsResponse = AssertContactProxy(contactsProxy, givenName: "carl", familyName: "o'neil", contactId: "GLD879");

            Assert.IsTrue(contactsResponse.DataObject.Contacts.Count >= 1, "Incorrect number of contacts found.");

            var proxy = new ContactProxy();

            var id = contactsResponse.DataObject.Contacts[0].Id;
            Assert.IsNotNull(id);
            var response = proxy.GetContact(id.Value);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.IsSuccessfull);
            Assert.IsNotNull(response.DataObject);
            Assert.IsNotNull(response.DataObject._links);
            Assert.IsTrue(response.DataObject._links.Count > 0);
            Assert.IsTrue(response.DataObject.Id == id);
        }
        public void DeleteContact()
        {
            var contact = GetMinimalContact();

            var proxy = new ContactProxy();
            var result = proxy.InsertContact(contact);

            Assert.IsTrue(result.IsSuccessfull);
            Assert.Greater(result.DataObject.InsertedContactId, 0);

            var deleteResult = proxy.DeleteContact(result.DataObject.InsertedContactId);
            Assert.IsTrue(deleteResult.IsSuccessfull);

            var deletedContact = proxy.GetContact(result.DataObject.InsertedContactId);
            Assert.IsNull(deletedContact.DataObject);
            Assert.AreEqual(HttpStatusCode.NotFound, deletedContact.StatusCode);
        }
Example #10
0
        private void GetPrimarySupplierContact()
        {
            var contact = new Contact()
            {
                GivenName = "Peter",
                FamilyName = "Baker",
                EmailAddress = "*****@*****.**",
                HomePhone = "0252113414"
            };

            var proxy = new ContactProxy();
            var response = proxy.InsertContact(contact);
            _primarySupplierId = response.DataObject.InsertedContactId;
        }
Example #11
0
        public void IndexedTransactionShouldMatchEntityData()
        {
            var searchProxy = new SearchProxy();
            var invoice = new InvoiceProxy().GetInvoice(_invoiceHelper.InvoiceId1.Value).DataObject;
            Assert.IsNotNull(invoice.BillingContactId, "Contact not found");
            var contact = new ContactProxy().GetContact(invoice.BillingContactId.Value).DataObject;

            var searchResults = searchProxy.Search(_invoiceHelper.InvoiceId1Summary, SearchScope.Transactions, 1, 100);
            Assert.IsNotNull(searchResults.DataObject);
            Assert.IsTrue(searchResults.DataObject.Transactions.Count > 0);
            var indexedTransaction = searchResults.DataObject.Transactions.First(x => x.Id == invoice.TransactionId);

            Assert.AreEqual(invoice.DueDate, indexedTransaction.DueDate);
            Assert.AreEqual(invoice.BillingContactOrganisationName, indexedTransaction.Company);
            Assert.AreEqual(contact.EmailAddress, ReplaceEm(indexedTransaction.ContactEmail));
            Assert.AreEqual(invoice.InvoiceNumber, indexedTransaction.InvoiceNumber);
            Assert.AreEqual(invoice.PurchaseOrderNumber, indexedTransaction.PurchaseOrderNumber);
            Assert.AreEqual(invoice.NotesExternal, indexedTransaction.ExternalNotes);
            Assert.AreEqual(invoice.NotesInternal, indexedTransaction.Notes);
            Assert.AreEqual(invoice.TransactionType, indexedTransaction.Type);
        }
        public void ShouldAddNewContactWithNewCompanyAndContactManager()
        {
            var contactAggregateProxy = new ContactAggregateProxy();
            var contactProxy = new ContactProxy();
            var companyProxy = new CompanyProxy();
            var contactAggregate = GetNewContactAggregate();
            var Response = contactAggregateProxy.InsertContactAggregate(contactAggregate);

            Assert.IsTrue(Response.IsSuccessfull, "Contact aggregate insert failed.");
            Assert.IsNotNull(Response.DataObject);
            Assert.IsTrue(Response.DataObject.InsertedContactId > 0, "Invalid InsertedContactId returned from InsertContactAggregate");
            Assert.IsTrue(Response.DataObject.LastUpdatedId.Length > 0, "Invalid LastUpdatedId returned");
            Assert.IsTrue(Response.DataObject.LastModified > DateTime.UtcNow.AddMinutes(-5), "Invalid LastModified returned");
            Assert.IsTrue(Response.DataObject.CompanyId > 0, "Invalid CompanyId returned from InsertContactAggregate when inserting new company");
            Assert.IsTrue(Response.DataObject.CompanyLastUpdatedId.Length > 0, "Invalid CompanyLastUpdatedId returned from InsertContactAggregate when inserting new company");
            Assert.IsTrue(Response.DataObject.ContactManagerId > 0, "Invalid ContactManagerId returned from InsertContactAggregate when inserting new contact manager");
            Assert.IsTrue(Response.DataObject.ContactManagerLastUpdatedId.Length > 0, "Invalid ContactManagerLastUpdatedId returned from InsertContactAggregate when inserting new contact manager");

            var contactResponse = contactProxy.GetContact(Response.DataObject.InsertedContactId);
            Assert.IsTrue(contactResponse.IsSuccessfull, "Contact not found");
            Assert.IsNotNull(contactResponse.DataObject);
            Assert.IsNotNull(contactResponse.DataObject.CompanyId);
            Assert.IsNotNull(contactResponse.DataObject.ContactManagerId);

            var contactManagerResponse = contactProxy.GetContact(contactResponse.DataObject.ContactManagerId.Value);
            Assert.IsTrue(contactManagerResponse.IsSuccessfull, "Contact manager not found");
            Assert.AreEqual(contactAggregate.ContactManager.FamilyName, contactManagerResponse.DataObject.FamilyName);

            var companyResponse = companyProxy.GetCompany(contactResponse.DataObject.CompanyId.Value);
            Assert.IsTrue(companyResponse.IsSuccessfull, "Company not found");
            Assert.AreEqual(contactAggregate.Company.Name, companyResponse.DataObject.Name);
        }
        public void ShouldUpdateContactAndUpdateCompanyAndContactManager()
        {
            var contactProxy = new ContactProxy();
            var companyProxy = new CompanyProxy();
            var contactAggregateProxy = new ContactAggregateProxy();
            var contact = GetContact();
            var contactResponse = contactProxy.InsertContact(contact);
            Assert.IsTrue(contactResponse.IsSuccessfull);
            var contactManager = GetContact();
            var contactManagerResponse = contactProxy.InsertContact(contactManager);
            Assert.IsTrue(contactManagerResponse.IsSuccessfull);
            var company = GetCompany();
            var companyResponse = companyProxy.InsertCompany(company);
            Assert.IsTrue(companyResponse.IsSuccessfull);

            var contactAggregate = GetNewContactAggregate();
            contactAggregate.Id = contactResponse.DataObject.InsertedContactId;
            contactAggregate.ContactManager.Id = contactManagerResponse.DataObject.InsertedContactId;
            contactAggregate.ContactManager.LastUpdatedId = contactManagerResponse.DataObject.LastUpdatedId;
            contactAggregate.Company.Id = companyResponse.DataObject.InsertedCompanyId;
            contactAggregate.Company.LastUpdatedId = companyResponse.DataObject.LastUpdatedId;

            var contactAggregateUpdateResponse = contactAggregateProxy.UpdateContactAggregate(contactAggregate,
                contactResponse.DataObject.InsertedContactId);
            Assert.IsTrue(contactAggregateUpdateResponse.IsSuccessfull, "Updating contact and company and contact manager in aggregate failed");
            Assert.IsNotNull(contactAggregateUpdateResponse.DataObject);
            Assert.IsTrue(contactAggregateUpdateResponse.DataObject.CompanyId > 0, "Invalid CompanyId returned from UpdateContactAggregate when updating company");
            Assert.IsTrue(contactAggregateUpdateResponse.DataObject.CompanyLastUpdatedId.Length > 0, "Invalid CompanyLastUpdatedId returned from UpdateContactAggregate when updating company");
            Assert.IsTrue(contactAggregateUpdateResponse.DataObject.ContactManagerId > 0, "Invalid ContactManagerId returned from UpdateContactAggregate when updating contact manager");
            Assert.IsTrue(contactAggregateUpdateResponse.DataObject.ContactManagerLastUpdatedId.Length > 0, "Invalid ContactManagerLastUpdatedId returned from UpdateContactAggregate when updating contact manager");

            var updatedContactAggregateResponse =
                contactAggregateProxy.GetContactAggregate(contactResponse.DataObject.InsertedContactId);
            Assert.IsTrue(updatedContactAggregateResponse.IsSuccessfull, "Updating contact and company and contact manager in aggregate failed");
            Assert.IsNotNull(updatedContactAggregateResponse.DataObject);
            var updatedAggregate = updatedContactAggregateResponse.DataObject;
            Assert.IsNotNull(updatedAggregate.Company, "Company not associated with updated aggregate");
            Assert.IsNotNull(updatedAggregate.ContactManager, "Contact manager not associated with updated aggregate");
            Assert.IsNotNull(updatedAggregate.Company.Id);
            Assert.IsNotNull(updatedAggregate.ContactManager.Id);

            var updatedContact = contactProxy.GetContact(contactResponse.DataObject.InsertedContactId);
            AssertUpdatedContact(contactAggregate, updatedContact);

            var updatedCompany = companyProxy.GetCompany(updatedAggregate.Company.Id.Value);
            Assert.IsTrue(updatedCompany.IsSuccessfull);
            Assert.IsNotNull(updatedCompany.DataObject);

            AssertCompany(contactAggregate.Company, updatedCompany.DataObject);

            var updatedContactManager = contactProxy.GetContact(updatedAggregate.ContactManager.Id.Value);
            Assert.IsTrue(updatedCompany.IsSuccessfull);
            Assert.IsNotNull(updatedCompany.DataObject);
            AssertContactManager(contactAggregate.ContactManager, updatedContactManager.DataObject);
        }
        public void ShouldUpdateContactAndAddNewCompanyAndContactManager()
        {
            var contactProxy = new ContactProxy();
            var contactAggregateProxy = new ContactAggregateProxy();
            var contact = GetContact();
            var contactResponse = contactProxy.InsertContact(contact);
            Assert.IsTrue(contactResponse.IsSuccessfull);

            var contactAggregate = GetNewContactAggregate();

            var contactAggregateResponse = contactAggregateProxy.UpdateContactAggregate(contactAggregate, contactResponse.DataObject.InsertedContactId);
            Assert.IsTrue(contactAggregateResponse.IsSuccessfull, "Failed to update existing contact and add new company and contact manager");
            Assert.IsNotNull(contactAggregateResponse.DataObject);
            Assert.AreEqual(contactResponse.DataObject.InsertedContactId, contactAggregateResponse.DataObject.UpdatedContactId);
            Assert.IsTrue(contactAggregateResponse.DataObject.CompanyId > 0, "Invalid CompanyId returned from UpdateContactAggregate when inserting new company");
            Assert.IsTrue(contactAggregateResponse.DataObject.CompanyLastUpdatedId.Length > 0, "Invalid CompanyLastUpdatedId returned from UpdateContactAggregate when inserting new company");
            Assert.IsTrue(contactAggregateResponse.DataObject.ContactManagerId > 0, "Invalid ContactManagerId returned from UpdateContactAggregate when inserting new contact manager");
            Assert.IsTrue(contactAggregateResponse.DataObject.ContactManagerLastUpdatedId.Length > 0, "Invalid ContactManagerLastUpdatedId returned from UpdateContactAggregate when inserting new contact manager");

            var updatedContact = contactProxy.GetContact(contactResponse.DataObject.InsertedContactId);
            AssertUpdatedContact(contactAggregate, updatedContact);

            var insertedAggregate =
                contactAggregateProxy.GetContactAggregate(contactResponse.DataObject.InsertedContactId);
            Assert.IsTrue(insertedAggregate.IsSuccessfull);
            Assert.IsNotNull(insertedAggregate.DataObject);
            Assert.IsNotNull(insertedAggregate.DataObject.Company, "New company not associated with existing contact");
            Assert.IsNotNull(insertedAggregate.DataObject.ContactManager, "New contact manager not associated with existing contact");
            Assert.AreEqual(contactAggregate.Company.Name, insertedAggregate.DataObject.Company.Name);
            Assert.AreEqual(contactAggregate.ContactManager.GivenName, insertedAggregate.DataObject.ContactManager.GivenName);
        }
        public void ShouldNotUpdateContactManagerWhenContactLastUpdatedIdIncorrect()
        {
            var contactProxy = new ContactProxy();
            var contactAggregateProxy = new ContactAggregateProxy();
            var contactAggregate = GetNewContactAggregate();
            var contactManager = GetContact();
            var contactManagerResponse = contactProxy.InsertContact(contactManager);

            var contact = GetContact();
            var contactResponse = contactProxy.InsertContact(contact);

            contactAggregate.Id = contactResponse.DataObject.InsertedContactId;
            contactAggregate.LastUpdatedId = contactResponse.DataObject.LastUpdatedId.ToLower();
            contactAggregate.ContactManager.Id = contactManagerResponse.DataObject.InsertedContactId;
            contactAggregate.Company.LastUpdatedId = contactManagerResponse.DataObject.LastUpdatedId;

            var aggregateResponse = contactAggregateProxy.UpdateContactAggregate(contactAggregate, contactResponse.DataObject.InsertedContactId);
            Assert.IsFalse(aggregateResponse.IsSuccessfull);
            Assert.AreEqual(HttpStatusCode.BadRequest, aggregateResponse.StatusCode);
            Assert.AreEqual("\"Record to be updated has changed since last read.\"", aggregateResponse.RawResponse);

            var updatedContact = contactProxy.GetContact(contactManagerResponse.DataObject.InsertedContactId);
            Assert.AreEqual(contactManagerResponse.DataObject.LastUpdatedId, updatedContact.DataObject.LastUpdatedId);
        }
        public void ShouldNotModifyExistingContactFieldsNotContainedInAggregateModel()
        {
            var contactProxy = new ContactProxy();
            var contactAggregateProxy = new ContactAggregateProxy();
            var contactAggregate = GetNewContactAggregate();

            var contact = GetCompleteContact();
            var contactResponse = contactProxy.InsertContact(contact);

            contactAggregate.Id = contactResponse.DataObject.InsertedContactId;
            contactAggregate.LastUpdatedId = contactResponse.DataObject.LastUpdatedId;

            var aggregateResponse = contactAggregateProxy.UpdateContactAggregate(contactAggregate, contactResponse.DataObject.InsertedContactId);
            Assert.IsTrue(aggregateResponse.IsSuccessfull);

            var updatedContactResponse = contactProxy.GetContact(contactResponse.DataObject.InsertedContactId);
            Assert.IsTrue(updatedContactResponse.IsSuccessfull);
            Assert.IsNotNull(updatedContactResponse.DataObject);
            var updatedContact = updatedContactResponse.DataObject;
            Assert.AreEqual(contact.AutoSendStatement, updatedContact.AutoSendStatement);
            Assert.AreEqual(contact.BpayDetails.BillerCode, updatedContact.BpayDetails.BillerCode);
            Assert.AreEqual(contact.BpayDetails.CRN, updatedContact.BpayDetails.CRN);
            Assert.AreEqual(contact.ChequeDetails.AcceptCheque, updatedContact.ChequeDetails.AcceptCheque);
            Assert.AreEqual(contact.ChequeDetails.ChequePayableTo, updatedContact.ChequeDetails.ChequePayableTo);
            Assert.AreEqual(contact.CustomField1, updatedContact.CustomField1);
            Assert.AreEqual(contact.CustomField2, updatedContact.CustomField2);
            Assert.AreEqual(contact.DefaultPurchaseDiscount, updatedContact.DefaultPurchaseDiscount);
            Assert.AreEqual(contact.DefaultSaleDiscount, updatedContact.DefaultSaleDiscount);
            Assert.AreEqual(contact.DirectDepositDetails.AcceptDirectDeposit, updatedContact.DirectDepositDetails.AcceptDirectDeposit);
            Assert.AreEqual(contact.DirectDepositDetails.AccountBSB, updatedContact.DirectDepositDetails.AccountBSB);
            Assert.AreEqual(contact.DirectDepositDetails.AccountName, updatedContact.DirectDepositDetails.AccountName);
            Assert.AreEqual(contact.DirectDepositDetails.AccountNumber, updatedContact.DirectDepositDetails.AccountNumber);
            Assert.AreEqual(contact.HomePhone, updatedContact.HomePhone);
            Assert.AreEqual(contact.LinkedInProfile, updatedContact.LinkedInProfile);
            Assert.AreEqual(contact.OtherAddress.City, updatedContact.OtherAddress.City);
            Assert.AreEqual(contact.OtherAddress.Country, updatedContact.OtherAddress.Country);
            Assert.AreEqual(contact.OtherAddress.Postcode, updatedContact.OtherAddress.Postcode);
            Assert.AreEqual(contact.OtherAddress.State, updatedContact.OtherAddress.State);
            Assert.AreEqual(contact.OtherAddress.Street, updatedContact.OtherAddress.Street);
            Assert.AreEqual(contact.OtherPhone, updatedContact.OtherPhone);
            Assert.AreEqual(contact.PurchaseTradingTerms.TradingTermsInterval, updatedContact.PurchaseTradingTerms.TradingTermsInterval);
            Assert.AreEqual(contact.PurchaseTradingTerms.TradingTermsIntervalType, updatedContact.PurchaseTradingTerms.TradingTermsIntervalType);
            Assert.AreEqual(contact.PurchaseTradingTerms.TradingTermsType, updatedContact.PurchaseTradingTerms.TradingTermsType);
            Assert.AreEqual(contact.SaleTradingTerms.TradingTermsInterval, updatedContact.SaleTradingTerms.TradingTermsInterval);
            Assert.AreEqual(contact.SaleTradingTerms.TradingTermsIntervalType, updatedContact.SaleTradingTerms.TradingTermsIntervalType);
            Assert.AreEqual(contact.SaleTradingTerms.TradingTermsType, updatedContact.SaleTradingTerms.TradingTermsType);
            Assert.AreEqual(contact.SkypeId, updatedContact.SkypeId);
            Assert.AreEqual(contact.TwitterId, updatedContact.TwitterId);
            Assert.AreEqual(contact.WebsiteUrl, updatedContact.WebsiteUrl);
        }