365真网址-365的真正网址

365真网址-365的真正网址

JustMock-hero
Support for .NET 5, .NET 6, .NET 7 & .NET framework

Telerik JustMock

最快、最灵活、最完整的模拟工具
for crafting unit tests.

big_wave_dblue_hero

探索365真网址的一些惊人的功能

ninja-peeking
[TestMethod]
public void ShouldMockGenericClass()
{
    int expectedValue = 1;

    // Arrange
    // Creating a mock instance of the "FooGeneric" class.
    var foo = Mock.Create<FooGeneric<int>>();

    // When the virtual foo.使用任何整数作为参数调用Get(),它应该返回expectedValue.
    Mock.Arrange(() => foo.Get(Arg.IsAny<int>())).Returns(expectedValue);

    // Act
    int actualValue = foo.Get(0);

    // Assert
    Assert.AreEqual(expectedValue, actualValue);
}
                        
<TestMethod> _
Public Sub ShouldMockGenericClass()
    Dim expectedValue As Integer = 1

    ' Arrange
    ' Creating a mock instance of the "FooGeneric" class.
    Dim foo = Mock.Create(Of FooGeneric(Of Integer))()

    ' When the virtual foo.使用任何整数作为参数调用Get(),它应该返回expectedValue.
    Mock.Arrange(Function() foo.[Get](Arg.IsAny(Of Integer)())).Returns(expectedValue)

    ' Act
    Dim actualValue As Integer = foo.[Get](0)

    ' Assert
    Assert.AreEqual(expectedValue, actualValue)
End Sub
                        
[TestMethod]
public void ShouldAssertWithCustomSelect()
{
    var simpleDataInstance = new SimpleData();

    //当simpleDataInstance . //.如果调用Products_GET,它应该返回预期的集合.
    Mock.Arrange(() => simpleDataInstance.Products).ReturnsCollection(ReturnExpextedCollectionOfProducts());

    为simpleDataMock应用LINQ查询.Products.
    var actual = (from p in simpleDataInstance.Products
                    where p.UnitsInStock == 50
                    select p.ProductID).SingleOrDefault();

    // Assert
    Assert.AreEqual(2, actual);
}
                        
<TestMethod> _
Public Sub ShouldAssertWithCustomSelect()
    Dim simpleDataInstance = New SimpleData()

    ' Arrange -当simpleDataInstance ..如果调用Products_GET,它应该返回预期的集合.
    Mock.Arrange(Function() simpleDataInstance.Products).ReturnsCollection(ReturnExpextedCollectionOfProducts())

    为simpleDataMock应用LINQ查询.Products.
    Dim actual = (From p In simpleDataInstance.Products _
                    Where p.UnitsInStock = 50 _
                    Select p.ProductID).SingleOrDefault()

    ' Assert
    Assert.AreEqual(2, actual)
End Sub
                        
[TestMethod]
public void DoPublic_OnExecute_ShouldCallDoPrivate()
{
    var isCalled = false;
    
    Foo foo = new Foo();
    
    //当从foo实例调用非公共方法DoPrivate()时, 
    //它应该将isCalled设置为true而不是执行它原来的逻辑.
    Mock.NonPublic.Arrange(foo, "DoPrivate").DoInstead(() => isCalled = true);
    
    // Act
    foo.DoPublic(); // dopubpublic()应该调用DoPrivate().
    
    // Assert
    Assert.IsTrue(isCalled);
}
                        
<TestMethod>
Public Sub DoPublic_OnExecute_ShouldCallDoPrivate()
    Dim isCalled = False

    Dim foo As New Foo()

    当从foo实例调用非公共方法DoPrivate()时, 
    '它应该将isCalled设置为true,而不是执行它原来的逻辑.
    Mock.NonPublic.Arrange(foo, "DoPrivate").DoInstead(Function() InlineAssignHelper(isCalled, True))

    '行为- dopubpublic()应该调用DoPrivate().
    foo.DoPublic()

    ' Assert
    Assert.IsTrue(isCalled)
End Sub
                        
