public void ShouldInsertCompany() { var proxy = new CompanyProxy(); var company = GetTestCompany(); var insertResponse = proxy.InsertCompany(company); Assert.IsTrue(insertResponse.IsSuccessfull); Assert.AreEqual(HttpStatusCode.OK, insertResponse.StatusCode); Assert.Greater(insertResponse.DataObject.InsertedCompanyId, 0); var insertedCompany = proxy.GetCompany(insertResponse.DataObject.InsertedCompanyId).DataObject; Assert.IsNotNullOrEmpty(insertedCompany.Abn, "Company ABN not saved"); Assert.AreEqual(company.Abn, insertedCompany.Abn, "Incorrect ABN"); Assert.IsNotNullOrEmpty(insertedCompany.CompanyEmail, "Company email not saved"); Assert.AreEqual(company.CompanyEmail, insertedCompany.CompanyEmail, "Incorrect Company email"); Assert.IsNotNullOrEmpty(insertedCompany.LongDescription, "Company description not saved"); Assert.AreEqual(company.LongDescription, insertedCompany.LongDescription, "Incorrect company description"); Assert.IsNotNullOrEmpty(insertedCompany.TradingName, "Company trading name not saved"); Assert.AreEqual(company.TradingName, insertedCompany.TradingName, "Incorrect company trading name"); Assert.IsNotNullOrEmpty(insertedCompany.Website, "Company website not saved"); Assert.AreEqual(company.Website, insertedCompany.Website, "Incorrect company website"); Assert.IsNotNullOrEmpty(insertedCompany.LastUpdatedId, "Company LastUpdatedId not returned"); Assert.IsNotNull(insertedCompany.CreatedDateUtc, "Company CreatedDateUtc not returned"); Assert.IsNotNull(insertedCompany.LastModifiedDateUtc, "Company LastModifiedDateUtc not returned"); Assert.IsNotNull(insertedCompany.LastModifiedByUserId, "Company LastModifiedByUserId not returned"); }
public void ShouldNotUpdateCompanyWhenContactLastUpdatedIdIncorrect() { var contactProxy = new ContactProxy(); var companyProxy = new CompanyProxy(); var contactAggregateProxy = new ContactAggregateProxy(); var contactAggregate = GetNewContactAggregate(); var companyDetail = GetCompany(); var companyResponse = companyProxy.InsertCompany(companyDetail); var contact = GetContact(); var contactResponse = contactProxy.InsertContact(contact); contactAggregate.Id = contactResponse.DataObject.InsertedContactId; contactAggregate.LastUpdatedId = contactResponse.DataObject.LastUpdatedId.ToLower(); contactAggregate.Company.Id = companyResponse.DataObject.InsertedCompanyId; contactAggregate.Company.LastUpdatedId = companyResponse.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 updatedCompany = companyProxy.GetCompany(companyResponse.DataObject.InsertedCompanyId); Assert.AreEqual(companyResponse.DataObject.LastUpdatedId, updatedCompany.DataObject.LastUpdatedId); }
public void ShouldInsertCompany() { var proxy = new CompanyProxy(); var company = GetTestCompany(); var insertResponse = proxy.InsertCompany(company); Assert.True(insertResponse.IsSuccessfull); Assert.Equal(insertResponse.StatusCode, HttpStatusCode.OK); Assert.True(insertResponse.DataObject.InsertedCompanyId > 0); var insertedCompany = proxy.GetCompany(insertResponse.DataObject.InsertedCompanyId).DataObject; Assert.True(!string.IsNullOrEmpty(insertedCompany.Abn), "Company ABN not saved"); Assert.Equal(insertedCompany.Abn, company.Abn); Assert.True(!string.IsNullOrEmpty(insertedCompany.CompanyEmail), "Company email not saved"); Assert.Equal(insertedCompany.CompanyEmail, company.CompanyEmail); Assert.True(!string.IsNullOrEmpty(insertedCompany.LongDescription), "Company description not saved"); Assert.Equal(insertedCompany.LongDescription, company.LongDescription); Assert.True(!string.IsNullOrEmpty(insertedCompany.TradingName), "Company trading name not saved"); Assert.Equal(insertedCompany.TradingName, company.TradingName); Assert.True(!string.IsNullOrEmpty(insertedCompany.Website), "Company website not saved"); Assert.Equal(insertedCompany.Website, company.Website); Assert.True(!string.IsNullOrEmpty(insertedCompany.LastUpdatedId), "Company LastUpdatedId not returned"); Assert.NotNull(insertedCompany.CreatedDateUtc); Assert.NotNull(insertedCompany.LastModifiedDateUtc); Assert.NotNull(insertedCompany.LastModifiedByUserId); }
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"); }
public (CompanyDetail CompanyDetail, int CompanyId) CreateCompany(string companyName = null) { var fakerCompany = new Faker <CompanyDetail>("en_AU") .RuleFor(c => c.Name, (f, c) => companyName ?? f.Company.CompanyName()) .RuleFor(c => c.TradingName, (f, c) => c.Name + " " + f.Company.CompanySuffix()) .RuleFor(c => c.CompanyEmail, (f, c) => f.Internet.Email(c.Name)) .RuleFor(c => c.Website, (f, c) => f.Internet.Url()) .RuleFor(c => c.Abn, f => f.Random.Long(100000000, 99999999).ToString()) .RuleFor(c => c.LongDescription, (f, c) => f.Company.CatchPhrase()); var company = fakerCompany.Generate(); var companyProxy = new CompanyProxy(); var response = companyProxy.InsertCompany(company); Assert.True(response.IsSuccessfull, "Failed to create organization for customer contact test data."); return(company, response.DataObject.InsertedCompanyId); }
public void ShouldDeleteCompany() { var proxy = new CompanyProxy(); var company = GetTestCompany(); var insertResponse = proxy.InsertCompany(company); Assert.IsTrue(insertResponse.IsSuccessfull); Assert.Greater(insertResponse.DataObject.InsertedCompanyId, 0); var deleteResponse = proxy.DeleteCompany(insertResponse.DataObject.InsertedCompanyId); Assert.IsTrue(deleteResponse.IsSuccessfull); var deletedCompany = proxy.GetCompany(insertResponse.DataObject.InsertedCompanyId); Assert.IsNull(deletedCompany.DataObject); Assert.AreEqual(HttpStatusCode.NotFound, deletedCompany.StatusCode); }
/// <summary> /// Add fictious customer contact. Currently have to use old Rest client API to insert record as this functionality not available in Web API yet. /// </summary> public int GetOrCreateContactCustomer() { var proxy = new ContactProxy(); var searchProxy = new ContactsProxy(); var companyProxy = new CompanyProxy(); var response = searchProxy.GetContacts(givenName: "carl", familyName: "o'neil", isCustomer: true, organisationName: "o'neil capital"); if (response.IsSuccessfull && response.DataObject.Contacts.Any()) { return(response.DataObject.Contacts[0].Id.GetValueOrDefault()); } var cResult = companyProxy.InsertCompany(new CompanyDetail() { Name = "O'Neil Capital" }); Assert.True(cResult.IsSuccessfull, "Failed to create organization for customer contact test data."); var contact = new Contact() { Salutation = "Mr.", GivenName = "Carl", FamilyName = "O'Neil", ContactId = "GLD879", CustomField1 = "O'NeilC", IsCustomer = true, Tags = new List <string>() { "carlTag1", "carlTag2" }, EmailAddress = "*****@*****.**", CompanyId = cResult.DataObject.InsertedCompanyId }; var result = proxy.InsertContact(contact); Assert.True(result.IsSuccessfull, "Failed to add customer contact test data."); return(result.DataObject.InsertedContactId); }
public int GetOrCreateContactCustomer(string firstName, string lastName, string organisationName, string email) { var proxy = new ContactProxy(); var searchProxy = new ContactsProxy(); var companyProxy = new CompanyProxy(); var response = searchProxy.GetContacts(givenName: firstName, familyName: lastName, isCustomer: true, organisationName: organisationName); if (response.IsSuccessfull && response.DataObject.Contacts.Any()) { return(response.DataObject.Contacts[0].Id.GetValueOrDefault()); } var cResult = companyProxy.InsertCompany(new CompanyDetail() { Name = organisationName }); Assert.True(cResult.IsSuccessfull, "Failed to create organization for customer contact test data."); var contact = new Contact() { GivenName = firstName, FamilyName = lastName, //ContactId = "GLD879", IsCustomer = true, Tags = new List <string>() { $"{firstName}Tag1", $"{lastName}Tag2" }, EmailAddress = email, CompanyId = cResult.DataObject.InsertedCompanyId }; var result = proxy.InsertContact(contact); Assert.True(result.IsSuccessfull, "Failed to add customer contact test data."); return(result.DataObject.InsertedContactId); }
public void ShouldUpdateCompany() { var proxy = new CompanyProxy(); var company = GetTestCompany(); var insertResponse = proxy.InsertCompany(company); Assert.IsTrue(insertResponse.IsSuccessfull); Assert.AreEqual(HttpStatusCode.OK, insertResponse.StatusCode); Assert.Greater(insertResponse.DataObject.InsertedCompanyId, 0); var insertedCompany = proxy.GetCompany(insertResponse.DataObject.InsertedCompanyId).DataObject; insertedCompany.LongDescription = "Modified company"; insertedCompany.Abn = "123456789"; insertedCompany.CompanyEmail = "updated@[email protected]"; insertedCompany.TradingName = "Updated Trading Name"; insertedCompany.Name = "Updated Name"; insertedCompany.Website = "http://updated.com"; var updateResponse = proxy.UpdateCompany(insertedCompany, insertResponse.DataObject.InsertedCompanyId); Assert.IsTrue(updateResponse.IsSuccessfull); Assert.AreEqual(insertResponse.DataObject.InsertedCompanyId, updateResponse.DataObject.UpdatedCompanyId); var updatedCompany = proxy.GetCompany(updateResponse.DataObject.UpdatedCompanyId).DataObject; Assert.AreEqual(updatedCompany.Abn, insertedCompany.Abn, "Incorrect ABN"); Assert.AreEqual(updatedCompany.CompanyEmail, insertedCompany.CompanyEmail, "Incorrect Company email"); Assert.AreEqual(updatedCompany.LongDescription, insertedCompany.LongDescription, "Incorrect company description"); Assert.AreEqual(updatedCompany.TradingName, insertedCompany.TradingName, "Incorrect company trading name"); Assert.AreEqual(updatedCompany.Website, insertedCompany.Website, "Incorrect company website"); Assert.IsNotNullOrEmpty(updatedCompany.LastUpdatedId, "Company LastUpdatedId not returned"); Assert.IsNotNull(updatedCompany.CreatedDateUtc, "Company CreatedDateUtc not returned"); Assert.IsNotNull(updatedCompany.LastModifiedDateUtc, "Company LastModifiedDateUtc not returned"); Assert.IsNotNull(updatedCompany.LastModifiedByUserId, "Company LastModifiedByUserId not returned"); }
public void ShouldUpdateCompany() { var proxy = new CompanyProxy(); var company = GetTestCompany(); var insertResponse = proxy.InsertCompany(company); Assert.True(insertResponse.IsSuccessfull); Assert.Equal(insertResponse.StatusCode, HttpStatusCode.OK); Assert.True(insertResponse.DataObject.InsertedCompanyId > 0); var insertedCompany = proxy.GetCompany(insertResponse.DataObject.InsertedCompanyId).DataObject; insertedCompany.LongDescription = "Modified company"; insertedCompany.Abn = "123456789"; insertedCompany.CompanyEmail = "updated@[email protected]"; insertedCompany.TradingName = "Updated Trading Name"; insertedCompany.Name = "Updated Name"; insertedCompany.Website = "http://updated.com"; var updateResponse = proxy.UpdateCompany(insertedCompany, insertResponse.DataObject.InsertedCompanyId); Assert.True(updateResponse.IsSuccessfull); Assert.Equal(updateResponse.DataObject.UpdatedCompanyId, insertResponse.DataObject.InsertedCompanyId); var updatedCompany = proxy.GetCompany(updateResponse.DataObject.UpdatedCompanyId).DataObject; Assert.Equal(insertedCompany.Abn, updatedCompany.Abn); Assert.Equal(insertedCompany.CompanyEmail, updatedCompany.CompanyEmail); Assert.Equal(insertedCompany.LongDescription, updatedCompany.LongDescription); Assert.Equal(insertedCompany.TradingName, updatedCompany.TradingName); Assert.Equal(insertedCompany.Website, updatedCompany.Website); Assert.True(!string.IsNullOrEmpty(updatedCompany.LastUpdatedId), "Company LastUpdatedId not returned"); Assert.NotNull(updatedCompany.CreatedDateUtc); Assert.NotNull(updatedCompany.LastModifiedDateUtc); Assert.NotNull(updatedCompany.LastModifiedByUserId); }
/// <summary> /// Add fictious contractor contact. Currently have to use old Rest client API to insert record as this functionality not available in Web API yet. /// </summary> public int GetOrCreateContractorContact() { var proxy = new ContactProxy(); var searchProxy = new ContactsProxy(); var companyProxy = new CompanyProxy(); var response = searchProxy.GetContacts(givenName: "kathy", familyName: "o'neil", isCustomer: true, organisationName: "O'Neil Contractor"); if (response.IsSuccessfull && response.DataObject.Contacts.Any()) { return(response.DataObject.Contacts[0].Id.GetValueOrDefault()); } var cResult = companyProxy.InsertCompany(new CompanyDetail() { Name = "O'Neil Contractor" }); Assert.True(cResult.IsSuccessfull, "Failed to create organization for supplier contact test data."); var contact = new Contact() { Salutation = "Ms.", GivenName = "Kathy", FamilyName = "O'Neil", ContactId = "GLD882", CustomField1 = "O'NeilK", CompanyId = cResult.DataObject.InsertedCompanyId, IsContractor = true }; var result = proxy.InsertContact(contact); Assert.True(result.IsSuccessfull, "Failed to add contractor contact test data."); return(result.DataObject.InsertedContactId); }
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); }