我的应用程序中有以下服务:
uaInProgressApp.factory('uaProgressService',
function(uaApiInterface, $timeout, $rootScope){
var factory = {};
factory.taskResource = uaApiInterface.taskResource()
factory.taskList = [];
factory.cron = undefined;
factory.updateTaskList = function() {
factory.taskResource.query(function(data){
factory.taskList = data;
$rootScope.$digest
console.log(factory.taskList);
});
factory.cron = $timeout(factory.updateTaskList, 5000);
}
factory.startCron = function () {
factory.cron = $timeout(factory.updateTaskList, 5000);
}
factory.stopCron = function (){
$timeout.cancel(factory.cron);
}
return factory;
});
Run Code Online (Sandbox Code Playgroud)
然后我在这样的控制器中使用它:
uaInProgressApp.controller('ua.InProgressController',
function ($scope, $rootScope, $routeParams, uaContext, uaProgressService) {
uaContext.getSession().then(function(){
uaContext.appName.set('Testing house');
uaContext.subAppName.set('In progress');
uaProgressService.startCron();
$scope.taskList = uaProgressService.taskList;
});
}
);
Run Code Online (Sandbox Code Playgroud)
所以基本上我的服务factory.taskList每5秒更新一次,我将其链接factory.taskList到$scope.taskList …
我试图在我的项目中测试一些异常,并且我遇到的一个例外是SQlException.
看来你不能new SqlException()这样做我不知道怎么能抛出一个异常,特别是没有以某种方式调用数据库(因为这些是单元测试,通常建议不要调用数据库,因为它很慢).
我正在使用NUnit和Moq,但我不确定如何伪造这个.
回应一些似乎都基于ADO.NET的答案,请注意我使用的是Linq to Sql.这样的东西就像在幕后.
根据@MattHamilton的要求提供更多信息:
System.ArgumentException : Type to mock must be an interface or an abstract or non-sealed class.
at Moq.Mock`1.CheckParameters()
at Moq.Mock`1..ctor(MockBehavior behavior, Object[] args)
at Moq.Mock`1..ctor(MockBehavior behavior)
at Moq.Mock`1..ctor()
Run Code Online (Sandbox Code Playgroud)
在尝试模型时发布到第一行
var ex = new Mock<System.Data.SqlClient.SqlException>();
ex.SetupGet(e => e.Message).Returns("Exception message");
Run Code Online (Sandbox Code Playgroud) 我想打包我的VS2010 Web应用程序项目,以便使用msdeploy进行部署.在开发机器上我可以使用:
MSBuild.exe "C:\path\to\WebApp.csproj" /target:package
Run Code Online (Sandbox Code Playgroud)
但在我的构建服务器上,我收到此错误:
错误MSB4057:项目中不存在目标"包".
我在构建服务器上缺少什么?
一些上下文:
我已经按照教程使用NuGet而没有提交包有一些成功.通过手动添加和为nuget.targets文件解决这个NuGet问题后,事情正在发挥作用.<RestorePackages><Import ...>
但是,一旦我用Mercurial克隆了存储库,我在构建时遇到以下错误:
无法找到'C:\ ...\Visual Studio 2010\Projects\MyProject\.nuget \nuget.exe'
这是有道理的,因为我的忽略模式阻止我检查exe文件.从这个相关的SO问题我推断出在版本控制中使用这个文件并不常见(或者是吗?),但是我真的不想将NuGet.exe提交给版本控制,如果我可以帮助的话.
问题:是否有方便的方法来防止需要检查NuGet.exe?
我尝试了一些谷歌,浏览文档,摆弄NuGet.targets文件,到目前为止没有运气.如果我可以动态地指向构建解决方案的特定环境的NuGet.exe似乎更可取.
我知道我可以添加exe文件,但我更愿意知道是否有其他方法来处理这个问题,或者知道为什么没有可行的替代方案.
更新:
nuget.targets文件包含一些相关的xml:
<!-- only (relevant) parts of the xml shown below -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
...
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
} …Run Code Online (Sandbox Code Playgroud) 我正在考虑将Vue.js作为Angular的替代品,到目前为止我非常喜欢它.为了感受它,我将现有的Angular项目重构为Vue项目.我只是需要与REST API进行通信.
在Angular中,我曾经为此定义了一个服务,它被注入到需要它的每个控制器中.据我所知,Vue似乎并不知道"服务"结构.如何在Vue中实现这一目标?
我考虑过vue-resource,但据我所知,它仅适用于http功能.因为我也使用jQuery,这已经过时了.
例:
我有vueComponent1和vueComponent2.两者都需要访问相同的REST资源.为了解决这个问题,我想要一个中央服务,这两个组件都可以用来处理对REST资源的请求.Angular有"服务"组件,正是这样做的.Vue没有.
我正在尝试使用远程svc Web服务.我创建了代理类svcutil.exe,之后我将该类添加到我的控制台应用程序中,但它产生了一个错误:
从另一方收到了不安全的错误或错误的安全故障.有关故障代码和详细信息,请参阅内部故障异常.
System.ServiceModel.FaultException:验证消息的安全性时发生错误
我没有创建WCF端,它是一个远程svc.请帮忙.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="EloquaDataTransferService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://secure.eloqua.com/API/1.2/DataTransferService.svc"
binding="basicHttpBinding" bindingConfiguration="EloquaDataTransferService"
contract="DataTransferService" name="EloquaDataTransferService" />
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这是我的app.config档案.我consoleApp.cs使用obj.ServiceCredentials.UserName.UserName="xxxxxx"和提供我的文件中的用户名和密码.Password="xxxXx"
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="EloquaDataTransferService" …Run Code Online (Sandbox Code Playgroud) 当我将文件值设置为logs\log-file.txt,它将在何处创建此文件夹?在/bin目录中?
我的web.config看起来像这样:
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="logs\log-file.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
</log4net>
Run Code Online (Sandbox Code Playgroud)
这是正确的记录方式:
ILog logger = LogManager.GetLogger(typeof(CCController));
logger.Error("Some Page", ex); // where ex is the exception instance
Run Code Online (Sandbox Code Playgroud) 在KnockoutJS教程中,我偶然发现了包含无法解释的变量的以下代码示例$data.
视图(html):
<!-- Folders -->
<ul class="folders" data-bind="template: { name: 'folderTemplate', foreach: folders }"></ul>
<script type="text/html" id="folderTemplate">
<li data-bind="css: { selected: $data == mailViewModel.selectedFolder() },
click: function() { mailViewModel.selectFolder($data) }">
${$data}
</li>
</script>
Run Code Online (Sandbox Code Playgroud)
视图模型(JavaScript):
var viewModel = {
// Data
folders: ['Inbox', 'Archive', 'Sent', 'Spam'],
selectedFolder: ko.observable('Inbox'),
// Behaviours
selectFolder: function (folder) {
this.selectedFolder(folder);
}
};
window.mailViewModel = viewModel;
ko.applyBindings(viewModel);
Run Code Online (Sandbox Code Playgroud)
本教程不包含任何解释该美元符号的用途及其$data来源.该变量$data未定义,当我重命名为$datato的所有三个实例时$foobar,该示例不再起作用.
这里有什么样的魔力?
canLoad和之间有什么区别canActivate?
export interface Route {
path?: string;
pathMatch?: string;
matcher?: UrlMatcher;
component?: Type<any>;
redirectTo?: string;
outlet?: string;
canActivate?: any[];
canActivateChild?: any[];
canDeactivate?: any[];
canLoad?: any[];
data?: Data;
resolve?: ResolveData;
children?: Routes;
loadChildren?: LoadChildren;
}
Run Code Online (Sandbox Code Playgroud)
什么时候我应该选哪一个?
我们有一个使用Entity Framework 5的Visual Studio 2012 ASP.NET MVC项目.
有些单元测试依赖于数据库.在测试项目中设置app.config文件以使用中央SQL Server数据库可以正常工作.
但是,使用LocalDb会更好,因此每个开发人员在运行测试时都有自己的数据库.特别是因为我们希望DropCreateDatabaseAlways在运行时设置测试.
但是,我无法让设置工作.如果我在app.config中尝试这个:
<add name="TestDb"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=unittestdb;
Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\unittestdb.mdf"
providerName="System.Data.SqlClient" />
Run Code Online (Sandbox Code Playgroud)
我明白了:
System.Data.SqlClient.SqlException:发生文件激活错误.物理文件名'\ unittestdb.mdf'可能不正确.诊断并更正其他错误,然后重试该操作.CREATE DATABASE失败.无法创建列出的某些文件名.检查相关错误.
听起来它想要mdf文件已经存在,这似乎很奇怪,因为它试图创建数据库.手动创建mdf文件不会更改错误消息.
unit-testing mstest entity-framework-5 localdb visual-studio-2012
asp.net-mvc ×2
c# ×2
javascript ×2
.net ×1
angular ×1
angularjs ×1
html ×1
knockout.js ×1
localdb ×1
log4net ×1
logging ×1
moq ×1
msbuild ×1
msdeploy ×1
mstest ×1
nuget ×1
package ×1
rest ×1
sqlexception ×1
unit-testing ×1
vue.js ×1
wcf ×1