我想为我的Asp .net核心应用程序编写集成测试,但我不希望我的测试使用某些服务的真实实现。
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
...
services.AddTransient<IExternalService,ExternalService>();
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
}
}
public interface IExternalService
{
bool Verify(int id);
}
public class ExternalService : IExternalService
{
public bool Verify(int id)
{
//Implemetation is here.
//I want to fake this implemetation during testing.
}
}
[Fact]
public void TestCase()
{
//Stub out service
var myExtService = new Mock<IExternalService>();
//Setup response by stub
myExtService
.Setup(p => p.Verify(It.IsAny<int>()))
.Returns(false);
var …Run Code Online (Sandbox Code Playgroud) 我想设置一个带有构建,测试和部署阶段的CI/CD管道.我可以在构建阶段构建我的项目
msbuild src\MyProject.csproj /t:Restore
msbuild src\MyProject.csproj /p:Configuration=Release /p:OutputPath=../BuildOutput
Run Code Online (Sandbox Code Playgroud)
接下来,我将构建并运行..\BuildOutput\MyProject.dll已经构建的测试.
msbuild tests\MyProject.Tests.csproj /t:Restore
msbuild tests\MyProject.Tests.csproj /p:Configuration=Release /p:OutputPath=../BuildOutput /p:BuildProjectReferences=false
vstest.console BuildOutput\MyProject.Tests.dll
Run Code Online (Sandbox Code Playgroud)
到目前为止它似乎有效.
现在我想生成nuget包.我可以打电话:
msbuild src\MyProject.csproj /t:Pack /p:Configuration=Release /p:OutputPath=../BuildOutput /p:VersionPrefix=1.2.3
Run Code Online (Sandbox Code Playgroud)
这将MyProject.1.2.3.nupkg在BuildOutput文件夹中创建.但是它重新构建了该项目.
我正在寻找类似于dotnetcli的东西.
dotnet pack --no-build
Run Code Online (Sandbox Code Playgroud)
但我无法使用,dotnet因为我的项目有一个COM引用.
我也查看了Nuget.exe,但是当我打电话时似乎抛出了一个错误 nuget pack
Unable to cast object of type 'System.String' to type NuGet.Frameworks.NuGet.Frameworks1051960.NuGetFramework'.
Run Code Online (Sandbox Code Playgroud)
msbuild是否有可以跳过构建的属性?