Exemplo n.º 1
0
        public async Task FileSystemHubRegisterTests(bool update)
        {
            // Setup
            var env     = new Mock <IEnvironment>();
            var tracer  = new Mock <ITracer>();
            var context = new HubCallerContext(Mock.Of <IRequest>(), Guid.NewGuid().ToString());
            var groups  = new Mock <IGroupManager>();
            var clients = new Mock <HubConnectionContext>();

            using (
                var fileSystemHubTest = new FileSystemHubTest(env.Object, tracer.Object, context, groups.Object,
                                                              clients.Object))
            {
                // Test
                fileSystemHubTest.TestRegister(@"C:\");

                // Assert
                Assert.Equal(1, FileSystemHubTest.FileWatchersCount);

                if (update)
                {
                    // Test
                    fileSystemHubTest.TestRegister(@"C:\");

                    // Assert
                    Assert.Equal(1, FileSystemHubTest.FileWatchersCount);
                }

                // Test
                await fileSystemHubTest.TestDisconnect();

                // Assert
                Assert.Equal(0, FileSystemHubTest.FileWatchersCount);
            }
        }
Exemplo n.º 2
0
        public async Task FileSystemHubRegisterTests(bool update)
        {
            // Setup
            var env = new Mock<IEnvironment>();
            var tracer = new Mock<ITracer>();
            var context = new HubCallerContext(Mock.Of<IRequest>(), Guid.NewGuid().ToString());
            var groups = new Mock<IGroupManager>();
            var clients = new Mock<HubConnectionContext>();

            using (
                var fileSystemHubTest = new FileSystemHubTest(env.Object, tracer.Object, context, groups.Object,
                    clients.Object))
            {
                // Test
                fileSystemHubTest.TestRegister(@"C:\");

                // Assert
                Assert.Equal(1, FileSystemHubTest.FileWatchersCount);

                if (update)
                {
                    // Test
                    fileSystemHubTest.TestRegister(@"C:\");

                    // Assert
                    Assert.Equal(1, FileSystemHubTest.FileWatchersCount);
                }

                // Test
                await fileSystemHubTest.TestDisconnect();

                // Assert
                Assert.Equal(0, FileSystemHubTest.FileWatchersCount);
            }
        }
Exemplo n.º 3
0
        public void FileSystemHubMaxWatchers()
        {
            var listOfFileSystemHubs = new List <FileSystemHubTest>();

            try
            {
                // Setup
                var env     = new Mock <IEnvironment>();
                var tracer  = new Mock <ITracer>();
                var groups  = new Mock <IGroupManager>();
                var clients = new Mock <HubConnectionContext>();

                // Test
                for (var i = 0; i < 10; i++)
                {
                    var context           = new HubCallerContext(Mock.Of <IRequest>(), Guid.NewGuid().ToString());
                    var fileSystemHubTest = new FileSystemHubTest(env.Object, tracer.Object, context, groups.Object,
                                                                  clients.Object);
                    listOfFileSystemHubs.Add(fileSystemHubTest);
                    fileSystemHubTest.TestRegister(@"C:\");

                    // Assert
                    Assert.Equal(Math.Min(i + 1, FileSystemHub.MaxFileSystemWatchers), FileSystemHubTest.FileWatchersCount);
                }
            }
            finally
            {
                foreach (var fileSystemHub in listOfFileSystemHubs)
                {
                    fileSystemHub.Dispose();
                }
            }
        }
Exemplo n.º 4
0
        public void FileSystemHubMaxWatchers()
        {
            var listOfFileSystemHubs = new List<FileSystemHubTest>();

            try
            {
                // Setup
                var env = new Mock<IEnvironment>();
                var tracer = new Mock<ITracer>();
                var groups = new Mock<IGroupManager>();
                var clients = new Mock<HubConnectionContext>();

                // Test
                for (var i = 0; i < 10; i++)
                {
                    var context = new HubCallerContext(Mock.Of<IRequest>(), Guid.NewGuid().ToString());
                    var fileSystemHubTest = new FileSystemHubTest(env.Object, tracer.Object, context, groups.Object,
                        clients.Object);
                    listOfFileSystemHubs.Add(fileSystemHubTest);
                    fileSystemHubTest.TestRegister(@"C:\");

                    // Assert
                    Assert.Equal(Math.Min(i + 1, FileSystemHub.MaxFileSystemWatchers), FileSystemHubTest.FileWatchersCount);
                }
            }
            finally
            {
                foreach (var fileSystemHub in listOfFileSystemHubs)
                {
                    fileSystemHub.Dispose();
                }
            }
        }