public void DisposeTest()
        {
            SingletonPerScopeLifestyle container = new SingletonPerScopeLifestyle();
            FauxInjectionScope fauxInjectionScope = new FauxInjectionScope();

            bool eventFired = false;

            object locatedObject =
                container.Locate((scope, context) =>
                                 {
                                     DisposableService disposableService = new DisposableService();

                                     scope.AddDisposable(disposableService);

                                     disposableService.Disposing += (sender, args) => eventFired = true;

                                     return disposableService;
                                 },
                    fauxInjectionScope,
                    new FauxInjectionContext { RequestingScope = fauxInjectionScope },
                    new FauxExportStrategy(() => new object()));

            Assert.NotNull(locatedObject);

            container.Dispose();

            Assert.False(eventFired);

            fauxInjectionScope.Dispose();

            Assert.True(eventFired);
        }
Beispiel #2
0
        public void BasicDisposalTest()
        {
            DisposalScope disposalScope = new DisposalScope();
            DisposableService disposableService = new DisposableService();
            bool eventFired = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            disposalScope.AddDisposable(disposableService);

            disposalScope.Dispose();

            Assert.True(eventFired);
        }
Beispiel #3
0
        public void CleanUpDelegateTest()
        {
            DisposalScope disposalScope = new DisposalScope();
            DisposableService disposableService = new DisposableService();
            bool eventFired = false;
            bool cleanUpCalled = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            disposalScope.AddDisposable(disposableService,
                disposed =>
                {
                    Assert.True(ReferenceEquals(disposableService, disposed));

                    cleanUpCalled = true;
                });

            disposalScope.Dispose();

            Assert.True(eventFired);
            Assert.True(cleanUpCalled);
        }
Beispiel #4
0
        public void ThrowExceptionDuringCleanUp()
        {
            DisposalScope disposalScope = new DisposalScope();
            DisposableService disposableService = new DisposableService();
            bool eventFired = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            disposalScope.AddDisposable(disposableService, disposed => { throw new Exception(); });

            disposalScope.Dispose();

            Assert.True(eventFired);
        }
Beispiel #5
0
        public void SimpleDisposableTest()
        {
            Owned<IDisposableService> owned = new Owned<IDisposableService>();
            DisposableService disposableService = new DisposableService();
            bool eventFired = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            owned.SetValue(disposableService);

            Assert.True(ReferenceEquals(owned.Value, disposableService));

            owned.Dispose();

            Assert.True(eventFired);
        }