2022-06-30 01:46:41 +02:00
|
|
|
|
using System.Reflection;
|
2021-05-25 19:23:47 +02:00
|
|
|
|
using AutoFixture;
|
2021-12-16 15:35:09 +01:00
|
|
|
|
using AutoFixture.Xunit2;
|
2022-02-10 19:48:06 +01:00
|
|
|
|
using Bit.Core.Entities;
|
2021-12-16 15:35:09 +01:00
|
|
|
|
using Bit.Core.Enums;
|
2021-05-25 19:23:47 +02:00
|
|
|
|
|
2022-08-29 21:53:48 +02:00
|
|
|
|
namespace Bit.Core.Test.AutoFixture.PolicyFixtures
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2022-08-29 21:53:48 +02:00
|
|
|
|
internal class PolicyCustomization : ICustomization
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2022-08-29 21:53:48 +02:00
|
|
|
|
public PolicyType Type { get; set; }
|
2021-05-25 19:23:47 +02:00
|
|
|
|
|
2022-08-29 21:53:48 +02:00
|
|
|
|
public PolicyCustomization(PolicyType type)
|
|
|
|
|
{
|
|
|
|
|
Type = type;
|
|
|
|
|
}
|
2021-05-25 19:23:47 +02:00
|
|
|
|
|
2022-08-29 21:53:48 +02:00
|
|
|
|
public void Customize(IFixture fixture)
|
|
|
|
|
{
|
|
|
|
|
fixture.Customize<Policy>(composer => composer
|
|
|
|
|
.With(o => o.OrganizationId, Guid.NewGuid())
|
|
|
|
|
.With(o => o.Type, Type)
|
|
|
|
|
.With(o => o.Enabled, true));
|
|
|
|
|
}
|
2022-08-29 20:53:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 21:53:48 +02:00
|
|
|
|
public class PolicyAttribute : CustomizeAttribute
|
2022-08-29 20:53:16 +02:00
|
|
|
|
{
|
2022-08-29 21:53:48 +02:00
|
|
|
|
private readonly PolicyType _type;
|
|
|
|
|
|
|
|
|
|
public PolicyAttribute(PolicyType type)
|
|
|
|
|
{
|
|
|
|
|
_type = type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override ICustomization GetCustomization(ParameterInfo parameter)
|
|
|
|
|
{
|
|
|
|
|
return new PolicyCustomization(_type);
|
|
|
|
|
}
|
2021-05-25 19:23:47 +02:00
|
|
|
|
}
|
|
|
|
|
}
|