小编Moe*_*ald的帖子

查询Entitiy Framework缓存

是否可以对WhereEntity Framework缓存执行显式查询?我知道我可以用来Find在缓存中查找实体(基于实体主键).

代码示例:

var person = new PersonToStoreInDb() { Id = 1, Name = "John" };
dbSet.Add(person);
// Perform some other code
...
// DbContext.SaveChanges was NOT called!
var personFromDbSet = bSet.Where(p => p.Name == "John").First();
// personFromDbSet is null because it was not sent towards DB via SaveChanges
Run Code Online (Sandbox Code Playgroud)

c# entity-framework

5
推荐指数
1
解决办法
68
查看次数

Powershell 缩进此处字符串

有没有人知道是否可以将here-string. 其实我要写:

  $someString = @"
                First line
                second line
  "@
Run Code Online (Sandbox Code Playgroud)

如果您here-string在更深的缩进级别上定义 a ,这将变得非常难看,因为结尾"@必须是该行的第一个字符。此外,有人可能会“修复”丢失的缩进并破坏脚本......

是否可以定义一个here-string像:

  $someString = @"
                First line
                second line
                "@
Run Code Online (Sandbox Code Playgroud)

谢谢

powershell

5
推荐指数
1
解决办法
1412
查看次数

NUNIT3-CONSOLE排除特定的测试类别

旧的NUnit 2控制台运行器有一个/exclude参数来排除具有特定Category属性的测试.有人知道NUnit3的控制台是否支持此功能?

.\nunit3-console.exe --help没有说明排除参数.我只能看到一个Where参数,它可以用于此目的吗?

nunit-console nunit-3.0

5
推荐指数
1
解决办法
2038
查看次数

docker通过PowerShell远程连接到windowsservercore

我想测试两个docker容器之间的PS远程处理.我有以下DockerFile:

FROM microsoft/windowsservercore:latest

# Set trusted hosts for PS remoting
RUN winrm s winrm/config/client @{TrustedHosts="*"}
# Set password -> just for testing!
RUN net user Administrator 1234!password5678

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Enable PS remoting
RUN Enable-PSRemoting -force; if ($?) {Start-Service winrm}

# Keep container alive if started via docker-compose
CMD start-sleep -seconds 3600
Run Code Online (Sandbox Code Playgroud)

以下docker-compose.yml:

version: '3.1'

services:
   testserver:
      image: 172.23.86.48/myPowerShellImage:latest
      ports:
        - 6985:5985 
        - 6986:5986   

   startpowershelltests:
      image: 172.23.86.48/myPowerShellImage:latest
      ports:
       - 7985:5985 
       - 7986:5986   
      depends_on: …
Run Code Online (Sandbox Code Playgroud)

powershell docker docker-compose

5
推荐指数
1
解决办法
330
查看次数

Powershell invoke-webrequest不起作用

我有一个Powershell脚本,应该Invoke-WebRequest对一个网站运行。我想将此脚本与PRTG Network Monitor一起使用,以确保Web服务器正常启动并运行。

当前,该脚本可以在我的本地计算机上运行,​​也可以在探测服务器上使用我的域凭据运行。但是,当使用PRTG使用的本地管理员凭据登录时,它不会运行。

我把它缩小到一行

Invoke-WebRequest $uri -Method POST -Body $body -TimeoutSec 10
Run Code Online (Sandbox Code Playgroud)

看来,无论出于何种原因,在使用此帐户Invoke-WebRequest时均无法使用。运行该行时,它不会产生任何东西,没有错误,警告或输出。这两个$uri$body变量已被定义为好。

即使我使用本地admin PRTG帐户登录了探针服务器并以其他用户身份(使用我自己的凭据)运行Powershell,它仍然无法产生任何结果。

为什么本地管理员帐户无法运行Invoke-WebRequest?这是在带有PSVersion 4.0的Windows Server 2012R2上发生的。

windows powershell server prtg

4
推荐指数
1
解决办法
4227
查看次数

