public void SubmitMessagesToQueue_OneMessage_SubmitSuccessfully()
{
var messageServiceClientMock = new Mock<IMessageServiceClient>();
var queueableMessage = CreateSingleQueueableMessage();
var message = queueableMessage[0];
var xml = QueueableMessageAsXml(queueableMessage);
messageServiceClientMock.Setup(proxy => proxy.SubmitMessage(xml)).Verifiable();
//messageServiceClientMock.Setup(proxy => proxy.SubmitMessage(It.IsAny<XmlElement>())).Verifiable();
var serviceProxyFactoryStub = new Mock<IMessageServiceClientFactory>();
serviceProxyFactoryStub.Setup(proxyFactory => proxyFactory.CreateProxy()).Returns(essageServiceClientMock.Object);
var loggerStub = new Mock<ILogger>();
var client = new MessageClient(serviceProxyFactoryStub.Object, loggerStub.Object);
client.SubmitMessagesToQueue(new List<IMessageRequestDTO> {message});
//messageServiceClientMock.Verify(proxy => proxy.SubmitMessage(xml), Times.Once());
messageServiceClientMock.Verify();
}
Run Code Online (Sandbox Code Playgroud)
我开始使用Moq并且有点挣扎.我正在尝试验证messageServiceClient是否正在接收正确的参数,这是一个XmlElement,但我找不到任何方法使它工作.它仅在我不检查特定值时才有效.
有任何想法吗?
部分答案:我找到了一种方法来测试发送给代理的xml是否正确,但我仍然认为这不是正确的方法.
public void SubmitMessagesToQueue_OneMessage_SubmitSuccessfully()
{
var messageServiceClientMock = new Mock<IMessageServiceClient>();
messageServiceClientMock.Setup(proxy => proxy.SubmitMessage(It.IsAny<XmlElement>())).Verifiable();
var serviceProxyFactoryStub = new Mock<IMessageServiceClientFactory>();
serviceProxyFactoryStub.Setup(proxyFactory => proxyFactory.CreateProxy()).Returns(messageServiceClientMock.Object);
var loggerStub …Run Code Online (Sandbox Code Playgroud) 不知道我在这里缺少什么,但我无法从我的.net核心应用程序中的appsettings.json获取值.我的appsettings.json为:
{
"AppSettings": {
"Version": "One"
}
}
Run Code Online (Sandbox Code Playgroud)
启动:
public class Startup
{
private IConfigurationRoot _configuration;
public Startup(IHostingEnvironment env)
{
_configuration = new ConfigurationBuilder()
}
public void ConfigureServices(IServiceCollection services)
{
//Here I setup to read appsettings
services.Configure<AppSettings>(_configuration.GetSection("AppSettings"));
}
}
Run Code Online (Sandbox Code Playgroud)
模型:
public class AppSettings
{
public string Version{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
控制器:
public class HomeController : Controller
{
private readonly AppSettings _mySettings;
public HomeController(IOptions<AppSettings> settings)
{
//This is always null
_mySettings = settings.Value;
}
}
Run Code Online (Sandbox Code Playgroud)
_mySettings永远是空的.这里有什么我想念的吗?
我有一个休息端点,它在GET调用上返回一个列表.我还有一个POST端点来添加新项目,还有一个DELETE来删除它们.这适用于Firefox和Chrome,POST和DELETE适用于IE11.但是,IE11中的GET仅适用于页面的初始加载.刷新返回缓存的数据.我已经在Angular 1中看过关于这种行为的帖子,但是Angular 2(发布候选者1)没有.
javascript http-caching typescript internet-explorer-11 angular
由于3.0 C#具有很好的语法糖,如自动属性,这大大简化了封装原理的实现.如果你将它与原子值一起使用,这是很好的,所以你可以像这样替换封装模式:
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
Run Code Online (Sandbox Code Playgroud)
只有一行:
public string FirstName { get; set; }
Run Code Online (Sandbox Code Playgroud)
我非常喜欢这个很棒的功能,因为它节省了很多开发人员的时间.
但是当你创建指向集合的属性时,事情并不是那么好.通常我会看到以两种方式之一实现的集合属性.
1)根本没有自动属性可以使用字段初始化程序:
private List<string> _names = new List<string>();
public List<string> Names
{
get { return _names; }
}
Run Code Online (Sandbox Code Playgroud)
2)使用自动属性.如果类只有一个构造函数,这种方法就可以了:
public List<string> Names { get; private set; }
public .ctor()
{
Names = new List<string>();
}
Run Code Online (Sandbox Code Playgroud)
但是当你以这样的方式处理像列表这样的可变集合时,你会破坏封装,因为这个属性的用户可以修改集合而不让容器知道(如果忘记将setter设为私有,甚至可以替换集合).
至于我,关于Encapsulate Collection模式,集合封装的正确实现应如下所示:
private readonly List<string> _names = new List<string>();
public ICollection<string> Names
{
get …Run Code Online (Sandbox Code Playgroud) 我试图通过使用REST,WCF和JSON(所有这些技术的新手)来使我的应用程序正常工作.我让'GET'正常工作.正是"POST"导致了我的问题.
正如您将在下面看到的那样,我使用JSON.stringify打包'我的JSON,然后将POST发送到REST资源.但是,当对象到达处理请求的WCF方法时,该对象始终为null.
这是代码:
$.ajax({
type: "POST",
dataType: "json",
url: "Services/ContactCompanyService.svc/contactcompanies/customers",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ contactcompany: newCustomer }),
success: function (html) { alert(html); }
});
Run Code Online (Sandbox Code Playgroud)
这是配置的东西:
<services>
<service behaviorConfiguration="ServiceBehaviour" name="ContactCompanyService">
<endpoint address="contactcompanies" behaviorConfiguration="web" binding="webHttpBinding" contract="IContactCompanyService"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
<enableWebScript/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
Run Code Online (Sandbox Code Playgroud)
这是合同:
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate …Run Code Online (Sandbox Code Playgroud) c# ×3
.net ×1
angular ×1
asp.net-core ×1
http-caching ×1
javascript ×1
jquery ×1
json ×1
moq ×1
nunit ×1
rest ×1
typescript ×1
unit-testing ×1
wcf ×1