如何在TypeScript中为可测试的Dynamics CRM表单编写类?
通过testable,我的意思是一个非静态类,可以实例化并传递一个模拟Xrm对象.
我目前的方法是这样的,但它有局限性(我解释):
export class Contact {
Xrm: Xrm.XrmStatic;
constructor(xrm?: Xrm.XrmStatic) {
this.Xrm = xrm;
}
onLoad(): void {
if (this.Xrm) { Xrm = this.Xrm; }
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
首先,Contact
导出类以便可以通过CRM表单引用.CRM在调用它的函数之前无法实例化对象,因此要调用这些方法,我在CRM表单设计器中使用Contact.prototype.onLoad.
我的测试看起来像这样:
beforeEach(function () {
this.XrmMock = new XrmStaticMock();
this.contact = new Contact(this.XrmMock);
this.contact.onLoad();
}
it('does stuff', function () {
// ...
}
Run Code Online (Sandbox Code Playgroud)
测试能够实例化Contact
并传递XrmMock
给构造函数.随后onLoad()
调用时,它的计算结果if (this.Xrm)
为true,并使用XrmMock
.相反,当Contact.prototype.onLoad()
从CRM内部调用时,它(this.Xrm)
是假的,因为Contact
从未实例化过.因此,对Xrm
within的任何引用都onLoad()
使用默认Xrm
命名空间(这是我们想要的).我们想要这个,因为当打开CRM表单时, …
我使用 Semantic UI React创建了一个图像元素。
<Image floated="right" size="mini" src="/someImageUrl.png" />
Run Code Online (Sandbox Code Playgroud)
如果图像的src
属性未加载,则会显示损坏的图像占位符。
当我的图像未加载时,如何隐藏这个损坏的图像占位符而不显示图像?
我已经尝试按照这个 StackOverflow 答案中的答案进行操作,该答案建议使用
<Image src="Error.src" onerror="this.style.display='none'"/>
Run Code Online (Sandbox Code Playgroud)
但我收到错误 Expected 'onError' listener to be a function.
我正在尝试使用Angular创建一个可以通过Web API连接到Dynamics CRM的应用程序.这些是我遵循的步骤:
1.在Azure中注册本机应用程序,授予所需的委派权限并更新清单以允许隐式流.
2.在CRM中创建应用程序用户,将其应用程序ID设置为等于我的Azure注册应用程序的客户端ID.为我的应用程序用户分配了自定义安全角色.
3.克隆了许多Angular 2快速启动Git存储库,这些存储库通过ADAL(例如此 ADAL)通过Azure AD进行身份验证.
4.更新了克隆代码的阿达尔配置,设置我的tenant
,clientId
,redirectUri
和endpoints
.
到目前为止,这已经成功了.我可以通过我的浏览器启动应用程序并登录,作为我的应用程序用户或作为Azure AD一部分的其他CRM用户.这会返回一个令牌.
5.尝试发送http.get
要么v8.0
或v8.2
(有人告诉我v8.2
不支持跨域调用的):
getEntities(): Promise<any> {
let token = this.adalService.getCachedToken(this.adalService.config.clientId);
let headers = new Headers({
'Authentication': 'Bearer ' + token,
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'OData-MaxVersion': '4.0',
'OData-Version': '4.0'
});
let options = new RequestOptions({ headers: headers });
return this.http.get(`${crmURL}/api/data/v8.2/accounts`, options)
.toPromise()
.then((res) => { return res; }) …
Run Code Online (Sandbox Code Playgroud) 我有一个用于通过非交互式登录从我的Nodejs客户端调用CRM API的用例.为此,我在Azure Active Directory上注册我的应用程序后生成了客户端密钥和密钥.我成功生成访问令牌,但无论何时我尝试访问数据(通过Microsoft OData客户端或直接Web API HTTP请求),我总是会收到401,尽管在授权标头中包含了我的访问令牌.这是我的Nodejs客户端:
var adal = require('adal-node');
var azure = require('azure');
var express = require('express');
var https = require('https');
var app = express();
var AuthenticationContext = adal.AuthenticationContext;
var authorityHostUrl = 'https://login.microsoftonline.com';
var tenant = 'xxxx.onmicrosoft.com';
var authorityUrl = authorityHostUrl + '/' + tenant;
var clientId = 'xxxx';
var clientSecret = 'xxxx'
var resource = 'https://xxxx.crm.dynamics.com';
var context = new AuthenticationContext(authorityUrl);
var accessToken;
var credentials;
context.acquireTokenWithClientCredentials(resource, clientId, clientSecret, function(err, tokenResponse) {
if (err) {
console.log('well that didn\'t …
Run Code Online (Sandbox Code Playgroud) 如果我有一个带有n
可选参数的构造函数并且我只想为最后一个可选参数传递一个值,我必须传递undefined
n-1
时间。
例如:
class House() {
constructor(door?, roof?, windows?) { }
}
Run Code Online (Sandbox Code Playgroud)
如果我想实例化一个House
没有 adoor
或 aroof
但有的new windows
,我必须undefined
两次传递给构造函数:
let myHouse = new House(undefined, undefined, new Windows());
Run Code Online (Sandbox Code Playgroud)
C# 有命名参数,这在这里很理想。
undefined
n-1
在这种情况下,我如何避免通过时间?
我们知道Dynamics CRM具有特定的属性值:Customer.此值组合了客户端和帐户实体,但我是盲人或MSDN没有关于在查询中检索此字段的规范.例如:
QueryByAttribute query = new QueryByAttribute(entName);
query.ColumnSet = new ColumnSet(new String[] { searchAttr });
query.Attributes.Add(searchAttr);
query.Values.Add(searchValue);
EntityCollection retrived = service.RetrieveMultiple(query);
Run Code Online (Sandbox Code Playgroud)
此代码接受实体名称并搜索属性的名称和值,但是当我运行它时,我不知道从DataSouce中获取哪种类型的实体:客户端或帐户.所以问题是:是否可以在一个查询中检索Customer实体?
dynamics-crm ×4
azure ×2
typescript ×2
adal ×1
angular ×1
crm ×1
html ×1
image ×1
javascript ×1
parameters ×1
reactjs ×1
semantic-ui ×1
testing ×1
undefined ×1