我有一个方法很少的类。对于这些方法,我正在使用 MSTest 创建单元测试用例。
public class Class1
{
public virtual async Task<bool> GetData()
{
string var1 ="dsfs", var2 ="eer";
bool retVal = await DoSomething(var1, var2);
// some business logic
return true;
}
public virtual async Task<bool> DoSomething(string var1, string var2)
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
方法的测试用例GetData()如下所示。
[TestClass()]
public class Class1Test
{
[TestMethod()]
public async Task GetDataTest()
{
var mockService = new Mock<Class1>();
var isTrue = ReturnTrue(); // this function returns true
mockService.Setup(x => x.DoSomething(It.IsAny<string>(), It.IsAny<string>())).Returns(isTrue);
var result = await …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的Web应用程序实现OAuth2.0。我已经完成了这个链接。
我已经向2个外部提供商Microsoft和Google注册。我也在startup.cs文件中添加了身份验证。
因此,当我运行该应用程序时,单击右上角的“登录”按钮,将显示一个“登录”页面。其显示的URL为https://localhost:44325/Identity/Account/Login。
但是我无法在解决方案中的任何地方找到此页面。我想修改此页面的设计,并希望在打开应用程序后立即将其作为我的第一页。
我该怎么做。我已经搜索了几个小时,却找不到任何东西。
非常感谢您的帮助。在此先感谢您。
编辑
我正在尝试使用 powershell 创建 Azure VM。我还有创建它的脚本。
首先我需要登录 Azure 帐户:
Login-AzureRMAccount
Run Code Online (Sandbox Code Playgroud)
这会弹出一个窗口来输入凭据。
其次我需要运行以下脚本:
$UserName = "username"
$Password = ConvertTo-SecureString "password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password)
New-AzureRmVm `
-ResourceGroupName "RG1" `
-Name "VM1" `
-ImageName "Image1" `
-Location "West US" `
-Credential $psCred
Run Code Online (Sandbox Code Playgroud)
至此虚拟机创建成功。
但现在,我需要让这些脚本在有要求时自动运行。我面临的问题是,登录步骤会弹出一个窗口来输入我不想要的凭据。所以我尝试过类似的事情,但没有成功。
$username = "loginname@organization.com"
$SecurePassword = ConvertTo-SecureString "password" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($username, $SecurePassword)
Login-AzureRmAccount -Credential $cred
Run Code Online (Sandbox Code Playgroud)
它给出的错误消息是:
Login-AzureRmAccount : accessing_ws_metadata_exchange_failed: Accessing WS metadata exchange failed: The underlying connection was closed: An unexpected error occurred on …Run Code Online (Sandbox Code Playgroud) 我有一个类似于下面的配置文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<appSettings>
<add key="key1" value="Value1" />
<add key="key2" value="Value12" />
<add key="key3" value="Value3" />
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
现在,通过 PowerShell,我尝试替换一些值,例如Value1. 为此,我编写了以下脚本:
$original_file = "C:\test.xml"
(Get-Content $original_file) | Foreach-Object {
$_ -replace 'Value1', 'Newvalue'
} | Set-Content $original_file
Run Code Online (Sandbox Code Playgroud)
那么它的作用就是Value1用Newvalue字符串替换所有字符串。我在这里面临的问题是它改变了找到的所有值Value1 …
我仍在学习在我的应用程序中使用 MSTest 和 Moq 进行自动化单元测试。我已经成功地模拟了代码并运行了它。它表明测试通过,但代码覆盖率为 0%。这是我下面的代码。需要更改什么才能使代码覆盖率变为 100%。
我知道这个问题之前曾被问过几次,但似乎没有任何帮助。所以有人可以告诉我我做错了什么。
非常感谢任何帮助。谢谢。
PS:我使用 Sonarcube 来了解代码覆盖率。
using Moq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
namespace MyNameSpace
{
[TestClass]
public class ApplicationTest
{
readonly Helper moqHelper = new Helper();
[TestMethod()]
public void GetDataFromDataBaseMoq()
{
Task<bool> returnValue;
Mock<Application> mockType = new Mock<Application>();
mockType.CallBase = true;
mockType.Setup(x => x.GetDataFromDataBase()).Returns(returnValue = moqHelper.GetDataFromDataBaseMoq());
if (returnValue.Result)
{
Assert.IsTrue(true);
}
else
{
Assert.Fail();
}
}
}
[ExcludeFromCodeCoverage]
class Helper
{
internal async Task<bool> GetDataFromDataBaseMoq()
{
bool returnValue = true;
return returnValue; …Run Code Online (Sandbox Code Playgroud) 我有一个 Java 应用程序,它显示 Apache Tomcat Embed 为 9.0.35 版本。我需要将其更新到 10.0.4。我对 Java 很陌生,对它的了解也很少。需要此升级来解决应用程序中的一些漏洞。
我如何从 IntelliJ IDE 执行此操作?
c# ×3
moq ×2
mstest ×2
powershell ×2
unit-testing ×2
app-config ×1
azure ×1
java ×1
oauth-2.0 ×1
tomcat ×1
virtual ×1
xml ×1