[TestMethod]
public void ShouldFakeStaticPropertyGet()
{
    bool isCalled = false;
    var expected = 1;

    // Arrange
    //获取静态实例(Foo),忽略构造函数并应用严格的行为.
    //如果不模拟构造函数,将抛出NotImplementedException.
    Mock.SetupStatic(typeof(Foo), Behavior.Strict, StaticConstructor.Mocked);

    // When the static(Foo.FooProp_GET)属性, 
    //它应该将true赋值给isCalled并返回expected.
    Mock.Arrange(() => Foo.FooProp).DoInstead(() => { isCalled = true; }).Returns(expected);

    // Act
    var actual = Foo.FooProp;

    // Assert
    Assert.AreEqual(expected, actual);
    Assert.IsTrue(isCalled);
}

                        
<TestMethod>
Public Sub ShouldFakeStaticPropertyGet()
    Dim isCalled As Boolean = False
    Dim expected = 1

    ' Arrange
    '让静态实例(Foo)准备模仿忽略构造函数和应用严格的行为.
    '如果不模拟构造函数,将抛出NotImplementedException.
    Mock.SetupStatic(GetType(Foo), Behavior.[Strict], StaticConstructor.Mocked)

    ' When the static(Foo.FooProp_GET)属性, 
    '它应该将true赋值给isCalled,并返回expected.
    Mock.Arrange(Function() Foo.FooProp).DoInstead(Sub() isCalled = True).Returns(expected)

    ' Act
    Dim actual = Foo.FooProp

    ' Assert
    Assert.AreEqual(expected, actual)
    Assert.IsTrue(isCalled)
End Sub

                        
[TestMethod]
public void ShouldApplyIgnoreInstanceToVirtual()
{
    var expected = 10;

    // Arrange
    //创建一个"Calculus"类的模拟实例.
    //此mock也将用作给定类型的假类型,用于将未来实例期望应用于该类型.
    var calculus = Mock.Create<Calculus>();

    // When calculus.Sum()被调用时,它应该返回预期值.
    //同样,这个期望将应用于所有新创建的Calculus类实例 
    // during the test.
    Mock.Arrange(() => calculus.Sum()).IgnoreInstance().Returns(expected);

    // Act
    var valueFromExistingInstance = calculus.Sum();
    var valueFromNewInstance = new Calculus().Sum();

    // Assert
    Assert.AreEqual(expected, valueFromExistingInstance); //验证一个已经存在的实例的值.
    Assert.AreEqual(expected, valueFromNewInstance); //验证新创建实例的值.
}

                        
<TestMethod>
Public Sub ShouldApplyIgnoreInstanceToVirtual()
    Dim expected = 10

    ' Arrange
    '创建' Calculus '类的模拟实例.
    这个mock还将用作给定类型的伪,用于将未来实例期望应用于该类型.
    Dim calculus = Mock.Create(Of Calculus)()

    ' When calculus.Sum()被调用时,它应该返回预期值.
    同样,这个期望将应用于所有新创建的Calculus类实例 
    ' during the test.
    Mock.Arrange(Function() calculus.Sum()).IgnoreInstance().Returns(expected)

    ' Act
    Dim valueFromExistingInstance = calculus.Sum()
    Dim valueFromNewInstance = New Calculus().Sum()

    ' Assert
    Assert.AreEqual(expected, valueFromExistingInstance) '从已经存在的实例验证值.
    Assert.AreEqual(expected, valueFromNewInstance) '验证新创建实例的值.
End Sub

                        
[TestMethod]
public void ShouldAssertCustomValueForDateTimeNow()
{
    var expected = new DateTime(1900, 4, 12);

    //安排-在这里365真网址安排,当DateTime.它应该返回预期的DateTime.
    Mock.Arrange(() => DateTime.Now).Returns(expected);

    // Act
    var now = DateTime.Now;

    // Assert -日期确实是安排好的.
    Assert.AreEqual(expected.Year, now.Year);
    Assert.AreEqual(expected.Month, now.Month);
    Assert.AreEqual(expected.Day, now.Day);
}

                        
<TestMethod>
Public Sub ShouldAssertCustomValueForDateTimeNow()
    Dim expected = New DateTime(1900, 4, 12)

    ' Arrange -在这里365真网址安排,当DateTime.它应该返回预期的DateTime.
    Mock.Arrange(Function() DateTime.Now).Returns(expected)

    ' Act
    Dim now = DateTime.Now

    “请断言——日期确实是事先安排好的.
    Assert.AreEqual(expected.Year, now.Year)
    Assert.AreEqual(expected.Month, now.Month)
    Assert.AreEqual(expected.Day, now.Day)
