public void ScanAssembly_scans_assembly_only_if_it_has_not_already_been_scanned()
        {
            var mockChecker = new Mock<ViewAssemblyChecker>();
            var scanner = new ViewAssemblyScanner(new List<Assembly>(), new Dictionary<Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(object).Assembly, followReferences: false);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(object).Assembly), Times.Once());

            scanner.ScanAssembly(typeof(object).Assembly, followReferences: false);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(object).Assembly), Times.Once());
        }
Example #2
0
        public void ScanAssembly_scans_assembly_only_if_it_has_not_already_been_scanned()
        {
            var mockChecker = new Mock <ViewAssemblyChecker>();
            var scanner     = new ViewAssemblyScanner(new List <Assembly>(), new Dictionary <Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(object).Assembly, followReferences: false);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(object).Assembly), Times.Once());

            scanner.ScanAssembly(typeof(object).Assembly, followReferences: false);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(object).Assembly), Times.Once());
        }
        public void ScanAssembly_processes_assembly_again_if_previously_references_were_not_scanned_but_now_they_should_be()
        {
            var mockChecker = new Mock<ViewAssemblyChecker>();
            var scanner = new ViewAssemblyScanner(new List<Assembly>(), new Dictionary<Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: false);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly), Times.Once());
            mockChecker.Verify(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly), Times.Never());

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: true);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly));
            mockChecker.Verify(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly), Times.Once());
        }
Example #4
0
        public void ScanAssembly_does_not_processes_assembly_again_if_references_were_already_scanned()
        {
            var mockChecker = new Mock <ViewAssemblyChecker>();
            var scanner     = new ViewAssemblyScanner(new List <Assembly>(), new Dictionary <Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: true);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly), Times.Once());
            mockChecker.Verify(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly), Times.Once());

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: true);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly), Times.Once());
            mockChecker.Verify(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly), Times.Once());
        }
Example #5
0
        public void ScanAssembly_processes_assembly_again_if_previously_references_were_not_scanned_but_now_they_should_be()
        {
            var mockChecker = new Mock <ViewAssemblyChecker>();
            var scanner     = new ViewAssemblyScanner(new List <Assembly>(), new Dictionary <Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: false);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly), Times.Once());
            mockChecker.Verify(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly), Times.Never());

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: true);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly));
            mockChecker.Verify(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly), Times.Once());
        }
        public void ScanAssembly_can_scan_all_referenced_assemblies()
        {
            var mockChecker = new Mock<ViewAssemblyChecker>();
            var scanner = new ViewAssemblyScanner(new List<Assembly>(), new Dictionary<Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: true);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly), Times.Once());
            mockChecker.Verify(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly), Times.Once());
        }
        public void ScanAssembly_can_scan_only_a_single_assembly()
        {
            var mockChecker = new Mock<ViewAssemblyChecker>();
            var scanner = new ViewAssemblyScanner(new List<Assembly>(), new Dictionary<Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: false);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly), Times.Once());
            mockChecker.Verify(m => m.IsViewAssembly(It.IsAny<Assembly>()), Times.Once());
        }
Example #8
0
        public void ScanAssembly_can_scan_all_referenced_assemblies()
        {
            var mockChecker = new Mock <ViewAssemblyChecker>();
            var scanner     = new ViewAssemblyScanner(new List <Assembly>(), new Dictionary <Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: true);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly), Times.Once());
            mockChecker.Verify(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly), Times.Once());
        }
Example #9
0
        public void ScanAssembly_can_scan_only_a_single_assembly()
        {
            var mockChecker = new Mock <ViewAssemblyChecker>();
            var scanner     = new ViewAssemblyScanner(new List <Assembly>(), new Dictionary <Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: false);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly), Times.Once());
            mockChecker.Verify(m => m.IsViewAssembly(It.IsAny <Assembly>()), Times.Once());
        }
Example #10
0
        public void ScanAssembly_records_which_assemblies_contain_view_generation_attribute()
        {
            var mockChecker = new Mock <ViewAssemblyChecker>();

            mockChecker.Setup(m => m.IsViewAssembly(typeof(DbContext).Assembly)).Returns(false);
            mockChecker.Setup(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly)).Returns(true);
            var scanner = new ViewAssemblyScanner(new List <Assembly>(), new Dictionary <Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: true);

            Assert.True(scanner.ViewAssemblies.Contains(typeof(RequiredAttribute).Assembly));
            Assert.False(scanner.ViewAssemblies.Contains(typeof(DbContext).Assembly));
        }
        public void CheckAssembly(Assembly assembly, bool followReferences)
        {
            DebugCheck.NotNull(assembly);

            if (IsAssemblyVisited(assembly, followReferences))
            {
                return;
            }

            lock (_lock)
            {
                if (IsAssemblyVisited(assembly, followReferences))
                {
                    return;
                }

                var scanner = new ViewAssemblyScanner(_assemblies, _visitedAssemblies, _checker);
                scanner.ScanAssembly(assembly, followReferences);

                _assemblies = scanner.ViewAssemblies;
                _visitedAssemblies = scanner.VisitedAssemblies;
            }
        }
Example #12
0
        public void CheckAssembly(Assembly assembly, bool followReferences)
        {
            DebugCheck.NotNull(assembly);

            if (IsAssemblyVisited(assembly, followReferences))
            {
                return;
            }

            lock (_lock)
            {
                if (IsAssemblyVisited(assembly, followReferences))
                {
                    return;
                }

                var scanner = new ViewAssemblyScanner(_assemblies, _visitedAssemblies, _checker);
                scanner.ScanAssembly(assembly, followReferences);

                _assemblies        = scanner.ViewAssemblies;
                _visitedAssemblies = scanner.VisitedAssemblies;
            }
        }
        public void ScanAssembly_does_not_processes_assembly_again_if_references_were_already_scanned()
        {
            var mockChecker = new Mock<ViewAssemblyChecker>();
            var scanner = new ViewAssemblyScanner(new List<Assembly>(), new Dictionary<Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: true);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly), Times.Once());
            mockChecker.Verify(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly), Times.Once());

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: true);
            mockChecker.Verify(m => m.IsViewAssembly(typeof(DbContext).Assembly), Times.Once());
            mockChecker.Verify(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly), Times.Once());
        }
        public void ScanAssembly_records_which_assemblies_contain_view_generation_attribute()
        {
            var mockChecker = new Mock<ViewAssemblyChecker>();
            mockChecker.Setup(m => m.IsViewAssembly(typeof(DbContext).Assembly)).Returns(false);
            mockChecker.Setup(m => m.IsViewAssembly(typeof(RequiredAttribute).Assembly)).Returns(true);
            var scanner = new ViewAssemblyScanner(new List<Assembly>(), new Dictionary<Assembly, bool>(), mockChecker.Object);

            scanner.ScanAssembly(typeof(DbContext).Assembly, followReferences: true);

            Assert.True(scanner.ViewAssemblies.Contains(typeof(RequiredAttribute).Assembly));
            Assert.False(scanner.ViewAssemblies.Contains(typeof(DbContext).Assembly));
        }