Skip to content

ServiceCollector.Fake.Configuration

Ershad Raoufi- ارشاد رئوفی edited this page Jun 8, 2024 · 7 revisions

BaseGeneratorClass:

The BaseGenerator class provides a mechanism to create instances of objects with fake data using the AutoFixture library customized with AutoNSubstitute.

FakeConfiguration Class:

The FakeConfiguration class is used to configure a fake service instance. This class is designed to help set up and customize the behavior of a fake service for testing and development purposes.

namespace ServiceCollector.Fake.Configuration
{
    public class FakeConfiguration where TService : class
    {
        public TService Service { get; }

        public FakeConfiguration(TService service)
        {
            Service = service;
        }
    }
}

Description:

The Service property holds the instance of the fake service being configured. This property allows access to the fake service so that its behavior can be customized as needed.

Type TService: The type of the service being faked.

FakeConfigurationWithMultiEnvironment Class :

The FakeConfigurationWithMultiEnvironment class allows the configuration of fake services for multiple environments.

This class provides a mechanism to set up different fake implementations of a service based on the target environment, facilitating testing and development across various stages (e.g., Development, Staging, Production).

namespace ServiceCollector.Fake.Configuration
{
    public class FakeConfigurationWithMultiEnvironment
        where TService : class
    {
        private readonly string _currentEnv;
        public IDictionary Services { get; private set; }

        public FakeConfigurationWithMultiEnvironment(string currentEnv)
        {
            _currentEnv = currentEnv;
            Services = new Dictionary();
        }

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

        public void Add(Action service)
        {
            var serviceObject = BaseGenerator.Create();
            service(serviceObject);
            Services.Add(_currentEnv, serviceObject);
        }
    }
}
Clone this wiki locally