我正在测试我的配置文件以获取win表单应用程序.在LocalTestRun.testrunconfig中,我将其设置为复制app.config.我已经检查了Environment.CurrentDirectory测试运行的时间,文件也没有这个额外的连接字符串.这是测试方法:
[TestMethod]
public void Configuration_ConnectionStrings_Connect()
{
Console.WriteLine(Environment.CurrentDirectory);
Assert.IsTrue(System.IO.File.Exists("App.Config"));
var configFileMap = new ExeConfigurationFileMap(){ ExeConfigFilename = "App.Config"};
var config= ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
foreach (ConnectionStringSettings connectionString in config.ConnectionStrings.ConnectionStrings)
{
//Assumes all connections are to Sql server, test must be updated if not
Assert.AreEqual("System.Data.SqlClient",connectionString.ProviderName,"Test was only designed for SQL clients");
using (var cn=new System.Data.SqlClient.SqlConnection(connectionString.ConnectionString))
{
cn.Open();
Assert.AreEqual(System.Data.ConnectionState.Open,cn.State);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我迭代时,config.ConnectionStrings.ConnectionStrings我有一个不在文件中的额外配置字符串:
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
Run Code Online (Sandbox Code Playgroud)
这不是,也从来不是一个asp.net项目.
这是配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" …Run Code Online (Sandbox Code Playgroud) 是否可以模拟存根/模拟的对象成员调用而不必将其定义为存根,并将返回值设置为所有单独的详细行?
例:
[TestMethod]
public void AssignedPermissions_AssociateExists_ReturnsEdit_Rhino()
{
//Arrange
var fakeConfiguration = MockRepository.GenerateStub<IDomainControllerConfiguration>();
var fakeAssociateRepository = MockRepository.GenerateStub<IAssociateRepository>();
fakeConfiguration.Stub(x => x.AssociateRepository).Return(fakeAssociateRepository);
fakeAssociateRepository.Stub(x=>x.GetAssociatesByRole(null,false,null)).IgnoreArguments()
.Return(new IAssociate[]{MockRepository.GenerateStub<IAssociate>()});
var domain = new DomainController(fakeConfiguration);
const AssignedPermission expected = AssignedPermission.Edit;
//Act
AssignedPermission actual = domain.AssignedPermissions();
//Assert
Assert.AreEqual(expected, actual);
}
Run Code Online (Sandbox Code Playgroud)
所有那些临时变量是否只是为了存根嵌套方法调用?
获取控制器的标准return语句:
return View("Index");
Run Code Online (Sandbox Code Playgroud)
有没有办法让这个东西编译时安全?使用静态反射或其他一些技巧?
所以当我放
<#@ assembly name="$(ProjectDir)$(OutDir)$(TargetFileName)" #> 它说,在T4模板中
The assembly $(ProjectDir)$(OutDir)$(TargetFileName) could not be loaded. There was an exception during load: A dependency could not be found!
据我所知,T4已更新为不锁定程序集,因此引用当前项目应该是安全的,但在具有依赖项的项目中,它似乎是可怕的.
如何找出无法加载的程序集?
由于可观察性通常IDisposable如何改变,如果有的话,需要在事件处理程序中使用弱引用,或者任何其他基于事件的内存泄漏/ GC锁定引用?
虽然我主要关心/需要的是WPF,但我正在寻找更广泛的例子,并试图了解我可能需要弱引用的地方.
F#Observable.add没有提供解开事件的方法,因此我认为它不太可能成为泄密源.示例代码:
type Notifier() =
let propChanged = new Event<_,_>()
member __.Foo() = ()
interface INotifyPropertyChanged with
[<CLIEvent>]
member __.PropertyChanged = propChanged.Publish
abstract member RaisePropertyChanged : string -> unit
default x.RaisePropertyChanged(propertyName : string) = propChanged.Trigger(x, PropertyChangedEventArgs(propertyName))
Notifier() :?> INotifyPropertyChanged
|> Observable.add(fun _ -> printfn "I'm hooked on you")
Run Code Online (Sandbox Code Playgroud) 我希望能够做到
let upcast'<'T,'TResult when 'T :> 'TResult> (y:'T) = y |> upcast
然而,然后限制'T为'TResult而不是它可以被投射到的东西'TResult
我知道我可以
|> fun x -> x :> 'TResult
|> fun x -> upcast x
|> fun x -> x :> _
但当时如果我做什么都在该行我要回去,并把()周围的fun x -> upcast x或它认为我在做什么是的一部分fun x功能.
我可以定义或存在一种方法可以
|> upcast |> 不起作用
|> ( ( :> ) 'TResult) 不起作用,而且很乱
编辑 回应Thomas Petricek - 最小失败的自动翻译样本:
module Test =
let inline f'<'t>():IReadOnlyCollection<'t> =
List.empty
|> ResizeArray
|> System.Collections.ObjectModel.ReadOnlyCollection …Run Code Online (Sandbox Code Playgroud) 参数字典包含非可空类型'System.Int32'的参数'appId'的空条目,用于'HLIT_TicketingMVC.Controllers.TicketController'中的方法'System.Web.Mvc.ContentResult CheckForInstaller(Int32)'.可选参数必须是引用类型,可空类型,或者声明为可选参数.
function SubmitAjax(url, message, successFunc, errorFunc) {
$.ajax({
type:'POST',
url:url,
data:message,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success:successFunc,
error:errorFunc
});
};
Run Code Online (Sandbox Code Playgroud)
数据对象构建如下:
var message={"appId":application.val()};
Run Code Online (Sandbox Code Playgroud)
我也尝试了一个jsonified字符串:
var message="{'appId':"+application.val()+"}";
Run Code Online (Sandbox Code Playgroud)
和
var message="{'appId':'"+application.val()+"'}";
Run Code Online (Sandbox Code Playgroud)
我在尝试发布之前验证了消息是否带有正确的int值.鼠标在调试器上最近显示:{appId="6"}
控制器上的方法签名是:
public ContentResult CheckForInstaller(int appId)
Run Code Online (Sandbox Code Playgroud)
当我从方法签名中删除参数时,它确实触及了内部的断点,所以它是需要某种属性的签名,或者我认为消息没有正确构建.
我在控制器上有2个动作:
public class CalculatorsController : Controller
{
//
// GET: /Calculators/
public ActionResult Index()
{
return RedirectToAction("Accounting");
}
public ActionResult Accounting()
{
var combatants = Models.Persistence.InMemoryCombatantPersistence.GetCombatants();
Debug.Assert(combatants != null);
var bvm = new BalanceViewModel(combatants);
Debug.Assert(bvm!=null);
Debug.Assert(bvm.Combatants != null);
return View(bvm);
}
}
Run Code Online (Sandbox Code Playgroud)
调用Index方法时,我会得到一个null模型.当通过它的url直接调用Accounting方法时,我会得到一个水合模型.
我发现所有涉及intellisense的问题似乎都是指自定义配置设置.我试图在.net标准部分上获取intellisense,该部分已从web.config移到service.config中.
有办法吗?
我试图找到一个简单的解决方案,而不是手动工作来引用包.在.fsx文件中.
LinqPad 4 让我简单地添加nuget包
LinqPad 5 beta 让我添加nuget包
VS2015 不允许您下载/安装fsx文件的包(仅限于项目)VSCode 不允许您下载/安装fsx文件的nuget或paket包.所以我最终不得不在VS2015中使用.fsx,同时使用linqpad来获取下载的软件包(对于像templatus这样下载exe而不是dll的软件包仍然会失败).然后我可以将它们作为参考
#I @"..\LINQPad\NuGet.FW46\FParsec\FParsec.1.0.2\lib\net40-client\" // references AppData\local\ ... since . is %localappdata%\TEMP
Run Code Online (Sandbox Code Playgroud)
我不想创建一个项目.我有大量单独的脚本,可以由其他人按需单独维护和使用.
是否有一个IDE(或其中一个的修复/扩展)可以为F#.fsx文件提供智能感知,自动完成和包管理,这些文件可以轻松地从用户到用户,从机器到机器工作?
asp.net-mvc ×3
f# ×3
c# ×2
unit-testing ×2
.net ×1
app-config ×1
f#-scripting ×1
intellisense ×1
jquery ×1
memory-leaks ×1
rhino-mocks ×1
t4 ×1
wcf ×1
web-config ×1