Windows能够将填充程序应用于错误行为的应用程序.垫片用于拦截API调用并更改它.例如,垫片可用于:
该应用程序兼容性的无线工具包已经可以应用到自己的错误,应用程序运行得相当多的现有的垫片.下面是一个忽略API调用而是调用完全不同的API的示例:
alt text http://i34.tinypic.com/5n5h5c.png
我需要一个垫片,这不是微软已经写过的数百个垫片之一.我需要一个自定义垫片.
在我的情况下,我想拦截调用:
GetSystemMetrics(0x1000)
Run Code Online (Sandbox Code Playgroud)
所以它返回0.我找不到任何关于如何给我自己的DLL的信息,这将有我需要的修复.我甚至不知道你是否可以创建自定义垫片.
Windows是否支持自定义填充程序?
嗨我正在使用grunt browserify任务来设置我的代码,我已经在jQuery中填充了,我现在正在尝试包含jquery.tablesorter.
jquery插件可以用这种方式与browserify一起使用吗?
shim: {
jquery: {
path: 'lib/bower/jquery/jquery.js',
exports: '$'
},
'jquery.tablesorter': {
path: 'lib/bower/jquery.tablesorter/js/jquery.tablesorter.js',
exports: 'tablesorter',
depends: {
jquery: '$',
}
}
}
Run Code Online (Sandbox Code Playgroud) 我偶然发现了这个项目:https://github.com/termi/ES5-DOM-SHIM,它在包括旧IE在内的所有浏览器中提供了几乎完整的ES5支持.
我一直在纯JS项目中使用它,但现在我必须在项目中使用jquery/mootools/prototype(使用High Charts).
即使只包含jquery脚本也会导致IE8中出现错误以及此shim.我怎样才能保持两全其美?
我的文档头看起来像这样:
<!--[if lte IE 8]>
<script src="/js/a.ie8.js"></script>
<![endif]-->
<script src="/js/a.js"></script>
<script src="/js/jquery.1.8.2.js"></script>
<script src="/js/main.js"></script>
Run Code Online (Sandbox Code Playgroud) 我试图在VS 2012终极中制作一个垫片,如MSDN网站中所述:
[TestClass]
public class TestClass1
{
[TestMethod]
public void TestCurrentYear()
{
int fixedYear = 2000;
using (ShimsContext.Create())
{
// Arrange:
// Detour DateTime.Now to return a fixed date:
System.Fakes.ShimDateTime.NowGet =
() =>
{ return new DateTime(fixedYear, 1, 1); };
// Instantiate the component under test:
var componentUnderTest = new MyComponent();
// Act:
int year = componentUnderTest.GetTheCurrentYear();
// Assert:
// This will always be true if the component is working:
Assert.AreEqual(fixedYear, year);
}
}
}
Run Code Online (Sandbox Code Playgroud)
请参阅http://msdn.microsoft.com/en-us/library/hh549176.aspx
但是当我编译我的测试项目时,我在输出中得到了一个概念:
警告:无法生成一些假货.有关完整的详细信息,请将此文件中Fakes元素的Diagnostic属性设置为"true"并重建项目.
我该如何解决此警告?
我正在为一个项目的客户工作,现有的代码/测试正在使用MS Fakes库和Shims来隔离测试等...
我在试用版上安装了VS 2015企业版,一切都很好.通过我的MSDN订阅,我接受了VS 2015 Professional,现在测试没有运行,失败了:
Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables.
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.ResolveProfilerPath()
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.Initialize()
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider()
at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.CreateContext()
at Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create()
Run Code Online (Sandbox Code Playgroud)
看着垫片试图使用Intellitrace,VS2015没有给我.除了购买VS的企业版之外,任何人都知道这个方法吗?
我想创建一个不透明度模糊叠加层,类似于Windows Aero或iOS7.不幸的是,filter: blur()或filter: url(#svgBlur)属性只能应用于元素,而不是它背后的内容.
为了解决这个问题,我们需要一份模糊的背景副本.这在FX中可以使用background: -moz-element(#elementId)实验性CSS属性.使用它我只能在FX中获得我想要的效果.
还有其他的 问题,关于解决模糊问题,一个解决方案似乎是使用的html2Canvas插头.
然而,这是重新创建整个模糊内容,包括手动重新创建的样式等.这是非常令人印象深刻的工作,但对于这种效果来说,似乎是大规模的过度杀伤(包括性能和大小).
我想要做的是创造是某种垫片只是为了-moz-element.看起来应该可以使用SVGforeignObject,但是如果您的HTML不是有效的XML,则会出现安全问题并且会失败.
是否有任何方式来模拟-moz-element(使用画布,SVG或其他)我不需要解析/重绘整个重叠区域?
我正在学习在单元测试中使用垫片.我正在尝试使用DateTime的经典示例,来自以下链接:http: //www.wiliam.com.au/wiliam-blog/getting-started-with-microsoft-fakes
我可以在单元测试项目中为系统引用添加Fakes,但是当我尝试使用System.Fakes.ShimDateTime时,它告诉我:
The type or namespace name 'ShimDateTime' does not exist in the namespace 'System.Fakes' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
如果我检查System.Fakes下可用的内容,我只看到存根和没有垫片,所以我似乎缺少一些产生垫片的东西?
不确定它是否相关,但这是System.fakes文件中的(默认)内容:
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="System" Version="4.0.0.0"/>
</Fakes>
Run Code Online (Sandbox Code Playgroud)
我正在使用Visual Studio 2015. VS2015 14.0.25420.01 Update 3,我的项目在.NET Framework 4.5.2中运行
实际上我的项目在添加System的假货之后无法正确编译,因此甚至没有尝试使用ShimDateTime.我得到的编译错误是:
The type or namespace name 'EventSourceCreatedEventArgs' does not exist in the namespace 'System.Diagnostics.Tracing' (are you missing an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
这来自\ UnitTestProject1\obj\Debug\Fakes\m\f.csproj和文件f.cs在线:[mqttf :: Microsoft.QualityTools.Testing.Fakes.Stubs.StubClass(typeof(global :: Syst) em.Diagnostics.Traci ng.EventSourceCreate dEventArgs))]
谁能让我走上正确的轨道,在System.Fakes下获得ShimDateTime?
我正在尝试编写一个涵盖以下行的单元测试
var fileFullName = fileInfo.FullName;
Run Code Online (Sandbox Code Playgroud)
其中fileInfo是FileInfo的一个实例.
我使用fakes来填充FileInfo对象,但是我无法为FullName属性提供值,因为它是从基类继承的.
对于未继承的Name属性,我可以这样做:
ShimFileInfo.AllInstances.NameGet = info => OriginalFullName;
Run Code Online (Sandbox Code Playgroud)
Microsoft提供的答案是在基类上创建填充程序,在本例中为FileSystemInfo.但如果我试试这个:
ShimFileSystemInfo.AllInstances.FullNameGet = info => OriginalFullName;
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为FileSystemInfo是一个无法创建的抽象类,因此无法进行填充.
在这种特殊情况下,我可以解决它,因为我可以结合DirectoryName和Name属性使其可测试,但似乎很疯狂,我不能只使用我想要的属性,因为它恰好来自基地.
有没有人来解决这个问题并设法解决它?
所以我对它的实现方式感兴趣.基本上:我怎样才能自己重新实现同样的事情?......我不打算这样做.只是了解.
根本问题是:(?)如何拦截类实例化?如何在一个实例中替换它,在另一个实现中替换它的原始或甚至不同的实现?
如何拦截静态方法或密封类甚至是可能的.
这与垫片/痣有关,而不是存根.
我能够为Array#includes找到一个polyfill(堆栈溢出)并将其添加到typescript但是在我的文件中添加一个小的导入后它变成了一个模块(我明白他们为什么要这样做导出,但为什么要导入)我再也无法修改全局命名空间了.
如何修复polyfill?
interface Array<T> {
includes(searchElement: T) : boolean;
}
// Add Array includes polyfill if needed
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes#Polyfill
if (!Array.prototype.includes) {
Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
'use strict';
var O = Object(this);
var len = parseInt(O.length, 10) || 0;
if (len === 0) {
return false;
}
var n = parseInt(arguments[1], 10) || 0;
var k;
if (n >= 0) {
k = n;
} else {
k = len + n;
if (k < 0) {k …Run Code Online (Sandbox Code Playgroud) shim ×10
c# ×3
javascript ×2
jquery ×2
unit-testing ×2
.net ×1
browserify ×1
canvas ×1
css ×1
ecmascript-5 ×1
firefox ×1
gruntjs ×1
inheritance ×1
moles ×1
polyfills ×1
svg ×1
typescript ×1
windows ×1