在Android应用中,以下方法有什么问题:
public class MyApp extends android.app.Application {
private static MyApp instance;
public MyApp() {
instance = this;
}
public static Context getContext() {
return instance;
}
}
Run Code Online (Sandbox Code Playgroud)
并传递它到处(例如SQLiteOpenHelper)需要上下文(当然不泄漏)?
我正在为我的应用添加更多的rspec测试,并希望测试一个ScoringMethods模块,它位于/lib/scoring_methods.rb中.所以我添加了一个/ spec/lib目录并在那里添加了scoring_methods_spec.rb.我需要spec_helper并设置describe块,如下所示:
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe ScoringMethods do
describe "should have scorePublicContest method" do
methods = ScoringMethods.instance_methods
methods[0].should match(/scorePublicContest/)
end
end
Run Code Online (Sandbox Code Playgroud)
现在methods[0]是一个String,并且公共方法名称与正则表达式匹配没有问题.而"spec_helper"的相对路径是正确的.
问题是整个设置似乎没有使用rspec库.运行示例产生:
./spec/lib/scoring_methods_spec.rb:7: undefined method `match' for Spec::Rails::Example::RailsExampleGroup::Subclass_1::Subclass_1:Class (NoMethodError)
...
Run Code Online (Sandbox Code Playgroud)
似乎缺少整个期望和匹配支持.为了测试我的假设,我通过将"is_instance_of"替换为"is_foobar_of"来更改了工作助手规范.该测试完全失败,并说"is_foobar_of"不是目标对象的方法; 它,整个Spec :: Rails :: Example ...层次结构不存在.
我也尝试过使用其他匹配器.我试过"be_instance_of"和其他一些人.好像我没有正确地包含rspec库.
最后,ScoringMethods是一个模块,就像Helpers是模块一样.所以我认为可以测试一个模块(而不是像控制器和模型这样的类).
我非常感谢你对我做错了什么的想法.也许有更有效的方法来测试库模块?谢谢!
我有一个Visual Studio 2008解决方案,其中包含一些项目.一个项目包含我正在部署的WCF服务.该WCF服务引用了其他项目中的一些代码.该代码试图读取WCF项目中的文件夹中的文件.伪项目结构:
Solution
Project1
myclass.cs
string file = Server.Mappath("");
Project2
filefolder
myfile.txt
Run Code Online (Sandbox Code Playgroud)
放入Mappath的正确语法是什么?我尝试了所有不同的变化,例如:
".filefolder/myfile.txt"
"/filefolder/myfile.txt"
"./filefolder/myfile.txt"
"~/filefolder/myfile.txt"
Run Code Online (Sandbox Code Playgroud)
似乎没有人能够到达该文件.我想到的一件事是:Visual Studio 2008在IIS中自己的沙箱中运行项目和WCF .这可能是问题吗?如果在常规IIS中进行设置和部署,它会起作用吗?
在 postgres 中,我们定义了一个约束,它本质上允许我们将表中具有特定值的条目数限制为 1。我们创建了这个约束:
在 list_group(visitor_uid) 上创建唯一索引 list$default$uk 其中 list_type = 'default';
这意味着仅当 list_type='default' 时才应用唯一约束,因此表中每个访问者只能有一个“默认”列表。
看起来 MySql 不支持唯一约束上的附加位置。MySQL 的数据库模式是否有另一种方法来支持这一点?
在我们的ASP.NET MVC应用程序,我们已经注意到,我们不能有禁DOS文件业者名称,COM1通过COM9,LPT1通过LPT9,CON,AUX,PRN,和NUL我们的路线-anywhere.它们不可避免地导致IIS告诉我们无法找到文件,即使我们设置路由不首先检查文件是否存在.我们如何解决这个问题?
我正在寻找干净,优雅和智能的解决方案来从所有XML元素中删除名称空间?如何做到这一点的功能?
定义的界面:
public interface IXMLUtils
{
string RemoveAllNamespaces(string xmlDocument);
}
Run Code Online (Sandbox Code Playgroud)
示例XML从以下位置删除NS:
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfInserts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<insert>
<offer xmlns="http://schema.peters.com/doc_353/1/Types">0174587</offer>
<type2 xmlns="http://schema.peters.com/doc_353/1/Types">014717</type2>
<supplier xmlns="http://schema.peters.com/doc_353/1/Types">019172</supplier>
<id_frame xmlns="http://schema.peters.com/doc_353/1/Types" />
<type3 xmlns="http://schema.peters.com/doc_353/1/Types">
<type2 />
<main>false</main>
</type3>
<status xmlns="http://schema.peters.com/doc_353/1/Types">Some state</status>
</insert>
</ArrayOfInserts>
Run Code Online (Sandbox Code Playgroud)
在我们调用RemoveAllNamespaces(xmlWithLotOfNs)之后,我们应该得到:
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfInserts>
<insert>
<offer >0174587</offer>
<type2 >014717</type2>
<supplier >019172</supplier>
<id_frame />
<type3 >
<type2 />
<main>false</main>
</type3>
<status >Some state</status>
</insert>
</ArrayOfInserts>
Run Code Online (Sandbox Code Playgroud)
解决方案的优先语言是.NET 3.5 SP1上的C#.
我不是DBA,但我尊重数据库理论.是不是添加了像isDeleted和sequenceOrder这样糟糕的数据库实践的列?
我知道.gitignore文件隐藏了Git版本控制中指定的文件.我有一个项目(LaTeX),它在运行时会生成许多额外的文件(.auth,.dvi,.pdf,日志等),但我不希望这些文件被跟踪.
我知道我可以(也许应该)这样做所有这些文件放在项目中的一个单独的子文件夹中,因为我可以忽略该文件夹.
但是,有没有可行的方法将输出文件保存在项目树的根目录中,并使用.gitignore忽略除了我用Git跟踪的文件之外的所有内容?就像是
# Ignore everything
*
# But not these files...
script.pl
template.latex
# etc...
Run Code Online (Sandbox Code Playgroud) 对于Web应用程序或独立服务器应用程序,您会推荐哪个,为什么?