我想使用 PHPUnit 测试 Slim 应用程序的端点。我正在努力模拟 POST 请求,因为请求正文始终为空。
slim-input)php://input,但发现php://input是只读的(困难的方法)环境模拟工作正常,例如REQUEST_URI始终如预期。我发现请求的正文是Slim\Http\RequestBody从php://input中读出的。
笔记:
guzzle因为它发送了实际的请求。我不想在测试应用程序时运行服务器。到目前为止我的测试代码:
//inherits from Slim/App
$this->app = new SyncApiApp();
// write json to //temp, does not work
$tmp_handle = fopen('php://temp', 'w+');
fwrite($tmp_handle, $json);
rewind($tmp_handle);
fclose($tmp_handle);
//override environment
$this->app->container["environment"] =
Environment::mock(
[
'REQUEST_METHOD' => 'POST',
'REQUEST_URI' => '/1.0/' . $relativeLink,
'slim.input' => $json,
'SERVER_NAME' => 'localhost',
'CONTENT_TYPE' => 'application/json;charset=utf8'
]
); …Run Code Online (Sandbox Code Playgroud) 如果我尝试在客户端计算机上打开 Excel 文件,则会引发以下异常:
Exception from HRESULT: 0x800A03EC
Run Code Online (Sandbox Code Playgroud)
内部异常:(空)
堆栈跟踪:
at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
at (own assembly)
Run Code Online (Sandbox Code Playgroud)
这个 HResult 是一个非常通用的错误,我找不到任何有用的信息。
我的设置:
在 Windows 服务中运行的 WCF 服务。完全相同的安装程序正在其他三台机器上运行。
我可以排除的事情:
我做过的事情:
我没有使用该SelectedItem属性Combobox.项目已正确绑定并显示,但无法更改为其他项目.如果尝试选择其他项目,则项目列表将正确关闭,但SelectedItem不会被调用(也不会设置为setter或getter),并且不会更改显示的所选项目.
我的XAML如下:
<ComboBox
ItemsSource="{Binding PasswordTypes}"
ItemTemplate="{StaticResource PasswordTypeTemplate}"
SelectedItem="{Binding SelectedPasswordType, Mode=TwoWay}"
/>
Run Code Online (Sandbox Code Playgroud)
相关ViewModel代码:
public MyViewModel()
{
//these are the only two assignments in code of those two properties
_passwordTypes = new ObservableCollection<PasswordType>(nonEmptyList);
_selectedPasswordType = PasswordTypes.First();
}
private PasswordType _selectedPasswordType;
public PasswordType SelectedPasswordType
{
get => _selectedPasswordType;
set => Set(ref _selectedPasswordType, value);
}
private ObservableCollection<PasswordType> _passwordTypes;
public ObservableCollection<PasswordType> PasswordTypes
{
get => _passwordTypes;
set => Set(ref _passwordTypes, value);
}
Run Code Online (Sandbox Code Playgroud)
两个属性的调用如下:
get PasswordTypes 起源于 this.InitializeComponent() …我想使用 存储和检索密码Windows Hello。用户可以在登录时选择是否要手动输入密码,或者是否要使用Windows Hello解锁(然后检索上次使用的密码,并为用户填写)。
如果Windows Hello设置正确,文档中有两个用例。
只需解锁即可:
UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync("userMessage");
if (consentResult.Equals(UserConsentVerificationResult.Verified))
{
// continue
}
Run Code Online (Sandbox Code Playgroud)
以及对来自服务器的消息进行签名的方法:
var openKeyResult = await KeyCredentialManager.OpenAsync(AccountId);
if (openKeyResult.Status == KeyCredentialStatus.Success)
{
var userKey = openKeyResult.Credential;
var publicKey = userKey.RetrievePublicKey();
//the message is the challenge from the server
var signResult = await userKey.RequestSignAsync(message);
if (signResult.Status == KeyCredentialStatus.Success)
{
//the with the private key of the user signed message
return signResult.Result;
}
}
Run Code Online (Sandbox Code Playgroud)
两者对于我的用例来说都不是很有用:我想要一种对称的方式来存储和检索密码。
简而言之,我的问题是:
有没有办法对称存储数据Windows Hello …
我无法将泛型类型转换为另一种泛型类型,除了转换应该是有效的
我想要归档的是简短的(用于MyModel实现IModel和MyImplementation实现IImplementation):
IImplementation<IModel> implementation = new MyImplementation<MyModel>();
Assert.IsNull(implementation as IImplementation<IModel>);
Run Code Online (Sandbox Code Playgroud)
这有点令人困惑,因为类型应该是有效的.
完整的概念模型:
interface IModel {}
class MyModel : IModel {}
interface IImplementation<TModel> where TModel : IModel { }
class MyImplementation<TModel> : IImplementation<TModel>
where TModel : IModel { }
public void CallRegister()
{
var implementation = new MyImplementation<MyModel>();
var instance = CastModel(implementation);
Assert.IsNotNull(instance); //this assert fails!
}
private object CastModel<TModel>(IImplementation<TModel> implementation) where TModel : IModel
{
return implementation as IImplementation<IModel>;
}
Run Code Online (Sandbox Code Playgroud)
我需要这个强制转换才能让我将多个IImplementation …
解
能够达到预期效果的最短代码对我来说:
<ItemsControl ItemsSource="{Binding GeneralBoolSettings}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<ToggleSwitch IsOn="{Binding IsOn, Mode=TwoWay}" OffContent="{Binding OffContent}" OnContent="{Binding OnContent}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
原始问题
我遇到的问题就像拉伸ItemControl水平物品一样简单.当我在使用XAML时,我没有像SharedSizeGroupWPF那样的东西.
这里介绍的解决方案:不幸的是,ItemsControl中的水平拉伸内容对我不起作用.我的代码:
<ItemsControl ItemsSource="{Binding GeneralBoolSettings}" HorizontalContentAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<ToggleSwitch IsOn="{Binding IsOn, Mode=TwoWay}" OffContent="{Binding OffContent}" OnContent="{Binding OnContent}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
Designer的一些截图:
ItemControl具有正确的(拉伸)大小

DataTemplate已经太小了

我想避免绑定到父宽度; 在我以前的尝试中,宽度有时(重新)设置为0,我将不得不删除绑定并再次添加它.另外:请不要使用代码和/或事件捕手,必须有一个优雅的解决方案来解决这个相当基本的问题!
老实说,我有点惊讶我不能让这个工作.Mabye你可以推荐一本好书/网站来学习XAML基础知识的系统方法(当我们在这里时)?
我试图从包含大约200个条目(行)的文本文件中读取(n)大量随机行,并填充名为"recSongs"的列表框.我提供了一些简单的代码,从文本文件中检索一个随机行,但我想要检索n金额.
这是我的代码.
var lines = File.ReadAllLines(@"file.txt");
var r = new Random();
var randomLineNumber = r.Next(0, lines.Length - 1);
var line = lines[randomLineNumber];
recSongs.Items.Add(line);
Run Code Online (Sandbox Code Playgroud) 我按照https://learn.microsoft.com/en-us/windows/uwp/globalizing/put-ui-strings-into-resources中的说明创建了一个 .resw 文件。虽然本地化在运行时运行良好,但在设计时不会显示任何文本。
到目前为止提出的唯一解决方案似乎只适用于 Windows 8.1 应用程序:设计时的 Windows 应用商店应用程序 ResourceLoader