所以我正在尝试对 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);
}
}
}
饮歌长啸
相关分类