public void Factory_DerivedClass_GetNamed_Success()
    {
        // Arrange
        string testName          = Guid.NewGuid().ToString();
        string testValue         = Guid.NewGuid().ToString();
        var    serviceCollection = new ServiceCollection();

        serviceCollection
        .AddSingleton <DemoClientFactory>()
        .AddSingleton <IFactory <DemoClientConfig, DemoClient>, DemoClientFactory>(svc => svc.GetRequiredService <DemoClientFactory>())
        .ConfigureFactory <DemoClientConfig, DemoClient>((svc, o) => new DemoClient(o))
        .Configure(testName, o => o.Value = testValue);
        IServiceProvider  services = serviceCollection.BuildServiceProvider();
        DemoClientFactory factory1 = services.GetRequiredService <DemoClientFactory>();
        IFactory <DemoClientConfig, DemoClient> factory2 = services.GetRequiredService <IFactory <DemoClientConfig, DemoClient> >();

        // Act
        Result <DemoClient> item1 = factory1.GetItem(testName);
        Result <DemoClient> item2 = factory2.GetItem(testName);

        // Assert
        item1.IsSuccess.Should().BeTrue();
        item1.Value.ConfigValue.Should().Be(testValue);

        item2.IsSuccess.Should().BeTrue();
        item2.Value.ConfigValue.Should().Be(testValue);
    }
Beispiel #2
0
        public MainWindow(DemoClientFactory demoClientFactory)
        {
            if (demoClientFactory is null)
            {
                throw new System.ArgumentNullException(nameof(demoClientFactory));
            }

            InitializeComponent();
            demoClient = demoClientFactory.GetService();
        }