我有一个方法,返回map定义为:
public Map<String, ?> getData();
Run Code Online (Sandbox Code Playgroud)
这个方法的实际实现对我来说并不清楚,但是,当我尝试这样做时:
obj.getData().put("key","value")
Run Code Online (Sandbox Code Playgroud)
我得到以下编译时错误消息:
方法put(String,capture#9-of?)在Map类型中不适用于参数(String,String)
问题是什么?是String不是输入任何内容?
提前致谢.
我是NSubstitute的新手,我试图void用2个out参数模拟一个方法,我很确定我做错了.
我有一个CustomerDataAccess类具有以下签名的方法:
void GetCustomerWithAddresses(int customerId,
out List<Customer> customers,
out List<Address> addresses);
Run Code Online (Sandbox Code Playgroud)
在CustomerRepository调用它的GetCustomer方法,然后调用CustomerDataAccess.GetCustomerWithAddressesDAL方法.然后,DAL方法out为客户输出一个参数,为地址输出一个参数.然后,存储库方法用于AutoMapper将DAL方法中的两个对象映射到存储库随后返回的业务域.
这是我到目前为止的代码,它不起作用.我的研究没有帮助我确定我需要做些什么来解决这个问题.如何设置out参数的值?
// Arange
ICustomerDataAccess customerDataAccess = Substitute.For<ICustomerDataAccess>();
IList<Customer> customers;
IList<Address> addresses;
customerDataAccess.When(x => x.GetCustomerWithAddresses(
1, out customers, out addresses))
.Do(x =>
{
customers = new List<Customer>() { new Customer() { CustomerId = 1, CustomerName = "John Doe" } };
addresses = new List<Address>() { new Address() { AddressId = 1, …Run Code Online (Sandbox Code Playgroud) 嗨,我需要创建文本文件并将其写入/ data目录.
这是我正在使用的代码.
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("chmod 777 /data");
process.waitFor();
resultFile = new File(Environment.getDataDirectory()
+ "/resultfile.txt");
Log.i(TAG,"File Object Created....."+resultFile);
} catch (Exception e) {
Log.i(TAG, "Exception in Environment.getDataDirectory()"
+ e.toString());
}
try {
try {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("chmod 777 /data/resultfile.txt");
process.waitFor();
if (!resultFile.exists())
resultFile.createNewFile();
} catch (IOException ioException) {
Log.i(TAG, "Exception in creating file..."
+ ioException.toString());
}
try {
if (fileWriter == null)
fileWriter = new FileWriter(resultFile);
} catch …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Microsoft Entity Framework的ASP.NET MVC Framework 2,当我尝试保存新记录时,我收到此错误:
无法找到EntityType'WebUI.Controllers.PersonViewModel'的映射和元数据信息
My Entity Framework容器存储Person类型的记录,我的视图是使用派生自Person的类PersonViewModel强类型的.记录将保存正确,直到我尝试使用派生的视图模型类.任何人都可以解释为什么在推导我的视图模型时元数据类不起作用?我希望能够使用强类型模型并使用数据注释(元数据),而无需混合我的存储逻辑(EF类)和表示逻辑(视图).
// Rest of the Person class is autogenerated by the EF
[MetadataType(typeof(Person.Metadata))]
public partial class Person
{
public sealed class Metadata
{
[DisplayName("First Name")]
[Required(ErrorMessage = "Field [First Name] is required")]
public object FirstName { get; set; }
[DisplayName("Middle Name")]
public object MiddleName { get; set; }
[DisplayName("Last Name")]
[Required(ErrorMessage = "Field [Last Name] is required")]
public object LastName { get; set; }
} …Run Code Online (Sandbox Code Playgroud) 这部分是这个问题的后续行动.
我不确定最好的方式来问这个,所以我会尝试一个简短的故事来设置场景:
曾几何时,有一个类'A',它有一个单元测试类'ATests'负责通过公共接口测试它的行为.他们幸福地在一起生活了一段时间然后发生了变化,并且"B"级出现了,因为它与"A"级有很多共同之处,因此引入了一个基类.
A类的测试已经涵盖了基类的公共行为.那么问题是接下来会发生什么?
•B类是否需要对公共(基类行为)进行测试?看起来行为是B的一部分,所以应该进行测试,但这些测试是否应该与A类共享?对于基类?如果是这样,分享的最佳方式是什么?
•新基类是否需要单元测试,或者基类是否可以通过子项测试进行测试?基类是抽象的是否重要?
•是否足以确保类A和B派生自基类并"信任"基类的单元测试以测试常见行为(因此测试不需要在子类中复制)?A&B的测试只需要测试它们是新的/改变的行为吗?
•我是否遵循完全错误的方法,每个真实班级大约有一个单元测试课程?
我在不同的时间采取了不同的观点,不同的方法会对重构代码的能力,编写测试的时间等产生相当大的影响.人们发现哪些方法效果最好?
是否可以将无符号字符数组表示为字符串?
当我搜索它时,我发现只有memset()能够做到这一点(但是逐个字符).假设这不是正确的方法,有没有办法进行转换?
上下文:我正在尝试存储加密哈希函数的输出,该函数恰好是无符号字符数组.
例如:
unsigned char data[N]; ...
for(i=0;i<N;i++) printf("%x",data[i]);
Run Code Online (Sandbox Code Playgroud)
我的目标是将数据表示为String(%s),而不是每个元素访问它.因为我需要将哈希的输出作为字符串进行进一步处理.
谢谢!
我有这个域名:
public class ADomainClass
{
public int Id { get; set; }
}
public interface IMyClass : IEnumerable<ADomainClass>
{
}
public class MyClass : IMyClass
{
public IEnumerator<ADomainClass> GetEnumerator()
{
IList<ADomainClass> list = new List<ADomainClass>();
//list = GetData...();
foreach (var item in list)
{
yield return item;
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
并想要构建以下测试:
[Test]
public void TestSample()
{
//Arrange
IMyClass myclass = Substitute.For<IMyClass>();
IList<ADomainClass> testdata = new List<ADomainClass>()
{
new ADomainClass(){ Id = 1, },
new ADomainClass(){ Id = 2, }, …Run Code Online (Sandbox Code Playgroud) 我试图在一个项目中学习MVC2,C#和Linq到实体(是的,我很生气),我遇到了一些DropDownListFor问题,并将SelectList传递给它.
这是我的控制器中的代码:
public ActionResult Create()
{
var Methods = te.Methods.Select(a => a);
List<SelectListItem> MethodList = new List<SelectListItem>();
foreach (Method me in Methods)
{
SelectListItem sli=new SelectListItem();
sli.Text = me.Description;
sli.Value = me.method_id.ToString();
MethodList.Add(sli);
}
ViewData["MethodList"] = MethodList.AsEnumerable();
Talkback tb = new Talkback();
return View(tb);
}
Run Code Online (Sandbox Code Playgroud)
和我有麻烦试图让DropDownListFor走MethodList在ViewData.当我尝试:
<%:Html.DropDownListFor(model => model.method_id,new SelectList("MethodList","method_id","Description",Model.method_id)) %>
Run Code Online (Sandbox Code Playgroud)
它出错以及以下消息
DataBinding: 'System.Char' does not contain a property with the name 'method_id'.
Run Code Online (Sandbox Code Playgroud)
我知道为什么会这样,因为它是MethodList一个字符串,但我无法弄清楚如何让它采取SelectList.如果我按照正常情况执行以下操作DropDownList:
<%: Html.DropDownList("MethodList") %>
Run Code Online (Sandbox Code Playgroud)
对此非常满意. …
我如何知道在C程序中,我的代码运行在哪个物理处理器和核心上?我正在使用Linux和gcc 4.4.3.
我想跳过在验证调用中检查参数之一。因此对于:
def allowMockitoVerify=Mockito.verify(msg,atLeastOnce()).handle(1st param,,3rd param)
Run Code Online (Sandbox Code Playgroud)
我想跳过检查第二个参数。我怎样才能做到这一点?