Skip to content

Commit

Permalink
add new project for fake config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ershad95 committed Jun 7, 2024
1 parent 6db9d6e commit 31611af
Show file tree
Hide file tree
Showing 63 changed files with 8,059 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17176669366108550
17177852751331060
2 changes: 1 addition & 1 deletion ServiceCollector.Core/obj/rider.project.restore.info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17176669366148605
17177852751174862
21 changes: 21 additions & 0 deletions ServiceCollector.Fake.Configuration/BaseGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AutoFixture;
using AutoFixture.AutoNSubstitute;

namespace ServiceCollector.Fake.Configuration;

public static class BaseGenerator
{
private static readonly IFixture Fixture;
static BaseGenerator()
{
Fixture = new Fixture().Customize(new AutoNSubstituteCustomization()
{
ConfigureMembers = true
});
}

public static TModel Create<TModel>()
{
return Fixture.Create<TModel>();
}
}
12 changes: 12 additions & 0 deletions ServiceCollector.Fake.Configuration/FakeConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ServiceCollector.Fake.Configuration
{
public class FakeConfiguration<TService> where TService : class
{
public TService Service { get; }

public FakeConfiguration(TService service)
{
Service = service;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
using System;
using System.Collections.Generic;
using AutoFixture;

namespace ServiceCollector.Fake
{

public static partial class ServiceConfigExtension
namespace ServiceCollector.Fake.Configuration
{
public class FakeConfigurationWithMultiEnvironment<TService>
public class FakeConfigurationWithMultiEnvironment<TService>
where TService : class
{
private readonly string _currentEnv;
internal IDictionary<string, TService> Services { get; private set; }
public IDictionary<string, TService> Services { get; private set; }

public FakeConfigurationWithMultiEnvironment(string currentEnv)
{
Expand All @@ -21,20 +14,20 @@ public FakeConfigurationWithMultiEnvironment(string currentEnv)

public void Add(string targetEnvironment, Action<TService> service)
{
var obj = AutoFixture.Create<TService>();
service(obj);
Services.Add(targetEnvironment, obj);
var serviceObject = BaseGenerator.Create<TService>();
service(serviceObject);
Services.Add(targetEnvironment, serviceObject);
}

/// <summary>
/// set current env as target env
/// </summary>
/// <param name="service"></param>
public void Add(Action<TService> service)
{
var obj = AutoFixture.Create<TService>();
service(obj);
Services.Add(_currentEnv, obj);
var serviceObject = BaseGenerator.Create<TService>();
service(serviceObject);
Services.Add(_currentEnv, serviceObject);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Title>ServiceCollector.Fake.Configuration</Title>
<Authors>Ershad Raoufi</Authors>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>service-collector fake configuration service serviceCollection Collection ServiceCollector</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<None Update="icon.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<PropertyGroup>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
</Project>
Binary file not shown.
Loading

0 comments on commit 31611af

Please sign in to comment.