试图模拟在另一个方法中调用的方法.
public virtual bool hello(string name, int age)
{
string lastName = GetLastName();
}
public virtual string GetLastName()
{
return "xxx";
}
Mock<program> name= new Mock<program>();
name.Setup(x => x.GetLastName()).Returns("qqq");
Run Code Online (Sandbox Code Playgroud)
我希望方法GetLastName始终返回"qqq".
当我尝试删除具有子键的HKCU中的键时,我收到错误.
这是我正在使用的代码:
using (RegistryKey regkey = Registry.CurrentUser.OpenSubKey(@"Software\Policies\", true))
{
if (regkey.OpenSubKey("Google") != null)
{
regkey.DeleteSubKey("Google");
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
注册表项具有子项,此方法不支持递归删除.
我怎么能克服它?
使用refor out参数调用方法时,必须在调用方法时指定相应的关键字.我从样式和代码质量的角度来理解(例如这里所解释的),但我很好奇是否还需要在调用者中指定关键字.
例如:
static void Main()
{
int y = 0;
Increment(ref y); // Is there any technical reason to include ref here?
}
static void Increment(ref int x)
{
x++;
}
Run Code Online (Sandbox Code Playgroud) 我有一个 EventDetails.aspx 页面,其中包含我的用户可以使用 Timetable.aspx 页面中的 Window.Open() 打开的事件的详细信息。在 EventDetails.aspx 页面上,我有一个按钮,允许我使用以下代码关闭窗口:
protected void CloseWindow_Click(object sender, EventArgs eventArgs)
{
Response.Write("<script language='javascript'>window.open('','_self');window.close();</script>");
}
Run Code Online (Sandbox Code Playgroud)
当我从 Timetable.aspx 页面使用 Window.Open() 打开我的窗口时,关闭窗口按钮工作正常,但是如果我独立导航到 EventDetails.aspx 页面,我将无法使用关闭窗口按钮 - 没有任何反应!
有没有一种方法可以确定用户是否使用 Window.Open() 导航,以便我可以更改按钮的可见性,或者更好的是,是否有另一种方法可以关闭不依赖于使用 Window.Open() 的选项卡。打开()?
我正在尝试使用CMake和Visual Studio 2015社区在Windows上的Atlasian Bamboo上构建C ++项目测试套件。以我的用户帐户运行时,CMake和VS可以正常工作,但是通过Bamboo运行它们时,出现以下错误:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_CXX_COMPILER could be found.
Run Code Online (Sandbox Code Playgroud)
我不认为由于通常的原因我会收到此错误。CMake似乎能够找到编译器本身。而是,资源编译器似乎是错误的根源。在CMakeFiles/CMakeError.log文件中,我有以下输出:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe
<<options removed> CMakeCCompilerId.c
C:\Windows\system32\config\systemprofile\AppData\Local\Temp\lnk{ECA1FDDF-C2EA-4
819-AFE3-6A5E06ECA59E}.tmp(1): error RC2135: file not found: C:\Windows\system3
2\config\systemprofile\AppData\Local\Temp\lnk{8A24DD6C-9300-41A6-9CAC-B48137E0E
056}.tmp [C:\bamboo\bamboo-agent-home\...\CMakeFiles\3.6.1\CompilerIdC\CompilerIdC.vcxproj]
Run Code Online (Sandbox Code Playgroud)
我不太了解针对初学者的报道路径。这是符号链接还是什么?为什么还要涉及资源编译器?有人知道为什么找不到该文件吗?
我正在尝试一个示例应用程序来测试依赖注入.在使用DI之前,我的课程中有以下方法:
public IQueryable<BookDTO> GetBooks()
{
var books = from b in db.Books
select new BookDTO()
{
Id = b.Id,
Title = b.Title,
AuthorName = b.Author.Name
};
return books;
}
Run Code Online (Sandbox Code Playgroud)
BookDTO是另一个项目中定义的数据传输对象.现在我想把我的项目松散地结合在一起.所以我创建了IDTOBase接口并使BookDTO实现了这一点.我有一个统一容器,我已经将BookDTO类的相关注册到IDTOBase.
但是,如何在原始方法中重写LINQ查询?什么将取代"新BookDTO()"?
谢谢
c# linq dependency-injection data-transfer-objects unity-container
Caliburn.Micro 3.0(和Caliburn.Micro.Xamarin.Forms)是否实现了模拟/支持Navigation.PushModalAsyncXamarin.Forms的功能?
我有两个采用以下形式的数组:
0…0…0 0 0 0…0 0…0…0 0 0 0…0
? ? ? ? ? ? ? ? ? ? ? ? ? ?
0…0 0 0 0 0…0 0…0 0 0 0 0…0
A = 0…0 1 2 3 0…0 B = 0…0 9 8 7 0…0
0…0 4 5 6 0…0 0…0 6 5 4 0…0
0…0 0 0 0 0…0 0…0 0 0 0 0…0
? ? ? ? ? ? ? ? ? ? ? ? ? …Run Code Online (Sandbox Code Playgroud) 试图创建一个表达式树来做一个对象映射器类型的事情。
Type ts = typeof(Source);
Type td = typeof(Dest);
ParameterExpression val = Expression.Parameter(ts);
ParameterExpression ret = Expression.Parameter(td);
PropertyInfo[] propsS = ts.GetProperties();
PropertyInfo[] propsD = td.GetProperties();
List<Expression> lst = new List<Expression>();
foreach (PropertyInfo pi in propsS)
{
PropertyInfo piD = propsD.Where(x => x.Name == pi.Name).FirstOrDefault();
if (piD != null)
{
MethodInfo ge = pi.GetGetMethod();
MethodInfo se = piD.GetSetMethod();
var v1 = Expression.Call(val, ge);
var v2 = Expression.Call(ret, se, v1);
lst.Add(v2);
}
}
lst.Add(Expression.Return(Expression.Label(td), ret));
BlockExpression block = Expression.Block(
new[] { ret …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写单元测试,以确保该方法正在写入文本文件。我的方法写入文本文件MovieList.txt。我一直收到一条错误消息,说它无法访问文件,因为它正在被另一个进程使用。因此,我尝试更改方法以接受参数以写入不同的文本文件MovieListTEST.txt,但是我仍然无法弄清楚。有人知道如何正确执行此操作吗?
这是我写入文件的代码:
public bool WriteMovieListToFile()
{
try
{
FileStream fs = new FileStream("MovieList.txt", FileMode.Append, FileAccess.Write);
StreamWriter textWriter = new StreamWriter(fs);
textWriter.WriteLine(movie.Title);
textWriter.WriteLine(movie.Genre);
textWriter.WriteLine(movie.Actor);
textWriter.WriteLine(movie.Year);
textWriter.Close();
return true;
}
catch (Exception ex)
{
Console.WriteLine("Error:" + ex.Message);
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
用param编辑:
public bool WriteMovieListToFile(string fileLocation)
{
try
{
FileStream fs = new FileStream(fileLocation, FileMode.Append, FileAccess.Write);
StreamWriter textWriter = new StreamWriter(fs);
Run Code Online (Sandbox Code Playgroud)
这是我的单元测试代码:
/// <summary>
///A test for WriteMovieListToFile
///</summary>
[TestMethod()]
public void WriteMovieListToFileTest1()
{
Movie movie1 = new …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 hyper 创建 REST 服务器。对于稳健的错误处理,我希望服务返回一个带有自定义错误类型的未来,该类型包含 hyper、Diesel 和其他错误。不幸的是,hyper::Response似乎对错误类型的流进行了硬编码hyper::error::Error,这与我为我的服务定义的错误类型相冲突。我看到了几个可能的解决方案:
通过修改 使我的服务返回我的自定义错误类型hyper::Response,这似乎很难。
将非超级错误包装在hyper::error::Error. 这看起来很hacky。
别的东西。似乎我错过了执行此操作的“正确”方法。
以下代码显示了我认为我想做的事情:
extern crate diesel;
extern crate futures;
extern crate hyper;
use futures::future::{ok, Future};
use hyper::StatusCode;
use hyper::server::{Request, Response, Service};
fn main() {
let address = "127.0.0.1:8080".parse().unwrap();
let server = hyper::server::Http::new()
.bind(&address, move || Ok(ApiService {}))
.unwrap();
server.run().unwrap();
}
pub struct ApiService;
impl Service for ApiService {
type Request = Request;
type Response = Response;
type Error = Error;
type Future …Run Code Online (Sandbox Code Playgroud) c# ×7
unit-testing ×2
.net ×1
asp.net ×1
bamboo ×1
cmake ×1
expression ×1
hyper ×1
javascript ×1
linq ×1
matlab ×1
matrix ×1
mocking ×1
moq ×1
registry ×1
rust ×1
tree ×1
visual-c++ ×1
winforms ×1
xamarin ×1