Inheritance: ICassetteApplicationContainer
 public void WhenCreateContainer_ThenApplicationPropertyReturnsApplicationCreatedByFactoryMethod()
 {
     using (var container = new CassetteApplicationContainer(StubApplicationFactory, rootPath))
     {
         container.Application.ShouldBeSameAs(applicationInstances[0].Object);
     }
 }
Example #2
0
 public void WhenCreateContainer_ThenApplicationPropertyReturnsApplicationCreatedByFactoryMethod()
 {
     using (var container = new CassetteApplicationContainer(StubApplicationFactory, rootPath))
     {
         container.Application.ShouldBeSameAs(applicationInstances[0].Object);
     }
 }
        public void GivenFirstCreateCallsThrowsException_WhenFileSystemUpdated_ThenCreateIsCalledNextTimeApplicationRequested()
        {
            Func<ICassetteApplication> create;
            var exception = new Exception();
            var createCalledSecondTime = false;
            var successfulCreate = new Func<ICassetteApplication>(() =>
            {
                createCalledSecondTime = true;
                return Mock.Of<ICassetteApplication>();
            });
            var failingCreate = new Func<ICassetteApplication>(() =>
            {
                create = successfulCreate;
                throw exception;
            });
            create = failingCreate;

            var container = new CassetteApplicationContainer<ICassetteApplication>(() => create());
            container.CreateNewApplicationWhenFileSystemChanges(rootPath);
            var actualException = Assert.Throws<Exception>(delegate
            {
                var app1 = container.Application;
            });
            actualException.ShouldBeSameAs(exception);

            // Touch the file system.
            File.WriteAllText(Path.Combine(rootPath, "test.txt"), "");
            Thread.Sleep(500);

            var app2 = container.Application;
            createCalledSecondTime.ShouldBeTrue();
        }
Example #4
0
        public void GivenFirstCreateCallsThrowsException_WhenFileSystemUpdated_ThenCreateIsCalledNextTimeApplicationRequested()
        {
            Func <ICassetteApplication> create;
            var exception = new Exception();
            var createCalledSecondTime = false;
            var successfulCreate       = new Func <ICassetteApplication>(() =>
            {
                createCalledSecondTime = true;
                return(Mock.Of <ICassetteApplication>());
            });
            var failingCreate = new Func <ICassetteApplication>(() =>
            {
                create = successfulCreate;
                throw exception;
            });

            create = failingCreate;

            var container       = new CassetteApplicationContainer(() => create(), rootPath);
            var actualException = Assert.Throws <Exception>(delegate
            {
                var app1 = container.Application;
            });

            actualException.ShouldBeSameAs(exception);

            // Touch the file system.
            File.WriteAllText(Path.Combine(rootPath, "test.txt"), "");
            Thread.Sleep(500);

            var app2 = container.Application;

            createCalledSecondTime.ShouldBeTrue();
        }
Example #5
0
 public void WhenDispose_ThenCurrentApplicationInstanceDisposed()
 {
     using (var container = new CassetteApplicationContainer(StubApplicationFactory, rootPath))
     {
         var first = container.Application;
     }
     applicationInstances[0].Verify(a => a.Dispose());
 }
Example #6
0
 public void WhenFileCreated_ApplicationPropertyReturnsSecondApplication()
 {
     using (var container = new CassetteApplicationContainer(StubApplicationFactory, rootPath))
     {
         var first = container.Application;
         File.WriteAllText(Path.Combine(rootPath, "test.txt"), "");
         Thread.Sleep(500); // File system events are asynchronously fired on different thread. Hack a brief pause to catch the event!
         container.Application.ShouldBeSameAs(applicationInstances[1].Object);
     }
 }
Example #7
0
        CassetteApplicationContainer <T> CreateContainerFromConfiguration()
        {
            var container = new CassetteApplicationContainer <T>(CreateApplication);

            if (ShouldWatchFileSystem)
            {
                container.CreateNewApplicationWhenFileSystemChanges(PhysicalApplicationDirectory);
            }
            return(container);
        }
 public void WhenFileCreated_ApplicationPropertyReturnsSecondApplication()
 {
     using (var container = new CassetteApplicationContainer <ICassetteApplication>(StubApplicationFactory))
     {
         container.CreateNewApplicationWhenFileSystemChanges(rootPath);
         var first = container.Application;
         File.WriteAllText(Path.Combine(rootPath, "test.txt"), "");
         PauseForFileSystemEvent();
         container.Application.ShouldBeSameAs(applicationInstances[1].Object);
     }
 }
Example #9
0
 public void WhenFileCreated_TheApplicationFactoryCalledAgain()
 {
     using (var container = new CassetteApplicationContainer(StubApplicationFactory, rootPath))
     {
         var first = container.Application;
         File.WriteAllText(Path.Combine(rootPath, "test.txt"), "");
         Thread.Sleep(500); // File system events are asynchronously fired on different thread. Hack a brief pause to catch the event!
         var getItAgain = container.Application;
     }
     factoryCallCount.ShouldEqual(2);
 }
 public void WhenFileCreated_TheApplicationFactoryCalledAgain()
 {
     using (var container = new CassetteApplicationContainer <ICassetteApplication>(StubApplicationFactory))
     {
         container.CreateNewApplicationWhenFileSystemChanges(rootPath);
         var first = container.Application;
         File.WriteAllText(Path.Combine(rootPath, "test.txt"), "");
         PauseForFileSystemEvent();
         var getItAgain = container.Application;
     }
     factoryCallCount.ShouldEqual(2);
 }
        public void WhenCreatingANewApplication_ThenOldApplicationIsDisposed()
        {
            var filename = Path.Combine(rootPath, "test.txt");

            using (var container = new CassetteApplicationContainer <ICassetteApplication>(StubApplicationFactory))
            {
                container.CreateNewApplicationWhenFileSystemChanges(rootPath);
                var first = container.Application;
                File.WriteAllText(filename, "");
                PauseForFileSystemEvent();
                var getItAgain = container.Application;
            }
            applicationInstances[0].Verify(a => a.Dispose());
        }
