gpt4 book ai didi

asp.net - 找不到类型或 namespace 名称 'Moq'(是否缺少using指令或程序集引用?)

转载 作者:行者123 更新时间:2023-12-03 09:30:16 24 4
gpt4 key购买 nike

我确实使用程序包管理器控制台安装了Moq(Install-Package Moq -version 4.1.1309.1617 -projectname EssentialTools.Tests)

我的目标是.NET FRAMEWORK 4.5,(我确实尝试将其更改为4 Client Profile),仍然出现错误。我在“使用最小起订量”下收到错误消息。任何帮助,将不胜感激。谢谢

 using EssentialTools.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System.Linq;

namespace EssentialTools.Tests
{
[TestClass]
public class UnitTest2
{

private Product[] products = {
new Product {Name = "Kayak", Category = "Watersports", Price = 275M},
new Product {Name = "Lifejacket", Category = "Watersports", Price = 48.95M},
new Product {Name = "Soccer ball", Category = "Soccer", Price = 19.50M},
new Product {Name = "Corner flag", Category = "Soccer", Price = 34.95M}
};

[TestMethod]
public void Sum_Products_Correctly()
{
// arrange
Mock<IDiscountHelper> mock = new Mock<IDiscountHelper>();
mock.Setup(m => m.ApplyDiscount(It.IsAny<decimal>()))
.Returns<decimal>(total => total);
var target = new LinqValueCalculator(mock.Object);

// act
var result = target.ValueProducts(products);

// assert
Assert.AreEqual(products.Sum(e => e.Price), result);
}

private Product[] createProduct(decimal value)
{
return new[] { new Product { Price = value } };
}

[TestMethod]
[ExpectedException(typeof(System.ArgumentOutOfRangeException))]
public void Pass_Through_Variable_Discounts()
{
// arrange
Mock<IDiscountHelper> mock = new Mock<IDiscountHelper>();
mock.Setup(m => m.ApplyDiscount(It.IsAny<decimal>()))
.Returns<decimal>(total => total);
mock.Setup(m => m.ApplyDiscount(It.Is<decimal>(v => v == 0)))
.Throws<System.ArgumentOutOfRangeException>();
mock.Setup(m => m.ApplyDiscount(It.Is<decimal>(v => v > 100)))
.Returns<decimal>(total => (total * 0.9M));
mock.Setup(m => m.ApplyDiscount(It.IsInRange<decimal>(10, 100,
Range.Inclusive))).Returns<decimal>(total => total - 5);
var target = new LinqValueCalculator(mock.Object);

// act
decimal FiveDollarDiscount = target.ValueProducts(createProduct(5));
decimal TenDollarDiscount = target.ValueProducts(createProduct(10));
decimal FiftyDollarDiscount = target.ValueProducts(createProduct(50));
decimal HundredDollarDiscount = target.ValueProducts(createProduct(100));
decimal FiveHundredDollarDiscount = target.ValueProducts(createProduct(500));

// assert
Assert.AreEqual(5, FiveDollarDiscount, "$5 Fail");
Assert.AreEqual(5, TenDollarDiscount, "$10 Fail");
Assert.AreEqual(45, FiftyDollarDiscount, "$50 Fail");
Assert.AreEqual(95, HundredDollarDiscount, "$100 Fail");
Assert.AreEqual(450, FiveHundredDollarDiscount, "$500 Fail");
target.ValueProducts(createProduct(0));
}
}
}

最佳答案

右键单击引用,然后从已安装的软件包文件夹中添加Moq。希望能帮助到你!

关于asp.net - 找不到类型或 namespace 名称 'Moq'(是否缺少using指令或程序集引用?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29441518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com