我有一个界面,定义如下
public interface IFoo
{
object this[string key] { get; }
}
Run Code Online (Sandbox Code Playgroud)
如何使用NSubstitute模拟这个索引器?
我正在尝试构建一个由组合在一起的几个控件组成的小部件.这是小部件:
public class VarioView extends RelativeLayout {
private int value;
private ImageView m_circle;
private TextView m_varioText;
private TextView m_units;
public VarioView(Context context)
{
this(context,null);
}
public VarioView(Context context, AttributeSet attr)
{
this(context,attr, 0);
}
public VarioView(Context context, AttributeSet attr, int defStyle)
{
super(context, attr, defStyle);
//View.inflate(context, R.layout.vario, this);
LayoutInflater li = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
li.inflate(R.layout.vario, this, true);
m_circle = (ImageView)this.findViewById(R.id.VarioCircle);
m_varioText = (TextView)this.findViewById(R.id.VarioText);
//m_circle.setColorFilter(Color.BLUE);
}
public int getValue() {
return value;
}
public void setValue(int value) {
m_varioText.setText(Integer.valueOf(value).toString());
this.value = value;
} …Run Code Online (Sandbox Code Playgroud) 我的应用程序依赖于多个事件总线对象,这些对象是基本的发布/订阅通知模型(http://caliburn.codeplex.com/wikipage?title=The%20Event%20Aggregator).
我想要做的是与一组组件共享某些聚合器实例.假设组件我有一个在组件A,B和C之间共享的事件总线,然后是在D,E,F之间共享的另一个事件总线.
我基本上想要将事件总线声明为单例并根据某些条件注入它们.我有点想避免对事件总线进行分类,只是为了区分分辨率.
我在java中使用了Google Guice IoC,它允许参数的元数据解析.java中的Aka让我得到了与此相当的东西.
例:
public A([SpecialUseAggregator]IEventAggregator something)
public B([SpecialUseAggregator]IEventAggregator something)
public E([AnotherUseAggregator]IEventAggregator something)
public F([AnotherUseAggregator]IEventAggregator something)
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我正在尝试优化访问 SQL Server 2014 数据库的代码性能,并注意到连接池似乎不像 ADO.NET 所宣传的那样工作。默认情况下,它应该被启用并开箱即用(只要使用相同的连接字符串)。然而,我的实验表明,在 SqlConnection 上打开/关闭连接实际上会导致审核登录/注销被引发。
根据https://msdn.microsoft.com/en-us/library/vstudio/8xx3tyca(v=vs.100).aspx这不应该是这种情况:
从连接池获取连接或将连接返回到连接池时,不会在服务器上引发登录和注销事件。这是因为连接返回到连接池时实际上并没有关闭连接。
我的简单测试是创建一个控制台应用程序,类似于以下内容:
var conn = new SqlConnection("Data Source=(local);Integrated Security=SSPI;Initial Catalog=icedb;");
for (int i = 0; i < 3; i++)
{
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = "select 1";
cmd.ExecuteScalar();
conn.Close();
}
Run Code Online (Sandbox Code Playgroud)
运行此代码会产生类似于以下内容的 Sql Profiler 捕获的结果。观察多个登录/注销事件,如果池按宣传的那样工作,则不应捕获这些事件。我已经能够在多台机器(Windows 8/10、.NET 4.5、Sql Server 2014 Developer Edition)上重现这个。
主要问题:如何让连接池工作。
.net ×2
ado.net ×1
android ×1
autofac ×1
c# ×1
eclipse ×1
mocking ×1
nsubstitute ×1
sql-server ×1
unit-testing ×1