我是Autofixture的新手,但我非常喜欢它所提供的功能,我有一个处理不同类型的Push通知的类,对于每个可能的类型,我都有一个Enum。
我有一个处理不同类型的Push通知的类,对于每一种可能的类型,我都有一个Enum.我想让Autofixture为每一个enum类型创建一个对象,但是还不能做到。
我的简单通知类是这样的。
public class PushNotificationModel
{
public string CustomerId { get; set; }
public EPushNotifications NotificationType { get; set; }
public bool EnableNotification { get; set; }
}
有了enum:
public enum EPushNotifications
{
DailyConsumption,
WeeklyConsumption,
MonthlyConsumption,
QuarterlyConsumption,
Marketing
}
我用XUnit来做后面的断言。
任何帮助都是非常感激的 :)
你可以枚举一个枚举
var builder = new Fixture().Build<PushNotificationModel>();
var allTypes = Enum.GetValues(typeof(EPushNotifications))
.Select(value => (EPushNotifications)value)
.Select(type => builder.With(e => NotificationType, type).Create())
.ToArray();