Beispiel #1
0
        public void Get_Success_SingletonIgnoresSecond()
        {
            var dependencyService =
                new DependencyBuilder()
                .AddSingleton <IFirst, First.IgnoreSecond>()
                .Build();

            var service = dependencyService.Get <IFirst>();

            Assert.NotNull(service);
            Assert.IsType <First.IgnoreSecond>(service);
        }
Beispiel #2
0
        public void Get_Success_ScopedRequiresSingleton()
        {
            var dependencyService =
                new DependencyBuilder()
                .AddScoped <IFirst, First.RequiresSecond>()
                .AddSingleton <ISecond, Second.RequiresNone>()
                .Build().CreateScope();

            var service = dependencyService.Get <IFirst>();

            Assert.NotNull(service);
            var first = Assert.IsType <First.RequiresSecond>(service);

            Assert.NotNull(first.Second);
            Assert.IsType <Second.RequiresNone>(first.Second);
        }
Beispiel #3
0
        public void Get_Success_ScopedRequiresScopedAutoDetected()
        {
            var dependencyService =
                new DependencyBuilder()
                .EnableServiceAutoDetection(GetType().Assembly)
                .AddScoped <IFirst, First.RequiresUniqueSecond>()
                .Build().CreateScope();

            var service = dependencyService.Get <IFirst>();

            Assert.NotNull(service);
            var first = Assert.IsType <First.RequiresUniqueSecond>(service);

            Assert.NotNull(first.UniqueSecond);
            Assert.IsType <Second.RequiresNone>(first.UniqueSecond);
        }
Beispiel #4
0
        public void Get_Success_SingletonRequiresTransientFunction()
        {
            var dependencyService =
                new DependencyBuilder()
                .AddSingleton <IFirst, First.RequiresSecond>()
                .AddTransient <ISecond>(x => new Second.RequiresNone())
                .Build();

            var service = dependencyService.Get <IFirst>();

            Assert.NotNull(service);
            var first = Assert.IsType <First.RequiresSecond>(service);

            Assert.NotNull(first.Second);
            Assert.IsType <Second.RequiresNone>(first.Second);
        }
Beispiel #5
0
        public void Get_Success_SingletonRequiresSingletonInstance()
        {
            var dependencyService =
                new DependencyBuilder()
                .AddSingleton <IFirst, First.RequiresSecond>()
                .AddSingleton <ISecond>(new Second.RequiresNone())
                .Build();

            var service = dependencyService.Get <IFirst>();

            Assert.NotNull(service);
            var second = Assert.IsType <First.RequiresSecond>(service);

            Assert.NotNull(second.Second);
            Assert.IsType <Second.RequiresNone>(second.Second);
        }
Beispiel #6
0
        public void Dispose_Success_DisposableScoped_SuppressesExceptions()
        {
            var dependencyService =
                new DependencyBuilder()
                .EnableServiceAutoDetection(GetType().Assembly)
                .AddScoped <IFirst, First.RequiresNone>()
                .Build().CreateScope();

            var service = dependencyService.Get <IFirst>();

            Assert.NotNull(service);
            var first = Assert.IsType <First.RequiresNone>(service);

            first.Dispose();

            dependencyService.Dispose();
        }
Beispiel #7
0
        public void Dispose_Success_DisposableSingleton()
        {
            var dependencyService =
                new DependencyBuilder()
                .EnableServiceAutoDetection(GetType().Assembly)
                .AddSingleton <IFirst, First.RequiresNone>()
                .Build();

            var service = dependencyService.Get <IFirst>();

            Assert.NotNull(service);
            var first = Assert.IsType <First.RequiresNone>(service);

            dependencyService.Dispose();

            Assert.True(first.IsDisposed);
        }
Beispiel #8
0
        public void Get_Success_TransientRequiresSingleton()
        {
            var dependencyService =
                new DependencyBuilder()
                .EnableServiceAutoDetection(GetType().Assembly)
                .AddTransient <IFirst, First.RequiresSecond>()
                .AddSingleton <ISecond, Second.RequiresNone>()
                .Build();

            var service = dependencyService.Get <IFirst>();

            Assert.NotNull(service);
            var first = Assert.IsType <First.RequiresSecond>(service);

            Assert.NotNull(first.Second);
            Assert.IsType <Second.RequiresNone>(first.Second);
        }
Beispiel #9
0
        public void Get_Success_ScopedRequiresSameTransientAsScoped()
        {
            var dependencyService =
                new DependencyBuilder()
                .EnableServiceAutoDetection(GetType().Assembly)
                .AddScoped <IFirst, First.RequiresSecondAndThird>()
                .AddScoped <ISecond, Second.RequiresThird>()
                .AddTransient <IThird, Third.RequiresNone>()
                .Build().CreateScope();

            var service = dependencyService.Get <IFirst>();

            Assert.NotNull(service);
            var first = Assert.IsType <First.RequiresSecondAndThird>(service);

            Assert.NotNull(first.Second);
            var second = Assert.IsType <Second.RequiresThird>(first.Second);

            Assert.NotNull(first.Third);
            Assert.IsType <Third.RequiresNone>(first.Third);

            Assert.NotSame(first.Third, second.Third);
        }