Ejemplo n.º 1
0
        public void ShouldReturnProductsCountAndTotalPriceInCartInfo()
        {
            // Arrange
            using (new SiteContextSwitcher(new TSiteContext("webshop")))
            {
                var cartLines = new ReadOnlyCollectionAdapter <CartLine>
                {
                    new CartLine {
                        Product = new CartProduct {
                            ProductId = "T-800", Price = new Price(10.20m, "USD")
                        }, Quantity = 1
                    },
                    new CartLine {
                        Product = new CartProduct {
                            ProductId = "T-850", Price = new Price(5.15m, "USD")
                        }, Quantity = 2
                    },
                };

                this.cart.Lines = cartLines;

                // Act
                var result = this.controller.GetInfo();

                // Assert
                result.Should().Be("3 item(s) in your cart.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of <see cref="ConstructorDocumentation"/>
        /// </summary>
        /// <param name="typeDocumentation">The documentation model for the type that defines the constructor.</param>
        /// <param name="definitions">The definitions of the type's constructor</param>
        /// <param name="xmlDocsProvider">The XML documentation provider to use for loading XML documentation comments.</param>
        /// <exception cref="ArgumentNullException">Thrown when one of the constructor arguments is null.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="definitions"/> contains definitions with different method names.</exception>
        internal ConstructorDocumentation(TypeDocumentation typeDocumentation, IEnumerable <MethodDefinition> definitions, IXmlDocsProvider xmlDocsProvider) : base(typeDocumentation)
        {
            if (definitions == null)
            {
                throw new ArgumentNullException(nameof(definitions));
            }

            if (xmlDocsProvider == null)
            {
                throw new ArgumentNullException(nameof(xmlDocsProvider));
            }

            if (definitions.Select(x => x.Name).Distinct().Count() > 1)
            {
                throw new ArgumentException("All definitions have to be overloads of the same method", nameof(definitions));
            }

            m_Overloads = definitions
                          .Select(d => new ConstructorOverloadDocumentation(this, d, xmlDocsProvider))
                          .ToDictionary(d => d.MemberId);

            Overloads = ReadOnlyCollectionAdapter.Create(m_Overloads.Values);

            m_Name = definitions.First().Name;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of <see cref="OperatorDocumentation"/>.
        /// </summary>
        /// <param name="typeDocumentation">The documentation model of the type defining the operator overload.</param>
        /// <param name="definitions">The underlying Mono.Cecul definitions of the operator overload.</param>
        /// <param name="xmlDocsProvider">The XML documentation provider to use for loading XML documentation comments.</param>
        internal OperatorDocumentation(TypeDocumentation typeDocumentation, IEnumerable <MethodDefinition> definitions, IXmlDocsProvider xmlDocsProvider)
            : base(typeDocumentation)
        {
            if (definitions == null)
            {
                throw new ArgumentNullException(nameof(definitions));
            }

            if (definitions.Select(x => x.Name).Distinct().Count() > 1)
            {
                throw new ArgumentException("All definitions have to be overloads of the same method", nameof(definitions));
            }

            m_Overloads = definitions
                          .Select(d => new OperatorOverloadDocumentation(this, d, xmlDocsProvider))
                          .ToDictionary(x => x.MemberId);

            Overloads = ReadOnlyCollectionAdapter.Create(m_Overloads.Values);

            var operatorKinds = Overloads.Select(x => x.OperatorKind).Distinct().ToArray();

            Kind = operatorKinds.Length == 1
                ? operatorKinds[0]
                : throw new ArgumentException("Cannot combine overloads of different operators");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of <see cref="AssemblyDocumentation"/>.
        /// </summary>
        /// <param name="assemblySet">The set of all assemblies documentation is being generated for.</param>
        /// <param name="definition">The definition of the assembly.</param>
        /// <param name="xmlDocsProvider">The XML documentation provider to use for loading XML documentation comments.</param>
        /// <param name="logger">The logger to use.</param>
        internal AssemblyDocumentation(AssemblySetDocumentation assemblySet, AssemblyDefinition definition)
        {
            AssemblySet = assemblySet ?? throw new ArgumentNullException(nameof(assemblySet));
            Definition  = definition ?? throw new ArgumentNullException(nameof(definition));

            Name    = definition.Name.Name;
            Version = definition.GetInformationalVersionOrVersion();

            m_Types = new Dictionary <TypeId, TypeDocumentation>();
            Types   = ReadOnlyCollectionAdapter.Create(m_Types.Values);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of <see cref="NamespaceDocumentation"/>.
        /// </summary>
        /// <param name="assemblySet">The the set of assemblies documentation is being generated for.</param>
        /// <param name="parentNamespaceDocumentation">The documentation model of the namespace that contains this namespace.</param>
        /// <param name="namespaceId">The id of the namespace.</param>
        /// <param name="logger">The logger to use.</param>
        internal NamespaceDocumentation(AssemblySetDocumentation assemblySet, NamespaceDocumentation?parentNamespaceDocumentation, NamespaceId namespaceId, ILogger logger)
        {
            m_AssemblySet = assemblySet ?? throw new ArgumentNullException(nameof(assemblySet));
            ParentNamespaceDocumentation = parentNamespaceDocumentation;
            NamespaceId = namespaceId ?? throw new ArgumentNullException(nameof(namespaceId));
            m_Logger    = logger ?? throw new ArgumentNullException(nameof(logger));

            m_Logger.LogDebug($"Initializing documentation object for namespace '{namespaceId.Name}'");

            Types      = ReadOnlyCollectionAdapter.Create(m_Types.Values);
            Namespaces = ReadOnlyCollectionAdapter.Create(m_Namespaces.Values);
            //TODO: Support XML docs for namespaces
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of <see cref="AssemblySetDocumentation"/>
        /// </summary>
        private AssemblySetDocumentation(IReadOnlyList <AssemblyDefinition> assemblyDefinitions, IXmlDocsProvider xmlDocsProvider, ILogger logger)
        {
            if (assemblyDefinitions is null)
            {
                throw new ArgumentNullException(nameof(assemblyDefinitions));
            }

            m_XmlDocsProvider = xmlDocsProvider ?? throw new ArgumentNullException(nameof(xmlDocsProvider));
            m_Logger          = logger ?? throw new ArgumentNullException(nameof(logger));

            m_Assemblies = new Dictionary <string, AssemblyDocumentation>(StringComparer.OrdinalIgnoreCase);
            m_Namespaces = new Dictionary <NamespaceId, NamespaceDocumentation>();
            m_Types      = new Dictionary <TypeId, TypeDocumentation>();

            Assemblies = ReadOnlyCollectionAdapter.Create(m_Assemblies.Values);
            Namespaces = ReadOnlyCollectionAdapter.Create(m_Namespaces.Values);
            Types      = ReadOnlyCollectionAdapter.Create(m_Types.Values);

            LoadAssemblies(assemblyDefinitions);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of <see cref="SingleVersionChangeLog"/>
 /// </summary>
 public SingleVersionChangeLog(VersionInfo version)
 {
     Version    = version ?? throw new ArgumentNullException(nameof(version));
     AllCommits = ReadOnlyCollectionAdapter.Create(m_AllCommits.Values);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of <see cref="TypeDocumentation"/>.
        /// </summary>
        /// <param name="assemblyDocumentation">The documentation model of the assembly that defines the type.</param>
        /// <param name="namespaceDocumentation">The documentation model of the type's namespace.</param>
        /// <param name="definition">The type's underlying Mono.Cecil definition.</param>
        /// <param name="xmlDocsProvider">The XML documentation provider to use for loading XML documentation comments.</param>
        /// <param name="logger">The logger to use.</param>
        internal TypeDocumentation(AssemblyDocumentation assemblyDocumentation,
                                   NamespaceDocumentation namespaceDocumentation,
                                   TypeDefinition definition,
                                   IXmlDocsProvider xmlDocsProvider,
                                   ILogger logger,
                                   TypeDocumentation?declaringType)
        {
            TypeId        = definition.ToTypeId();
            DeclaringType = declaringType;

            AssemblyDocumentation  = assemblyDocumentation ?? throw new ArgumentNullException(nameof(assemblyDocumentation));
            NamespaceDocumentation = namespaceDocumentation ?? throw new ArgumentNullException(nameof(namespaceDocumentation));
            Definition             = definition ?? throw new ArgumentNullException(nameof(definition));
            m_XmlDocsProvider      = xmlDocsProvider ?? throw new ArgumentNullException(nameof(xmlDocsProvider));
            m_Logger = logger ?? throw new ArgumentNullException(nameof(logger));

            m_Logger.LogDebug($"Loading documentation for type '{definition.FullName}'");

            Kind = definition.Kind();

            m_Logger.LogDebug("Loading fields");
            m_Fields = definition.Fields
                       .Where(field => field.IsPublic && !field.Attributes.HasFlag(FieldAttributes.SpecialName))
                       .Select(field => new FieldDocumentation(this, field, xmlDocsProvider))
                       .ToDictionary(f => f.MemberId);

            Fields = ReadOnlyCollectionAdapter.Create(m_Fields.Values);

            m_Logger.LogDebug("Loading events");
            m_Events = definition.Events
                       .Where(ev => (ev.AddMethod?.IsPublic == true || ev.RemoveMethod?.IsPublic == true))
                       .Select(e => new EventDocumentation(this, e, xmlDocsProvider))
                       .ToDictionary(e => e.MemberId);

            Events = ReadOnlyCollectionAdapter.Create(m_Events.Values);

            m_Logger.LogDebug("Loading properties");
            m_Properties = definition.Properties
                           .Where(property => (property.GetMethod?.IsPublic == true || property.SetMethod?.IsPublic == true) && !property.HasParameters)
                           .Select(p => new PropertyDocumentation(this, p, xmlDocsProvider))
                           .ToDictionary(p => p.MemberId);

            Properties = ReadOnlyCollectionAdapter.Create(m_Properties.Values);

            m_Logger.LogDebug("Loading indexers");
            m_Indexers = definition.Properties
                         .Where(property => (property.GetMethod?.IsPublic == true || property.SetMethod?.IsPublic == true) && property.HasParameters)
                         .GroupBy(p => p.Name)
                         .Select(group => new IndexerDocumentation(this, group, xmlDocsProvider))
                         .ToDictionary(indexer => indexer.Name);

            Indexers = ReadOnlyCollectionAdapter.Create(m_Indexers.Values);

            m_Logger.LogDebug("Loading constructors");
            var ctors = definition.GetPublicConstrutors();

            if (ctors.Any())
            {
                Constructors = new ConstructorDocumentation(this, ctors, xmlDocsProvider);
            }

            m_Logger.LogDebug("Loading methods");
            m_Methods = definition.GetPublicMethods()
                        .Where(m => !m.IsOperator())
                        .GroupBy(x => x.Name)
                        .Select(group => new MethodDocumentation(this, group, xmlDocsProvider))
                        .ToDictionary(m => m.Name);

            Methods = ReadOnlyCollectionAdapter.Create(m_Methods.Values);

            m_Logger.LogDebug("Loading operator overloads");
            m_Operators = definition.GetPublicMethods()
                          .GroupBy(x => x.GetOperatorKind())
                          .Where(group => group.Key.HasValue)
                          .Select(group => new OperatorDocumentation(this, group, xmlDocsProvider))
                          .ToDictionary(x => x.Kind);


            Operators = ReadOnlyCollectionAdapter.Create(m_Operators.Values);

            m_Logger.LogDebug("Loading inheritance hierarchy.");
            InheritanceHierarchy = LoadInheritanceHierarchy();

            m_Logger.LogDebug("Loading custom attributes");
            Attributes = Definition
                         .GetCustomAttributes()
                         .Select(x => x.AttributeType.ToTypeId())
                         .ToArray();

            m_Logger.LogDebug("Loading implemented interfaces");
            ImplementedInterfaces = LoadImplementedInterfaces();

            TypeParameters = LoadTypeParameters();

            var documentationComments = m_XmlDocsProvider.TryGetDocumentationComments(MemberId);

            Summary = documentationComments?.Summary ?? TextBlock.Empty;
            Remarks = documentationComments?.Remarks ?? TextBlock.Empty;
            SeeAlso = documentationComments?.SeeAlso?.AsReadOnlyList() ?? Array.Empty <SeeAlsoElement>();
            Example = documentationComments?.Example ?? TextBlock.Empty;

            CSharpDefinition = CSharpDefinitionFormatter.GetDefinition(definition);

            IsObsolete      = definition.IsObsolete(out var obsoleteMessage);
            ObsoleteMessage = obsoleteMessage;
        }