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();
        }
Beispiel #2
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);
     }
 }
 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());
        }
        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();
        }
 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 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());
 }