我已经实现了Content Provider,它从网络上安装的服务中检索数据.内容提供程序从共享首选项(用户凭据,应用程序名称等)中获取所需参数
SharedPreferences settings = getContext().getSharedPreferences(NET_PREFS, 0);
Run Code Online (Sandbox Code Playgroud)
我对此内容提供商使用单元测试:
public class ResearchProviderTest extends ProviderTestCase2<MyProvider>{
public ResearchProviderTest() {
super(MyProvider.class, MyProvider.CONTENT_AUTHORITY);
}
public void testInsert() {
ContentValues values = new ContentValues();
values.put(QueryFields.FIELD_QUERY_TEXT, "query" );
Uri newUri = getMockContentResolver().insert(MyProvider.CONTENT_URI, values);
Cursor readMessagesCursor = getMockContentResolver().query(
newUri ,
new String[] { FIELD_SR_TITLE },
null, null, null );
assertTrue("The cursor should contain some entries", readMessagesCursor.moveToFirst());
}
}
Run Code Online (Sandbox Code Playgroud)
在执行单元测试期间.抛出异常:
java.lang.UnsupportedOperationException
at android.test.mock.MockContext.getSharedPreferences(MockContext.java:127)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:146)
at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:146)
at com.company.mobile.android.net.RemoteExecutor.retrieveCredentials(RemoteExecutor.java:171)
at com.company.mobile.android.net.service.Adapter.executeSearch(Adapter.java:33)
at com.company.mobile.android.provider.MyProvider.insert(MyProvider.java:167)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:174)
...
Run Code Online (Sandbox Code Playgroud)
有人知道如何将共享首选项传递给MockContext吗?如果在测试Content Provider期间需要Context,我应该使用其他方法吗?
我正在尝试用C#编写函数,将JSON转换为键/值对.它应该支持数组.例如,以下JSON:
{
title: title_value,
components: [
{
component_id: id1,
menu: [
{title: menu_title1},
{title: menu_title_x},
{id: menu_id1}
]
},
{
component_id: id2,
menu: [
{title: menu_title2},
{id: menu_id2}
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
应转换为:
这是完成这项任务的简单方法吗?当我开始考虑数组和嵌套数组时,逻辑变得复杂.
我需要检查现有的Web应用程序是否已准备好部署在集群环境中.
集群:
几个Linux机器.该流程由负载均衡器控制,该负载均衡器使用具有粘性会话的简单循环算法.
应用程序
无状态(希望)java Web应用程序,它从后台检索内容并对其进行适当格式化.
我可以访问源代码.我应该检查代码以确保它将在群集中运行?
我打算用PhoneGap编写移动应用程序.
我的问题是:Java脚本(带有业务逻辑)是否应该打包到分发包中.如果业务逻辑更新,我需要它以避免重新提交应用程序到App Store.
所以在主要的html中我包含了PhoneGap JS,我可以包含远程JS吗?
<script type="text/javascript" charset="utf-8" src="phonegap.0.9.5.1.js" />
<script type="text/javascript" charset="utf-8" src="http://remote.server.com/main.js" />
Run Code Online (Sandbox Code Playgroud) 据我所知,Apple将推送通知有效负载限制为256字节,Windows Phone将其限制为3KB.
Azure Notification Hub是否为此限制提供了一些解决方法?
如果向Apple设备发送通知并且其有效负载超过256字节,则通知中心的预期行为是什么?
在检查LINQ的能力时,我编写了简单的QuickSort实现,
很高兴最终快速排序功能适合一行.
但是我注意到这个"一行"功能的性能与我原来的"直接"版本有很大不同.
这是在循环中调用快速排序函数10次的代码:
var r = new Random(DateTime.Now.Millisecond);
Stopwatch watch = new Stopwatch();
for (int i = 0; i < 10; i++)
{
watch.Reset();
var randomA = new int[100].Select(x => r.Next(100)).ToList();
watch.Start();
var sorted = QuickSort<int>(randomA);
watch.Stop();
Console.WriteLine("Duration: {0} ms", watch.ElapsedMilliseconds);
}
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
两个QuickSort函数的实现与输出结果:
简单版本:
IEnumerable<T> QuickSort<T>(IEnumerable<T> a) where T : IComparable<T>
{
if (a.Count() <= 1) return a;
var pivot = a.First();
IEnumerable<T> lesser = a.Skip(1).Where(x => x.CompareTo(pivot) < 0);
IEnumerable<T> bigger = a.Skip(1).Where(x => x.CompareTo(pivot) >= 0); …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建管理用户和用户角色的简单ExtJs应用程序.一组REST服务在后端提供此功能.当我为用户分配新角色时,相应的数据存储会向服务发送POST(创建)请求.但是,当我从用户中删除现有角色时,它仅从本地存储中删除,而不向服务发送DELETE请求.这是我的代码:
模型:
Ext.define('UserRole', {
extend: 'Ext.data.Model',
fields: [
{ name: 'Id', mapping: "Id" },
{ name: 'RoleId', mapping: "RoleId" },
{ name: 'UserId', mapping: "UserId" }
]
});
Run Code Online (Sandbox Code Playgroud)
使用代理存储:
Ext.define('UserRoleStore', {
extend: 'Ext.data.Store',
model: 'UserRole',
autoload: false,
proxy: {
type: 'ajax',
reader: {
type: 'json',
root: 'd.results'
},
api: {
read: '/accessmanager.svc/Users(\'{userid}\')/Roles?$format=json',
create: '/accessmanager.svc/UserRoles?$format=json',
update: '/accessmanager.svc/UserRoles?$format=json',
destroy: '/accessmanager.svc/UserRoles?$format=json'
},
updateApiUrlWithUserId: function (userId) {
this.api.read = this.api.read.replace('{userid}', userId);
}
}
});
Run Code Online (Sandbox Code Playgroud)
基于所选复选框的方法更新UserRole存储
var chekboxes = Ext.ComponentQuery.query('userdetails #roleslist')[0];
var selectedUserId = this.selectedUserId; …Run Code Online (Sandbox Code Playgroud)