AutoFixture 能否为每个可能的枚举创建一个对象列表,该枚举是 class 的 属性?
Can AutoFixture create a list of objects for each possible enum that is a property of that class?
我是 Autofixture 的新手,但我非常喜欢它提供的功能。
我有一个 class 可以处理不同类型的推送通知,对于每种可能的类型,我都有一个枚举。
我希望 Autofixture 为每种枚举类型创建一个对象,但还不能这样做。
我的简单通知 class 如下所示:
public class PushNotificationModel
{
public string CustomerId { get; set; }
public EPushNotifications NotificationType { get; set; }
public bool EnableNotification { get; set; }
}
枚举:
public enum EPushNotifications
{
DailyConsumption,
WeeklyConsumption,
MonthlyConsumption,
QuarterlyConsumption,
Marketing
}
之后我使用 XUnit 进行断言。
非常感谢任何帮助! :)
你可以枚举一个enum
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();
我是 Autofixture 的新手,但我非常喜欢它提供的功能。
我有一个 class 可以处理不同类型的推送通知,对于每种可能的类型,我都有一个枚举。 我希望 Autofixture 为每种枚举类型创建一个对象,但还不能这样做。
我的简单通知 class 如下所示:
public class PushNotificationModel
{
public string CustomerId { get; set; }
public EPushNotifications NotificationType { get; set; }
public bool EnableNotification { get; set; }
}
枚举:
public enum EPushNotifications
{
DailyConsumption,
WeeklyConsumption,
MonthlyConsumption,
QuarterlyConsumption,
Marketing
}
之后我使用 XUnit 进行断言。
非常感谢任何帮助! :)
你可以枚举一个enum
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();