public void each_service_interface_can_be_resolved_from_container()
        {
            var assemblies = ConventionsHelper.assemblies()
                             .ToArray();

            var builder = new ContainerBuilder();

            builder.RegisterAssemblyModules(assemblies);

            var container = builder.Build();

            var service_interfaces = ConventionsHelper.interfaces()
                                     .Where(x => x != typeof(IEntity))
                                     .Where(x => x.Namespace.Contains("._Infrastructure") == false)
                                     .ToList();

            Assert.NotEmpty(service_interfaces);

            foreach (var serviceInterface in service_interfaces)
            {
                var error = Record.Exception(
                    () => container.Resolve(serviceInterface)
                    );

                Assert.Null(error);
            }
        }
        public void each_interface_name_starts_with_capital_I()
        {
            var interfaces = ConventionsHelper.interfaces();

            Assert.NotEmpty(interfaces);

            var interfaces_not_starting_with_I = interfaces
                                                 .Where(x => x.Name.StartsWith("I") == false);

            Assert.Empty(interfaces_not_starting_with_I);
        }
        public void controllers_name_should_end_with_Controller()
        {
            var controllers = ConventionsHelper.classes()
                              .Where(x => x.IsAssignableTo <Controller>())
                              .ToList();

            Assert.NotEmpty(controllers);

            foreach (var controller in controllers)
            {
                Assert.EndsWith("Controller", controller.Name);
            }
        }
        public void each_class_in_DataAccess_namespace_implements_interface()
        {
            var data_access_classes = ConventionsHelper.classes()
                                      .Where(x => x.Namespace.Contains(".DataAccess"))
                                      .ToList()
            ;

            Assert.NotEmpty(data_access_classes);

            var data_access_without_interfaces = data_access_classes
                                                 .Where(x => x.GetInterfaces().Length == 0)
            ;

            Assert.Empty(data_access_without_interfaces);
        }
Ejemplo n.º 5
0
        public void scripts_do_not_contain_GO_statement()
        {
            var dbDirectory = ConventionsHelper.db_directory();

            var sql_scripts = Directory.EnumerateFiles(dbDirectory, "*sql")
                              .ToList();

            Assert.NotEmpty(sql_scripts);

            var scripts_with_GO = sql_scripts
                                  .Select(x => File.ReadAllText(x))
                                  .Where(x => Regex.IsMatch(x, "^\\s*GO\\s*$", RegexOptions.IgnoreCase | RegexOptions.Multiline))
            ;

            Assert.Empty(scripts_with_GO);
        }
Ejemplo n.º 6
0
        public void each_property_of_IEntity_is_virtual()
        {
            var entities = ConventionsHelper.types()
                           .Where(x => x.IsAssignableTo <IEntity>())
            ;

            var entity_properties = entities.SelectMany(x => x.GetProperties())
                                    .ToList();

            Assert.NotEmpty(entity_properties);

            var non_virtual_getters = entity_properties
                                      .Select(x => x.GetGetMethod())
                                      .Where(x => x.IsVirtual == false)
            ;

            Assert.Empty(non_virtual_getters);
        }
Ejemplo n.º 7
0
        public void each_interface_has_at_least_one_implementation()
        {
            var interfaces = ConventionsHelper.interfaces()
                             .Where(x => x.Namespace.Contains("._Infrastructure") == false)
                             .ToList();

            var concrete_types = ConventionsHelper.classes()
                                 .Where(x => x.IsConcrete())
                                 .ToList();

            foreach (var @interface in interfaces)
            {
                var types_assignable_to_interface = concrete_types
                                                    .Where(x => @interface.IsAssignableFrom(x));

                Assert.NotEmpty(types_assignable_to_interface);
            }
        }
        public void cshtml_files_should_be_marked_as_Content()
        {
            var projectFiles = ConventionsHelper.project_files()
                               .ToList();

            Assert.NotEmpty(projectFiles);

            foreach (var csproj in projectFiles)
            {
                var sqls = from d in XDocument.Load(csproj).Descendants()
                           let include = d.Attribute("Include")
                                         where include != null
                                         where include.Value.EndsWith(".cshtml")
                                         select d;

                var sqls_as_non_EmbeddedResource = sqls
                                                   .Where(x => x.Name.LocalName != "Content");

                Assert.Empty(sqls_as_non_EmbeddedResource);
            }
        }
Ejemplo n.º 9
0
        public void each_command_has_exactly_one_handler()
        {
            var commands = ConventionsHelper.classes()
                           .Where(x => x.IsAssignableTo <ICommand>())
                           .ToList();

            var handlers = ConventionsHelper.classes()
                           .Where(x => x.IsAssignableTo <IHandleCommand>())
                           .ToList();

            Assert.NotEmpty(commands);

            foreach (var command in commands)
            {
                var handler_type = typeof(IHandleCommand <>).MakeGenericType(command);

                var command_handlers = handlers.Where(x => x.GetInterfaces().Contains(handler_type));

                Assert.Equal(1, command_handlers.Count());
            }
        }
Ejemplo n.º 10
0
        public void DateTime_Now_is_never_used__should_use_UtcNow_instead()
        {
            var sourcePaths = ConventionsHelper.GetSourceFiles()
                              .ToArray();

            foreach (var sourcePath in sourcePaths)
            {
                var source = File.ReadAllText(sourcePath);

                var tree = CSharpSyntaxTree.ParseText(source);

                var root           = tree.GetRoot();
                var memberAccesses = root.DescendantNodes()
                                     .OfType <MemberAccessExpressionSyntax>()
                                     .ToList();

                var datetime_now_invocations = memberAccesses
                                               .Where(x => x.Expression.Parent.ToString()
                                                      .Equals("datetime.now", StringComparison.OrdinalIgnoreCase)
                                                      ).ToArray();

                Assert.Empty(datetime_now_invocations);
            }
        }