Пример #1
0
    public void Can_Register_Command_Settings_When_Configuring_Application()
    {
        // Given
        var registrar = new FakeTypeRegistrar();

        registrar.Register(typeof(DogSettings), typeof(DogSettings));
        registrar.Register(typeof(MammalSettings), typeof(MammalSettings));
        var app = new CommandApp(registrar);

        app.Configure(config =>
        {
            config.PropagateExceptions();
            config.AddBranch <AnimalSettings>("animal", animal =>
            {
                animal.AddCommand <DogCommand>("dog");
                animal.AddCommand <HorseCommand>("horse");
            });
        });

        // When
        app.Run(new[]
        {
            "animal", "4", "dog", "12",
        });

        // Then
        registrar.Registrations.ContainsKey(typeof(DogSettings)).ShouldBeTrue();
        registrar.Registrations[typeof(DogSettings)].Count.ShouldBe(1);
        registrar.Registrations[typeof(DogSettings)].ShouldContain(typeof(DogSettings));
        registrar.Registrations.ContainsKey(typeof(MammalSettings)).ShouldBeTrue();
        registrar.Registrations[typeof(MammalSettings)].Count.ShouldBe(1);
        registrar.Registrations[typeof(MammalSettings)].ShouldContain(typeof(MammalSettings));
    }
Пример #2
0
    public void Can_Register_Default_Command_Settings_When_Configuring_Application()
    {
        // Given
        var registrar = new FakeTypeRegistrar();

        registrar.Register(typeof(DogSettings), typeof(DogSettings));
        var app = new CommandApp <DogCommand>(registrar);

        app.Configure(config =>
        {
            config.PropagateExceptions();
        });

        // When
        app.Run(new[]
        {
            "12", "4",
        });

        // Then
        registrar.Registrations.ContainsKey(typeof(DogSettings)).ShouldBeTrue();
        registrar.Registrations[typeof(DogSettings)].Count.ShouldBe(1);
        registrar.Registrations[typeof(DogSettings)].ShouldContain(typeof(DogSettings));
    }