所以我正在尝试对 Umbraco 7.5.10 控制器进行单元测试。上下文已被模拟并顺利通过。然后我继续创建一个模拟 IMember 对象,但是每当我尝试设置任何属性(LastLoginDate、Name、Email 等)时,它们都没有被设置,当您在调试期间检查 inactiveMemberEmailed.Object 时,所有属性都是空值。我已经检查了 IMember 继承了什么,没有理由不应该设置它们。using NUnit.Framework;using Umbraco.Core.Models;using Site.Logic.Controllers.SurfaceControllers;using System;using Moq;using Umbraco.UnitTesting.Adapter.Support;using System.Collections.Generic;namespace Site.Tests{ [TestFixture] public class InactiveMemberCheckTest { private UmbracoSupport support = new UmbracoSupport(); private Mock<IMember> inactiveMemberEmailed; [SetUp] public void Setup() { support.SetupUmbraco(); this.inactiveMemberEmailed = new Mock<IMember>(); inactiveMemberEmailed.Object.LastLoginDate = DateTime.Today.AddMonths(-12); inactiveMemberEmailed.Object.Name = "inactiveMemberNotEmailed"; inactiveMemberEmailed.Object.Email = "email@example.co.uk"; inactiveMemberEmailed.Object.SetValue("contactId", 1); inactiveMemberEmailed.Object.SetValue("inactiveCheckEmailed", true); } [Test] public void MembersCanBeChecked() { var controller = new InactiveMemberCheckController(support.UmbracoContext); var resultInactiveEmailed = controller.InactiveCheck(inactiveMemberEmailed.Object); Assert.AreEqual(resultInactiveEmailed, true); } }}
1 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
我已经解决了我自己的问题;在设置属性之前我没有设置它们(我假设它们会在对象初始化时自动设置)所以解决这个问题的代码行是:
inactiveMemberEmailed.SetupAllProperties();
- 1 回答
- 0 关注
- 164 浏览
添加回答
举报
0/150
提交
取消