1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-02 13:53:23 +01:00
bitwarden-server/test/Core.Test/AutoFixture/PolicyFixtures.cs

41 lines
911 B
C#
Raw Normal View History

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