Pester 自定义错误文本

有谁知道 Pester 是否支持自定义错误文本?

假设我有以下测试:

Describe "Get-HelloWorld" {
    It "outputs 'Hello world!'" {
        Get-HelloWorld | Should Be 'Hello world!'
    }
}
Run Code Online (Sandbox Code Playgroud)

Get-HelloWorld如果返回“Hello World”以外的另一个字符串,有没有办法可以设置一些自定义错误消息?

谢谢

powershell pester

4
推荐指数
1
解决办法
527
查看次数

Pester 测试非导出的 PowerShell cmdlet/函数

我有一个可导出一个 cmdlet 的 PowerShell 模块。该模块包含一些最终用户不可见的功能。但是,我想通过 Pester 测试这些功能(因为测试设置很简单)。

是否可以调用 cmdlet 的非导出函数?或者,是否可以强制加载所有函数的模块,尽管 psd1 文件仅导出其中的一些函数?

powershell pester

4
推荐指数
1
解决办法
533
查看次数

git flow init -d 默认建议为空

我在 Windows 上使用 Git flow。当我通过以下方式初始化我的存储库时

git flow init -d 
Run Code Online (Sandbox Code Playgroud)

我得到以下输出

Which branch should be used for bringing forth production releases?
- develop
- master
 Branch name for production releases: [master]

Which branch should be used for integration of the "next release"?
  - develop
Branch name for "next release" development: [develop]

How to name your supporting branch prefixes?
Feature branches? []
Bugfix branches? []
Release branches? []
Hotfix branches? []
Support branches? []
Version tag prefix? []
Run Code Online (Sandbox Code Playgroud)

可以看出,默认前缀为空。谁能告诉我这些前缀是在哪个配置文件中设置的?

问题是我正在使用 PowerShell 脚本克隆多个存储库并通过 …

git git-flow

4
推荐指数
1
解决办法
8082
查看次数

Git,检测本地HEAD指向GIT标签

如何检测是否根据标签检查了实际工作?

假设我正在执行以下 GIT 命令:

 > git checkout 1.2.3
Run Code Online (Sandbox Code Playgroud)

git status告诉我我的HEAD“指针”处于分离状态。如果我直接检查 SHA,也可能出现这种情况,例如通过:

 > git checkout f1d96551ab404de047c846a0a59f76e8505046c9 
Run Code Online (Sandbox Code Playgroud)

我怎样才能知道它HEAD实际上指向一个带有标签的提交?

谢谢

git

4
推荐指数
1
解决办法
1339
查看次数

Dockerfile:将目录从 Windows 主机复制到 docker 容器

我想构建一个 Docker 镜像,包括我的自定义 Powershell 模块。因此,我使用 Microsoft 的microsoft/powershell:latest图像,我想从中创建自己的图像,其中包括我的 psm1 文件。

对于简单的测试,我有以下 docker 文件:

FROM microsoft/powershell:latest
RUN mkdir -p /tmp/powershell
COPY  C:/temp/somedirectory /tmp/powershell
Run Code Online (Sandbox Code Playgroud)

我想将 C:\temp\somedirectory 中包含的文件复制到 docker linux 容器。构建图像时,我收到以下错误:

C:\temp\docker_posh> docker build --rm -f Dockerfile -t docker_posh:latest 。

将构建上下文发送到 Docker 守护进程 2.048kB

第 1/3 步:从 microsoft/powershell:latest ---> 9654a0b66645

第 2/3 步:运行 mkdir -p /tmp/powershell ---> 使用缓存 ---> 799972c0dde5

步骤 3/3 : COPY C:/temp/somedirectory /tmp/powershell COPY failed: stat /var/lib/docker/tmp/docker-builder566832559/C:/temp/somedirectory: no such file or directory

我当然知道 Docker 说我找不到文件/目录。因此,我还尝试了C:/temp/somedirectory/.C:/temp/somedirectory/*和 …

docker

3
推荐指数
1
解决办法
1万
查看次数