本文整理汇总了C#中Mocks.CreateReactEnvironment方法的典型用法代码示例。如果您正苦于以下问题:C# Mocks.CreateReactEnvironment方法的具体用法?C# Mocks.CreateReactEnvironment怎么用?C# Mocks.CreateReactEnvironment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mocks
的用法示例。
在下文中一共展示了Mocks.CreateReactEnvironment方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteWithLargerStackIfRequiredWithNoNewThread
public void ExecuteWithLargerStackIfRequiredWithNoNewThread()
{
var mocks = new Mocks();
var environment = mocks.CreateReactEnvironment();
environment.ExecuteWithLargerStackIfRequired<int>("foo");
mocks.Engine.Verify(x => x.CallFunction<int>("foo"), Times.Exactly(1));
}
示例2: ExecuteWithLargerStackIfRequiredWithNoNewThread
public void ExecuteWithLargerStackIfRequiredWithNoNewThread()
{
var mocks = new Mocks();
var environment = mocks.CreateReactEnvironment();
environment.ExecuteWithLargerStackIfRequired<int>("1+1");
mocks.Engine.Verify(x => x.Evaluate<int>("1+1"));
}
示例3: ShouldNotTransformJsxIfNoAnnotationPresent
public void ShouldNotTransformJsxIfNoAnnotationPresent()
{
var mocks = new Mocks();
var environment = mocks.CreateReactEnvironment();
var input = "<div>Hello World</div>";
var output = environment.TransformJsx(input);
Assert.Equal(input, output);
}
示例4: GeneratesContainerIdIfNotProvided
public void GeneratesContainerIdIfNotProvided()
{
var mocks = new Mocks();
var environment = mocks.CreateReactEnvironment();
mocks.Config.Setup(x => x.Scripts).Returns(new List<string>());
var component1 = environment.CreateComponent("ComponentName", new { });
var component2 = environment.CreateComponent("ComponentName", new { });
Assert.AreEqual("react1", component1.ContainerId);
Assert.AreEqual("react2", component2.ContainerId);
}
示例5: ExecuteWithBabelShouldThrowIfBabelDisabled
public void ExecuteWithBabelShouldThrowIfBabelDisabled()
{
var mocks = new Mocks();
mocks.Config.Setup(x => x.LoadBabel).Returns(false);
var environment = mocks.CreateReactEnvironment();
Assert.Throws<BabelNotLoadedException>(() =>
{
environment.ExecuteWithBabel<string>("foobar");
});
}
示例6: ShouldTransformJsxIfAnnotationPresent
public void ShouldTransformJsxIfAnnotationPresent()
{
var mocks = new Mocks();
var environment = mocks.CreateReactEnvironment();
const string input = "/** @jsx React.DOM */ <div>Hello World</div>";
environment.TransformJsx(input);
mocks.Engine.Verify(x => x.Evaluate<string>(
@"global.JSXTransformer.transform(""/** @jsx React.DOM */ <div>Hello World</div>"").code"
));
}
示例7: ExecuteWithLargerStackIfRequiredShouldBubbleExceptions
public void ExecuteWithLargerStackIfRequiredShouldBubbleExceptions()
{
var mocks = new Mocks();
var environment = mocks.CreateReactEnvironment();
// Always fail
mocks.Engine.Setup(x => x.CallFunction<int>("foobar"))
.Throws(new Exception("Something bad happened :("));
Assert.Throws<Exception>(() =>
{
environment.ExecuteWithLargerStackIfRequired<int>("foobar");
});
}
示例8: ExecuteWithLargerStackIfRequiredWithNewThread
public void ExecuteWithLargerStackIfRequiredWithNewThread()
{
var mocks = new Mocks();
var environment = mocks.CreateReactEnvironment();
// Fail the first time Evaluate is called, succeed the second
// http://stackoverflow.com/a/7045636
mocks.Engine.Setup(x => x.CallFunction<int>("foo"))
.Callback(() => mocks.Engine.Setup(x => x.CallFunction<int>("foo")))
.Throws(new Exception("Out of stack space"));
environment.ExecuteWithLargerStackIfRequired<int>("foo");
mocks.EngineFactory.Verify(
x => x.GetEngineForCurrentThread(It.IsAny<Action<IJsEngine>>()),
Times.Exactly(2),
"Two engines should be created (initial thread and new thread)"
);
mocks.EngineFactory.Verify(
x => x.DisposeEngineForCurrentThread(),
Times.Exactly(1),
"Inner engine should be disposed"
);
}
示例9: UsesProvidedContainerId
public void UsesProvidedContainerId()
{
var mocks = new Mocks();
var environment = mocks.CreateReactEnvironment();
mocks.Config.Setup(x => x.Scripts).Returns(new List<string>());
var component1 = environment.CreateComponent("ComponentName", new { }, "foo");
var component2 = environment.CreateComponent("ComponentName", new { });
Assert.AreEqual("foo", component1.ContainerId);
StringAssert.StartsWith("react_", component2.ContainerId);
}
示例10: ReturnsEngineToPool
public void ReturnsEngineToPool()
{
var mocks = new Mocks();
var environment = mocks.CreateReactEnvironment();
mocks.Config.Setup(x => x.ReuseJavaScriptEngines).Returns(true);
environment.CreateComponent("ComponentName", new { });
mocks.EngineFactory.Verify(x => x.GetEngine(), Times.Once);
environment.ReturnEngineToPool();
environment.CreateComponent("ComponentName", new { });
mocks.EngineFactory.Verify(x => x.GetEngine(), Times.AtLeast(2));
}