public async Task CreateAsync_When_Present_DateTime_Property_Then_Ok() { const string propertyName = "finaldecisiondate"; var propertyValue = DateTime.Now.Date.ToUniversalTime(); var opportunity = new Entity("opportunity"); opportunity.SetAttributeValue(propertyName, propertyValue); EntityReference opportunityRef = default; try { var opportunityId = await CrmClient.CreateAsync(opportunity); opportunityId.Should().NotBeEmpty(); opportunityRef = new EntityReference("opportunity", opportunityId); var opportunityFormDb = await CrmClient.RetrieveAsync(opportunityRef, QueryOptions.Select(propertyName)); var actualDate = opportunityFormDb.GetAttributeValue <DateTime>(propertyName); actualDate.Should().Be(propertyValue); } finally { if (opportunityRef != null) { await CrmClient.DeleteAsync(opportunityRef); } } }
public async Task RetrieveMultipleAsync_FetchXml_Pagination_Correct(int page, string pagingCookie) { var pageNumber = page; var nextPage = (pageNumber + 1); const int pageSize = 3; var fetchData = new { caseorigincode = "899090003", caseorigincode2 = "930660005", caseorigincode3 = "930660000" }; var cookie = string.Empty; if (!string.IsNullOrEmpty(pagingCookie)) { cookie = $"paging-cookie='{System.Net.WebUtility.HtmlEncode(pagingCookie)}'"; } //output-format='xml-platform' mapping='logical' var fetchXml = $@" <fetch no-lock='true' distinct='true' count='{pageSize}' page='{pageNumber}' {cookie}> <entity name='incident'> <order attribute='incidentid' /> <attribute name='createdon' /> <attribute name='statuscode' /> <attribute name='customerid' /> <attribute name='incidentid' /> <link-entity name='account' from='accountid' to='customerid' link-type='outer'> <attribute name='telephone2' /> <attribute name='address1_telephone1' /> <attribute name='telephone3' /> <attribute name='telephone1' /> <attribute name='createdby' /> <attribute name='modifiedby' /> <attribute name='accountnumber' /> <attribute name='accountid' /> </link-entity> <filter type='and'> <condition attribute='caseorigincode' operator='in'> <value>{fetchData.caseorigincode /*899090003*/}</value> <value>{fetchData.caseorigincode2 /*930660005*/}</value> <value>{fetchData.caseorigincode3 /*930660000*/}</value> </condition> </filter> </entity> </fetch>"; var collection = await CrmClient.RetrieveMultipleAsync(new FetchXmlExpression(fetchXml)); collection.PagingCookie.Should().StartWith($"<cookie page=\"{pageNumber}\"><incidentid last=\""); collection.EntityName.Should().Be("incident"); collection.MoreRecords.Should().BeTrue(); collection.Entities.Count.Should().Be(pageSize); collection.Entities.First().GetAttributeValue <Guid>("account1.createdby").Should().NotBeEmpty(); collection.Entities.First().LogicalName.Should().Be("incident"); }
private async Task <SetCustomerResponse> SetCustomer(CrmClient client, GetCustomerResponse customer) { var now = DateTime.Now; var accountNumber = (string)customer.Rows[0].Columns["PRIMARYPOSREF"]; var setCustomer = await client.SetCustomerAsync(customer.Rows.Single().Id, new[] { new ColumnValue("firstname", "Rubber"), new ColumnValue("lastname", now.ToString()), }); var getCustomerUpdated = await GetCustomer(client, accountNumber); var lastname = (string)getCustomerUpdated.Rows.Single().Columns["LASTNAME"]; // UNDOCUMENTED: updating account to ACTIVE = false doesn't cause // the SetCustomer API call to fail or the account state to change. // Oracle Hospitality carries out the update and returns Approved // response code to client. But the web UI remains frozen in that it // doesn't show updated values, but remains stuck on the value at // the time of closing. Only clicking an account will show the // updated name (likely a bug in Web UI). In order to change the // account state, one must use the PostAccountTransaction // transaction. The ACTIVE attribute value is likely replicated from // somewhere else by the backend and therefore any updated to it are // ignored. Assert.Equal(getCustomerUpdated.Rows[0].Id, setCustomer.RowId); Assert.Equal( new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second), DateTime.Parse(lastname)); return(setCustomer); }
public async Task CreateAsync_When_Present_Money_Property_Then_Ok() { const string propertyName = "budgetamount"; const double propertyValue = 123.15d; var opportunity = new Entity("opportunity") { [propertyName] = propertyValue }; EntityReference opportunityRef = null; try { var opportunityId = await CrmClient.CreateAsync(opportunity); opportunityId.Should().NotBeEmpty(); opportunityRef = new EntityReference("opportunity", opportunityId); var opportunityFormDb = await CrmClient.RetrieveAsync(opportunityRef, QueryOptions.Select(propertyName)); var actualBudged = opportunityFormDb.GetAttributeValue <double>(propertyName); actualBudged.Should().Be(propertyValue); } finally { if (opportunityRef != null) { await CrmClient.DeleteAsync(opportunityRef); } } }
public async Task program_id_on_valid_account() { const string response = @" <CRMMessage language=""en_US"" currency=""DKK"" isTrustedSAT=""false"" hostversion=""1.00""> <RequestCode>GetAccount</RequestCode> <ResponseCode>A</ResponseCode> <ResultSet> <ResultSetMetaData> <RSColumn name=""programid"" type=""long"" nullable=""false""></RSColumn> </ResultSetMetaData> <Rows> <Row id=""106632""> <Col>14631</Col> </Row> </Rows> </ResultSet> </CRMMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new CrmClient(_options, executor); var actual = await sut.GetAccountAsync( "accountposref = ?", new[] { new ColumnValue("accountposref", "123") }, new[] { new Column("programid") }); Assert.Single(actual.Rows); Assert.Equal(106632, actual.Rows[0].Id); Assert.Equal(14631, (long)actual.Rows[0].Columns["programid"]); }
public async Task error_on_invalid_programid() { const string response = @" <CRMMessage language=""en_US"" currency=""DKK"" isTrustedSAT=""false"" hostversion=""1.00""> <RequestCode>GetProgram</RequestCode> <ResponseCode>A</ResponseCode> <ResultSet> <ResultSetMetaData> <RSColumn name=""programcode"" type=""string"" nullable=""true""></RSColumn> </ResultSetMetaData> <Rows></Rows> </ResultSet> </CRMMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new CrmClient(_options, executor); var actual = await sut.GetProgramAsync( "programid = ?", new[] { new ColumnValue("programid", "123") }, new[] { new Column("programcode") }); Assert.Empty(actual.Rows); }
public async Task update_failed_on_invalid_account() { const string response = @" <CRMMessage language=""en_US"" currency=""DKK"" hostversion=""1.00""> <RequestCode>SetCustomer</RequestCode> <ResponseCode>D</ResponseCode> <DisplayMessage>com.micros.storedValue.worker.SetRollbackException: Update failed for row ID = 123</DisplayMessage> </CRMMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new CrmClient(_options, executor); var e = await Assert.ThrowsAsync <OracleHospitalityClientException>( () => sut.SetCustomerAsync( 123, new[] { new ColumnValue("firstname", "Rubber"), new ColumnValue("lastname", "Duck") })); Assert.Contains("Update failed for row ID = 123", e.Message); }
public async Task CreateAsync_When_Present_DateOnly_Property_Then_Ok() { const string propertyName = "birthdate"; var propertyValue = new DateTime(2020, 09, 17); var contact = new Entity("contact"); contact.SetAttributeValue(propertyName, propertyValue); EntityReference contactRef = default; try { var id = await CrmClient.CreateAsync(contact); id.Should().NotBeEmpty(); contactRef = new EntityReference("contact", id); var contactFromDb = await CrmClient.RetrieveAsync(contactRef, QueryOptions.Select(propertyName)); var actualValue = contactFromDb.GetAttributeValue <DateTime>(propertyName); actualValue.Should().Be(propertyValue); } finally { if (contactRef != null) { await CrmClient.DeleteAsync(contactRef); } } }
public async Task RetrieveAsync_When_DateOnly_Attribute_Then_Correct_DateValue() { var contact = new Entity("contact") { ["birthdate"] = new DateTime(1986, 12, 21, 00, 00, 00) }; var id = await CrmClient.CreateAsync(contact); var contactReference = new EntityReference("contact", id); var contactFields = QueryOptions.Select("birthdate"); var entity = await CrmClient.RetrieveAsync(contactReference, contactFields); try { entity.Should().NotBeNull(); var birthDate = entity.GetAttributeValue <DateTime>("birthdate"); birthDate.Date.Should().Be(new DateTime(1986, 12, 21)); birthDate.TimeOfDay.Should().Be(new TimeSpan()); birthDate.Kind.Should().Be(DateTimeKind.Unspecified); } finally { if (!Guid.Empty.Equals(id)) { await CrmClient.DeleteAsync(new EntityReference("contact", id)); } } }
/// <summary> /// Initialize SearchCaseByAccountNameDialog. /// </summary> /// <param name="crmClient">CRM client for interacting with CRM</param> /// <param name="entityCache">List of entities in the cache</param> /// <param name="query">Query</param> /// <param name="days">Days</param> public SearchCaseByAccountNameDialog(CrmClient crmClient, ICache <string, List <IEntity> > entityCache, string query, int days = 3) { this.query = query; this.crmClient = crmClient; this.previousDays = days; this.entityCache = entityCache; }
public async Task ExecuteAsync_WinOpportunityRequest_When_Caller_Is_Null_Then_Ok() { var opportunityId = new Guid("{5D0E46CA-49F1-EA11-AAF2-005056B42CD8}"); var opportunityEntityRef = new EntityReference(OpportunityEntityName, opportunityId); await CrmClient.CreateAsync(new Entity(OpportunityEntityName, opportunityId)); var opportunityCloseEntity = new Entity("opportunityclose"); opportunityCloseEntity.SetAttributeValue("subject", "Won Opportunity"); opportunityCloseEntity.SetAttributeValue("opportunityid", opportunityEntityRef); var action = new WinOpportunityRequest() { OpportunityClose = opportunityCloseEntity, Status = 3 }; try { await CrmClient.ExecuteAsync(action); } finally { await CrmClient.DeleteAsync(opportunityEntityRef); } }
public async Task invalid_account_returns_empty_row_set() { const string response = @" <CRMMessage language=""en_US"" currency=""DKK"" isTrustedSAT=""false"" hostversion=""1.00""> <RequestCode>GetCustomer</RequestCode> <ResponseCode>A</ResponseCode> <ResultSet> <ResultSetMetaData> <RSColumn name=""firstname"" type=""string"" nullable=""true""></RSColumn> <RSColumn name=""lastname"" type=""string"" nullable=""true""></RSColumn> </ResultSetMetaData> <Rows></Rows> </ResultSet> </CRMMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new CrmClient(_options, executor); var actual = await sut.GetCustomerAsync( "primaryposref = ?", new[] { new ColumnValue("primaryPOSRef", "doesNotMatter") }, new[] { new Column("firstname"), new Column("lastname") }); Assert.Equal(2, actual.MetaData.Length); Assert.Empty(actual.Rows); }
public async Task valid_account_with_multiple_customers() { // If we create multiple customers and associate each with the same // account, response becomes as below. const string response = @" <CRMMessage language=""en_US"" currency=""DKK"" isTrustedSAT=""false"" hostversion=""1.00""> <RequestCode>GetCustomer</RequestCode> <ResponseCode>A</ResponseCode> <ResultSet> <ResultSetMetaData> <RSColumn name=""firstname"" type=""string"" nullable=""true""></RSColumn> <RSColumn name=""lastname"" type=""string"" nullable=""true""></RSColumn> </ResultSetMetaData> <Rows> <Row id=""416440""> <Col>John</Col> <Col>Doe</Col> </Row> <Row id=""422056""> <Col /> <Col /> </Row> <Row id=""456663""> <Col>Rubber</Col> <Col>Duck</Col> </Row> </Rows> </ResultSet> </CRMMessage>"; var handler = CreateMockMessageHandler(HttpStatusCode.OK, CreateSoapResponse(response.Trim())); var executor = new OracleHospitalityExecutor(_options, _executorLogger, new HttpClient(handler)); var sut = new CrmClient(_options, executor); var actual = await sut.GetCustomerAsync( "primaryposref = ?", new[] { new ColumnValue("primaryPOSRef", "doesNotMatter") }, new[] { new Column("firstname"), new Column("lastname") }); Assert.Equal(3, actual.Rows.Length); var r0 = actual.Rows[0]; Assert.Equal(416440, r0.Id); Assert.Equal("John", r0.Columns["firstname"]); Assert.Equal("Doe", r0.Columns["lastname"]); var r1 = actual.Rows[1]; Assert.Equal(422056, r1.Id); Assert.Null(r1.Columns["firstname"]); Assert.Null(r1.Columns["lastname"]); var r2 = actual.Rows[2]; Assert.Equal(456663, r2.Id); Assert.Equal("Rubber", r2.Columns["firstname"]); Assert.Equal("Duck", r2.Columns["lastname"]); }
public async Task ExecuteFunctionAsync_When_Function_WhoAmi_OrganizationId_Ok() { var response = await CrmClient.ExecuteAsync(new WhoAmIRequest()); response.OrganizationId.Should().Be(Setup.OrganizationId); response.BusinessUnitId.Should().NotBeEmpty(); response.UserId.Should().NotBeEmpty(); }
public async Task RetrieveAsync_When_Expand_Then_Retrieved_NestedEntity_Correct() { var account = new Account() { ["primarycontactid"] = new Entity("contact") { ["firstname"] = "[Test] First Name", ["lastname"] = "[Test] Last Name", } }; var accountId = await CrmClient.CreateAsync(account); var accountFiled = new[] { "*" // Only not NULL attributes }; var contactFiled = new[] { "ownerid", "statecode", "firstname", "fullname", "birthdate" }; var options = QueryOptions .Select(accountFiled) .Expand("primarycontactid", contactFiled); EntityReference accountReference = Account.Reference(accountId); EntityReference contactRef = null; try { var complexAccountEntity = await CrmClient.RetrieveAsync(accountReference, options); complexAccountEntity.Should().NotBeNull(); var contactEntity = complexAccountEntity.GetAttributeValue <Entity>("primarycontactid"); contactEntity .Should().NotBeNull(); contactEntity.GetAttributeValue <string>("firstname") .Should().Be("[Test] First Name"); contactEntity.Id .Should().NotBeEmpty(); contactRef = contactEntity.ToEntityReference(); } finally { await CrmClient.DeleteAsync(accountReference); if (contactRef != null) { await CrmClient.DeleteAsync(contactRef); } } }
public async Task RetrieveAsync_When_Select_Only_Id_Then_Ok() { var options = QueryOptions.Select("organizationid"); var entity = await CrmClient.RetrieveAsync("organization", Setup.OrganizationId, options); entity.Should().NotBeNull(); entity.Id.Should().Be(Setup.OrganizationId); entity.LogicalName.Should().Be("organization"); }
private async Task <GetCouponsResponse> GetCoupons(CrmClient client, string accountNumber) { return(await client.GetCouponsAsync( "accountposref = ?", new[] { new ColumnValue("accountposref", accountNumber) })); }
public async Task When_LocaleId_Is_Equal_0_ThrowException() { var localeId = 0; Func <Task> invoker = async() => { await CrmClient.GetAllTimeZonesWithDisplayNameAsync(localeId, CancellationToken.None); }; var assert = await invoker.Should().ThrowAsync <WebApiException>() .WithMessage("An unexpected error occurred."); }
public async Task RetrieveAsync_When_ColumnsSet_IsNull_Then_Only_Id_Returned() { var entity = await CrmClient.RetrieveAsync("organization", Setup.OrganizationId); entity.Should().NotBeNull(); entity.Id.Should().Be(Setup.OrganizationId); entity.LogicalName.Should().Be("organization"); entity.Attributes.Count.Should().BeLessOrEqualTo(1); entity.Attributes.ContainsKey("organizationid").Should().BeTrue(); }
public async Task RetrieveAsync_When_Select_ModifiedBy_Then_EntityReference_Correct() { var options = QueryOptions.Select("modifiedby"); var entity = await CrmClient.RetrieveAsync("organization", Setup.OrganizationId, options); entity.Should().NotBeNull(); entity.GetAttributeValue <EntityReference>("modifiedby").Should().NotBeNull(); entity.GetAttributeValue <EntityReference>("modifiedby").Id.Should().NotBeEmpty(); entity.GetAttributeValue <EntityReference>("modifiedby").LogicalName.Should().Be("systemuser"); }
public async Task SetCustomerCreateNewCustomerAndAssociateWithExistingAccountTest() { var client = new CrmClient(_options, _executor); var _ = await client.SetCustomerAsync(null, new[] { new ColumnValue("firstname", "Rubber"), new ColumnValue("lastname", "Duck"), new ColumnValue("sortvalue", "1"), new ColumnValue("primaryposref", "2200000") }); }
/// <summary> /// Initialize RootLuisDialog. /// </summary> /// <param name="client">CRM Client to interact with CRM</param> /// <param name="entityCache">List of cached entities</param> /// <param name="dialogFactory">Dialog factory</param> /// <param name="services">LUIS services</param> public RootLuisDialog(CrmClient client, ICache <string, List <IEntity> > entityCache, IDialogFactory dialogFactory, IAuthProvider authProvider, params ILuisService[] services) : base(services) { this.crmClient = client; this.entityCache = entityCache; this.dialogFactory = dialogFactory; this.authProvider = authProvider; }
public async Task When_LocaleId_Is_EN_Then_UserName_IsOK() { var localeId = 1033; var collection = await CrmClient.GetAllTimeZonesWithDisplayNameAsync(localeId, CancellationToken.None); collection?.Entities?.Should().NotBeNull(); var timezone = collection?.Entities?.FirstOrDefault(x => x.GetAttributeValue <int>("timezonecode") == 0); timezone.Should().NotBeNull(); timezone.GetAttributeValue <string>("userinterfacename") .Should().Be("(GMT-12:00) International Date Line West"); }
public async Task RetrieveAsync_When_Select_AllFields_Then_Ok() { var options = new QueryOptions() .Select(new ColumnSet { AllColumns = true }); var entity = await CrmClient.RetrieveAsync("organization", Setup.OrganizationId, options); entity.Should().NotBeNull(); entity.Id.Should().Be(Setup.OrganizationId); entity.LogicalName.Should().Be("organization"); entity.Attributes.Count.Should().BeGreaterThan(1); }
public async Task ExecuteAsync_AddMembersTeamRequest_When_OneUsersAdded_Then_Ok() { var unitTestsUserId = CrmClient.GetMyCrmUserId(); var userRef = new EntityReference(SystemUserEntityName, unitTestsUserId); var teamId = new Guid("a640a425-a463-ea11-aae8-005056b42cd8"); var action = new AddMembersTeamRequest(teamId) { Members = { userRef } }; await CrmClient.ExecuteAsync(action); }
public async Task Execute_QuerySchedule_When_Resource_Is_CurrentUser_Then_ResultOk() { var request = new QueryScheduleRequest() { ResourceId = CrmClient.GetMyCrmUserId(), Start = System.DateTime.Now.Date, End = System.DateTime.Now.Date.AddDays(1).AddSeconds(-1), TimeCodes = new TimeCode[] { TimeCode.Available } }; var response = await CrmClient.ExecuteAsync <QueryScheduleResponse>(request); response.TimeInfos.Should().NotBeNull(); response.TimeInfos.Should().NotBeEmpty(); }
private async Task <GetAccountResponse> GetAccount(CrmClient client, string accountNumber) { var columnList = await client.GetColumnListAsync("account"); var columnNames = columnList.Row.Columns.Select(c => new Column(c.Key)).ToArray(); var account = await client.GetAccountAsync( "accountposref = ?", new[] { new ColumnValue("accountposref", accountNumber) }, columnNames); InferMetaDataToFieldSpecifications(account.MetaData, columnList.Row.Columns); Assert.Single(account.Rows); Assert.Equal(accountNumber, account.Rows[0].Columns["ACCOUNTPOSREF"]); return(account); }
private async Task <PostAccountTransactionResponse> FlipAccountState(CrmClient client, GetCustomerResponse customer, GetProgramResponse program) { var accountNumber = (string)customer.Rows[0].Columns["PRIMARYPOSREF"]; var accountState = (bool)customer.Rows[0].Columns["ACTIVE"]; var programCode = (string)program.Rows[0].Columns["PROGRAMCODE"]; var kind = accountState ? Type.Kind.CloseAccount : Type.Kind.ReopenAccount; var transaction = new CloseReopenTransactionBuilder() .WithType(kind) .WithCustomerFriendlyDescription("Updated by test") .WithProgramCode(programCode) .WithAccountPosRef(accountNumber); return(await client.PostAccountTransactionAsync(transaction)); }
public async Task ExecuteAsync_AddMembersTeamRequest_When_MultipleUsersAdded_Then_Ok() { var unitTestsUserId = new Guid("{9A8A23B4-07DB-EA11-AAF0-005056B42CD8}"); var otherUserId = new Guid("a988c6a2-5236-ea11-aadc-005056b42cd8"); var testTeamId = new Guid("a640a425-a463-ea11-aae8-005056b42cd8"); var userRef = new EntityReference(SystemUserEntityName, unitTestsUserId); var userRef1 = new EntityReference(SystemUserEntityName, otherUserId); var teamId = testTeamId; var action = new AddMembersTeamRequest(teamId) { Members = { userRef, userRef1 } }; var resp = await CrmClient.ExecuteAsync(action); }
private async Task <GetProgramResponse> GetProgram(CrmClient client, GetAccountResponse account) { var columnList = await client.GetColumnListAsync("program"); var columnNames = columnList.Row.Columns.Select(c => new Column(c.Key)).ToArray(); var programId = account.Rows[0].Columns["PROGRAMID"].ToString(); var program = await client.GetProgramAsync( "programid = ?", new[] { new ColumnValue("programid", programId) }, columnNames); InferMetaDataToFieldSpecifications(program.MetaData, columnList.Row.Columns); Assert.Single(program.Rows); Assert.Equal("EMPDISC", program.Rows[0].Columns["PROGRAMCODE"]); return(program); }