Example #12
0
        public void WhenCreatingANewApplication_ThenOldApplicationIsDisposed()
        {
            var filename = Path.Combine(rootPath, "test.txt");

            using (var container = new CassetteApplicationContainer(StubApplicationFactory, rootPath))
            {
                var first = container.Application;
                File.WriteAllText(filename, "");
                Thread.Sleep(500);
                // File system events are asynchronously fired on different thread. Hack a brief pause to catch the event!
                var getItAgain = container.Application;
            }
            applicationInstances[0].Verify(a => a.Dispose());
        }
        public void GivenIgnoreFileSystemChange_WhenFileChanges_ThenApplicationIsNotRecycled()
        {
            var filename = Path.Combine(rootPath, "ignored.txt");
            using (var container = new CassetteApplicationContainer<ICassetteApplication>(StubApplicationFactory))
            {
                container.IgnoreFileSystemChange(new Regex("ignored"));

                File.WriteAllText(filename, "");
                var getIt = container.Application;
                PauseForFileSystemEvent();
                var getItAgain = container.Application;

                factoryCallCount.ShouldEqual(1);
            }
        }
        public void GivenIgnoreFileSystemChange_WhenFileChanges_ThenApplicationIsNotRecycled()
        {
            var filename = Path.Combine(rootPath, "ignored.txt");

            using (var container = new CassetteApplicationContainer <ICassetteApplication>(StubApplicationFactory))
            {
                container.IgnoreFileSystemChange(new Regex("ignored"));

                File.WriteAllText(filename, "");
                var getIt = container.Application;
                PauseForFileSystemEvent();
                var getItAgain = container.Application;

                factoryCallCount.ShouldEqual(1);
            }
        }
 public void WhenFileRenamed_TheApplicationFactoryCalledAgain()
 {
     var filename = Path.Combine(rootPath, "test.txt");
     File.WriteAllText(filename, "");
     using (var container = new CassetteApplicationContainer<ICassetteApplication>(StubApplicationFactory))
     {
         container.CreateNewApplicationWhenFileSystemChanges(rootPath);
         var first = container.Application;
         File.Move(filename, filename + ".new");
         PauseForFileSystemEvent();
         var getItAgain = container.Application;
     }
     factoryCallCount.ShouldEqual(2);
 }
 public void WhenFileCreated_ApplicationPropertyReturnsSecondApplication()
 {
     using (var container = new CassetteApplicationContainer<ICassetteApplication>(StubApplicationFactory))
     {
         container.CreateNewApplicationWhenFileSystemChanges(rootPath);
         var first = container.Application;
         File.WriteAllText(Path.Combine(rootPath, "test.txt"), "");
         PauseForFileSystemEvent();
         container.Application.ShouldBeSameAs(applicationInstances[1].Object);
     }
 }
 public void WhenDispose_ThenCurrentApplicationInstanceDisposed()
 {
     using (var container = new CassetteApplicationContainer<ICassetteApplication>(StubApplicationFactory))
     {
         var first = container.Application;
     }
     applicationInstances[0].Verify(a => a.Dispose());
 }
 public void WhenCreatingANewApplication_ThenOldApplicationIsDisposed()
 {
     var filename = Path.Combine(rootPath, "test.txt");
     using (var container = new CassetteApplicationContainer<ICassetteApplication>(StubApplicationFactory))
     {
         container.CreateNewApplicationWhenFileSystemChanges(rootPath);
         var first = container.Application;
         File.WriteAllText(filename, "");
         PauseForFileSystemEvent();
         var getItAgain = container.Application;
     }
     applicationInstances[0].Verify(a => a.Dispose());
 }
 public void WhenFileRenamed_TheApplicationFactoryCalledAgain()
 {
     var filename = Path.Combine(rootPath, "test.txt");
     File.WriteAllText(filename, "");
     using (var container = new CassetteApplicationContainer<ICassetteApplication>(StubApplicationFactory, rootPath))
     {
         var first = container.Application;
         File.Move(filename, filename + ".new");
         Thread.Sleep(500); // File system events are asynchronously fired on different thread. Hack a brief pause to catch the event!
         var getItAgain = container.Application;
     }
     factoryCallCount.ShouldEqual(2);
 }
 public void WhenFileCreated_ApplicationPropertyReturnsSecondApplication()
 {
     using (var container = new CassetteApplicationContainer<ICassetteApplication>(StubApplicationFactory, rootPath))
     {
         var first = container.Application;
         File.WriteAllText(Path.Combine(rootPath, "test.txt"), "");
         Thread.Sleep(500); // File system events are asynchronously fired on different thread. Hack a brief pause to catch the event!
         container.Application.ShouldBeSameAs(applicationInstances[1].Object);
     }
 }
 public void WhenCreatingANewApplication_ThenOldApplicationIsDisposed()
 {
     var filename = Path.Combine(rootPath, "test.txt");
     using (var container = new CassetteApplicationContainer<ICassetteApplication>(StubApplicationFactory, rootPath))
     {
         var first = container.Application;
         File.WriteAllText(filename, "");
         Thread.Sleep(500);
             // File system events are asynchronously fired on different thread. Hack a brief pause to catch the event!
         var getItAgain = container.Application;
     }
     applicationInstances[0].Verify(a => a.Dispose());
 }