vlookup函数视频教程,你是我的索尔斯克亚,xunbo
电脑不想装几十个g的 vs2017,那就用 vs code 吧
目标:
环境
首先在 vs code 安装几个扩展插件
c#
c# extensions
.net core test explorer
这三个插件就可以做最基础的开发了
创建解决方案文件夹 c:\here\skany
在 vs code 中打开这个文件夹
在 vs code 中打开终端(也可以在外部使用cmd或powershell)
接下来将使用 .net core cli 命令创建项目
# 创建类库项目 dotnet new classlib -n skany.core # 创建控制台应用程序 dotnet new console -n skany.output # 创建xunit单元测试项目 dotnet new xunit -n skany.tests # 为 output 添加 core 引用(因为当前在解决方案目录,而不是项目目录,所以add后要加上项目名,以下同理) dotnet add skany.output reference skany.core # 为 tests 添加 core 引用 dotnet add skany.tests reference skany.core # 为 core 项目添加 nuget 引用 dotnet add skany.core package hash --version 4.0.0 # 创建解决方案 sln dotnet new sln -n skany # 添加项目到解决方案 dotnet sln skany.sln add skany.core dotnet sln skany.sln add skany.output dotnet sln skany.sln add skany.tests # 编译一下 output 和 tests 项目 dotnet build skany.output dotnet build skany.tests
当不熟悉命令时,都可以通过 -h 或 --help 参数获取帮助,比如我不知道单元测试项目的参数,就输入 dotnet new -h 查看 new 的选项
注:其实用第三方插件(比如 vscode-solution-explorer)轻松实现以上命令的可视化操作,这里只是演示 .net core cli 命令用法
创建完后的项目结构
skany | skany.core | class1.cs | skany.core.csproj | skany.output | program.cs | skany.output.csproj | skany.tests | unittest1.cs | skany.tests.csproj | skany.sln
将 core 项目中的 class1.cs 改为 crypthelper.cs,代码如下
using hashlibrary; namespace skany.core { public class crypthelper { public static string hashpassword(string password, out string salt) { var hash = hashedpassword.new(password, hashlength: 50, saltlength: 10); salt = hash.salt; return hash.hash; } public static bool verifypassword(string password, string hashpassword, string salt) { var hash = new hashedpassword(hashpassword, salt); bool matches = hash.check(password); return matches; } } }
在 tests 项目中别写测试案例,将 unittest1.cs 改为 cryptunittest.cs,代码如下
using system; using xunit; namespace skany.tests { using core; public class cryptunittest { [theory] [inlinedata("zhang")] [inlinedata("baidu")] public void hashpasswordtest(string password) { string salt; var hashpassword = crypthelper.hashpassword(password, out salt); assert.notnull(hashpassword); assert.notnull(salt); assert.true(hashpassword.length == crypthelper.hashlength); assert.true(salt.length == crypthelper.saltlength); verifypasswordtest(password, hashpassword, salt); } [theory] [inlinedata("zhang", "áēõā1fv¾ēëüĝ}f§¼kè$æ7kďğđmĭzĝč9ëå«¢ýīùøê£i)¥jµqiįa", "ïûŀb³äĭonê")] [inlinedata("baidu", " g©®ģ¹óäõ¥ģh»7ċuo¸%aoį©ĩ§8ćkąöĉėß$µåë¬üö=ĝĵ¶cꨧh/", "āė§į^h7í_h")] public void verifypasswordtest(string password, string hashpassword, string salt) { assert.true(hashpassword.length == crypthelper.hashlength); assert.true(salt.length == crypthelper.saltlength); assert.true(crypthelper.verifypassword(password, hashpassword, salt)); } } }
通过命令执行单元测试
dotnet test skany.tests
如果只想测试其中一个方法 hashpasswordtest
dotnet test skany.tests --filter hashpasswordtest
当然有可视化的测试插件,谁还用命令啊
在 output 项目调用 core.crypthelper 输出结果,代码如下
static void main(string[] args) { string salt = null; var password = "baidu"; var hashpassword = crypthelper.hashpassword(password, out salt); console.writeline("password => {0}", password); console.writeline("hashpassword => {0}", hashpassword); console.writeline("salt => {0}", salt); //=================================== var matchs = crypthelper.verifypassword(password, hashpassword, salt); console.writeline("matchs: {0}", matchs); console.readline(); }
运行 output 项目
dotnet run --project skany.output
在 output/program.cs 中第13行设置一个端点(鼠标在行首点一下即可,再点一下移除断点)
debug面板配置选择 .net core launch (console),点击绿色的开始调试按钮,启动调试
与 vs 中一样,可以通过 f5/f10/f11 控制调试流程,也可以添加 watch 变量,鼠标也可以感知变量值
如果开始测试后,警告提示启动程序找不到,可以按提示(也可以点击界面齿轮按钮)修改配置文件 .vscode/launch.json
核对 program 节点路径是否正确
虽然 vs 无比强大,vs code 小清醒,但是 vs code 灵活扩展性强,用来开发前端或 .net core 项目,也是得心应手
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论