<commit_before>import "../../TestHelper";
import {Component, Inject} from "../../../src/index";
import {DIContainer} from "../../../src/di/DIContainer";
import {DIException} from "../../../src/di/error/DIException";


describe('Dependency Injection', () => {

    @Component()
    class AComponent {

        public name() {
            return "name";
        }
    }

    @Component()
    class AClass {

        @Inject()
        public aPropertyComponent: AComponent;

        @Inject(777)
        public num: number;

        constructor(public aParamComponent: AComponent, @Inject("aaa") public str: string) {
        }
    }

    class NoSuchComponent {
    }

    it('should have injected params', () => {
        const aClass = DIContainer.get(AClass);
        aClass.aParamComponent.name().should.be.equal('name');
        aClass.str.should.be.equal('aaa');
    });

    it('should have injected properties', () => {
        const aClass = DIContainer.get(AClass);
        aClass.aParamComponent.name().should.be.equal('name');
        aClass.num.should.be.equal(777);
    });

    it("should throw DIException error when there's no such component", () => {
        (() => DIContainer.get(NoSuchComponent)).should.throw(DIException);
    });

    it("should throw DIException error when there's no such component name", () => {
        (() => DIContainer.get("no-such-component")).should.throw(DIException);
    });
});<commit_msg>add more tests<commit_after>import "../../TestHelper";
import {Component, Inject} from "../../../src/index";
import {DIContainer} from "../../../src/di/DIContainer";
import {DIException} from "../../../src/di/error/DIException";


describe('Dependency Injection', () => {

    @Component()
    class AComponent {

        public name() {
            return "name";
        }
    }

    @Component("a-named-component")
    class ATestNamedComponent {

        public name() {
            return "a named component";
        }
    }

    @Component()
    class AClass {

        @Inject()
        public aPropertyComponent: AComponent;

        @Inject("a-named-component")
        public aTestNamedPropertyComponent: ATestNamedComponent;

        @Inject(777)
        public num: number;

        constructor(public aParamComponent: AComponent, @Inject("aaa") public str: string) {
        }
    }

    class NoSuchComponent {
    }

    it('should have injected params', () => {
        const aClass = DIContainer.get(AClass);
        aClass.aParamComponent.name().should.be.equal('name');
        aClass.str.should.be.equal('aaa');
    });

    it('should have injected properties', () => {
        const aClass = DIContainer.get(AClass);
        aClass.aParamComponent.name().should.be.equal('name');
        aClass.num.should.be.equal(777);
    });

    it('should have injected named component properties', () => {
        const aClass = DIContainer.get(AClass);
        aClass.aTestNamedPropertyComponent.name().should.be.equal('a named component');
    });

    it('should have injected type component properties', () => {
        const aClass = DIContainer.get(AClass);
        aClass.aPropertyComponent.name().should.be.equal('name');
    });

    it("should throw DIException error when there's no such component", () => {
        (() => DIContainer.get(NoSuchComponent)).should.throw(DIException);
    });

    it("should throw DIException error when there's no such component name", () => {
        (() => DIContainer.get("no-such-component")).should.throw(DIException);
    });
});
{'fraction_non_alphanumeric': 0.16275120294367393, 'fraction_numerical': 0.003396546844041891, 'mean_word_length': 2.602446483180428, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3741387', 'n_tokens_mistral': 1022, 'n_tokens_neox': 1007, 'n_words': 203}