mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
Freshsales integration (#1782)
* Add FreshsalesController * Add better errors * Fix formatting issues * Add comments * Add Billing.Test to solution files * Fix unit test * Format code * Address PR feedback
This commit is contained in:
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Xunit.Sdk;
|
||||
|
||||
namespace Bit.Test.Common.AutoFixture.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for collecting data from environment useful for when we want to test an integration with another service and
|
||||
/// it might require an api key or other piece of sensitive data that we don't want slipping into the wrong hands.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It probably should be refactored to support fixtures and other customization so it can more easily be used in conjunction
|
||||
/// with more parameters. Currently it attempt to match environment variable names to values of the parameter type in that positions.
|
||||
/// It will start from the first parameter and go for each supplied name.
|
||||
/// </remarks>
|
||||
public class EnvironmentDataAttribute : DataAttribute
|
||||
{
|
||||
private readonly string[] _environmentVariableNames;
|
||||
|
||||
public EnvironmentDataAttribute(params string[] environmentVariableNames)
|
||||
{
|
||||
_environmentVariableNames = environmentVariableNames;
|
||||
}
|
||||
|
||||
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
|
||||
{
|
||||
var methodParameters = testMethod.GetParameters();
|
||||
|
||||
if (methodParameters.Length < _environmentVariableNames.Length)
|
||||
{
|
||||
throw new ArgumentException($"The target test method only has {methodParameters.Length} arguments but you supplied {_environmentVariableNames.Length}");
|
||||
}
|
||||
|
||||
var values = new object[_environmentVariableNames.Length];
|
||||
|
||||
for (var i = 0; i < _environmentVariableNames.Length; i++)
|
||||
{
|
||||
values[i] = Convert.ChangeType(Environment.GetEnvironmentVariable(_environmentVariableNames[i]), methodParameters[i].ParameterType);
|
||||
}
|
||||
|
||||
return new[] { values };
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Test.Common.AutoFixture.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for requiring certain environment variables exist at the time. Mostly used for more edge unit tests that shouldn't
|
||||
/// be run during CI builds or should only be ran in CI builds when pieces of information are available.
|
||||
/// </summary>
|
||||
public class RequiredEnvironmentTheoryAttribute : TheoryAttribute
|
||||
{
|
||||
private readonly string[] _environmentVariableNames;
|
||||
|
||||
public RequiredEnvironmentTheoryAttribute(params string[] environmentVariableNames)
|
||||
{
|
||||
_environmentVariableNames = environmentVariableNames;
|
||||
|
||||
if (!HasRequiredEnvironmentVariables())
|
||||
{
|
||||
Skip = $"Missing one or more required environment variables. ({string.Join(", ", _environmentVariableNames)})";
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasRequiredEnvironmentVariables()
|
||||
{
|
||||
foreach (var env in _environmentVariableNames)
|
||||
{
|
||||
var value = Environment.GetEnvironmentVariable(env);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user