End Sub

                        
[TestMethod]
public void ShouldReturnFakeDbSet_WhenDbContextPropertyIsCalled()
{
    // Arrange
    NerdDinners nerdDinners = new NerdDinners();

    //当DBSet属性为nerdmeals时.当调用聚餐时,它应该返回一个预定义的假集合,其中包含3个项目.
    Mock.Arrange(() => nerdDinners.Dinners).ReturnsCollection(FakeDinners());

    //表演-365真网址称这些书呆子为晚宴.并搜索具有特定DinnerID的dinner.
    var actualQuery = from d in nerdDinners.Dinners
                        where d.DinnerID == 1
                        select d;

    // Assert -365真网址断言nerdmeals.实际上,聚餐集合将返回一个包含3项的集合.
    Assert.AreEqual(3, nerdDinners.Dinners.Count());
    //365真网址断言集合中只有一个元素DinnerID等于1.
    Assert.AreEqual(1, actualQuery.Count());
    Assert.AreEqual(1, actualQuery.First().DinnerID);
}
                        
<TestMethod>
Public Sub ShouldReturnFakeDbSet_WhenDbContextPropertyIsCalled()
    ' Arrange
    Dim nerdDinners As New NerdDinners()

    当DBSet属性nerdmeals.当调用聚餐时,它应该返回一个预定义的假集合,其中包含3个项目.
    Mock.Arrange(Function() nerdDinners.Dinners).ReturnsCollection(FakeDinners())

    “表演——365真网址叫书呆子晚餐.并搜索具有特定DinnerID的dinner.
    Dim actualQuery = From d In nerdDinners.Dinners Where d.DinnerID = 1D

    “断言——365真网址断言书呆子晚餐.实际上,聚餐集合将返回一个包含3项的集合.
    Assert.AreEqual(3, nerdDinners.Dinners.Count())
    “365真网址断言,在365真网址的集合中,只有一个项目的DinnerID等于1.
    Assert.AreEqual(1, actualQuery.Count())
    Assert.AreEqual(1, actualQuery.First().DinnerID)
End Sub

                        
Coppied!
Full List of Features

Why Choose JustMock

Awards

伟大——说你拥有伟大是一回事,但当别人认识到它时,这意味着更多. Telerik很荣幸能够举办以下行业奖项.

为您量身定制的软包装

你可以单独购买Telerik JustMock,也可以作为DevCraft捆绑包的一部分. 如果你想为所有人投保 .NET和JavaScript技术或需要一个报表, mocking or testing solution, DevCraft捆绑包提供了最大的物有所值 the most power.

ninja-175x175px-min

Buy Telerik JustMock

购买最快,最灵活和完整的模拟工具制作单元测试.

See Pricing

Starting at $399

Buy DevCraft Bundle

Get the complete bundle of .NET控件,JavaScript组件,报告,自动化测试和生产力工具.

See Pricing

Starting at $1,299

我最近放弃了另一个主要的模拟工具,转而支持JustMock. 我对其他工具的语法从来都不满意,但我在市场上找不到其他工具. 我发现JustMock是一种更愉快的体验.

Brad Irby

.NET架构师和Reengineering的作者 .NET, Reengineering .NET

当试图对遗留代码或数据库进行测试时,隔离用于测试的方法变得困难, JustMock真的开始与众不同了. 它的特性,如MsCorlib, Sealed, Static, 私有方法和实体框架模拟使其看起来不可测试, testable.

Bradley Braithwaite

软件开发人员,心满意足的编码员

我使用过一系列模拟工具,我相信JustMock的API是我迄今为止遇到的最成熟的API. 我能给予框架工具的最高赞扬是,它的语义足够可读,以至于在阅读代码时根本不需要考虑它们, JustMock就是这样.

Erik Dietrich

Software Developer, DaedTech

What's New

生成泛型方法模拟排列

在Visual Studio中生成模拟对象变得更好

JustMock现在允许您从Visual Studio中的快速操作菜单为泛型类型和方法创建模拟.

Telerik JustMock: Day-Zero支持 .NET 7

Telerik JustMock: Day-Zero支持 .NET 7

随着2022年11月的更新,365真网址发布了对 .NET 7 for all Telerik .NET产品,包括JustMock,以及它们各自的Visual Studio扩展.

Support & Learning

Industry-Leading Support

Expert and Timely Support

直接从构建此UI套件的开发人员那里获得问题的答案, 即使在你的试用期.

Contact support

Need Evaluation Help?

如果您不是开发人员或没有时间评估365真网址的产品, 把你的项目要求发给365真网址. 365真网址将评估您所需的功能,并让您了解365真网址的产品如何满足您的需求.

把你的项目要求发给365真网址
Background-NextSteps

Next Steps

See Plans & Pricing

购买单独的产品或任何捆绑

Download Free Trial

有专门的技术支持.