< Summary

Information
Class: OzonDomains.TransactionTypeExtensions
Assembly: OzonDomains
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonDomains/TransactionTypeExtensions.cs
Line coverage
100%
Covered lines: 91
Uncovered lines: 0
Coverable lines: 91
Total lines: 171
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetTransactionTypes()100%11100%
GetTransactionDisplayName(...)100%11100%
IsValidTransactionType(...)100%11100%
GetTransactionTypeByControllerName(...)100%44100%
GetCreateMethodName(...)100%22100%
GetTransactionTypeIcon(...)100%22100%
GetTransactionTypeCssClass(...)100%22100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonDomains/TransactionTypeExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Reflection;
 5using OzonDomains.Models;
 6
 7namespace OzonDomains
 8{
 9    /// <summary>
 10    /// Расширения для работы с типами транзакций
 11    /// Объединяет функциональность для работы с TransactionType enum
 12    /// </summary>
 13    public static class TransactionTypeExtensions
 14    {
 15        /// <summary>
 16        /// Получает все типы транзакций, исключая служебные (All)
 17        /// </summary>
 18        /// <returns>Список типов транзакций</returns>
 19        public static IEnumerable<TransactionType> GetTransactionTypes()
 20        {
 2621            return Enum.GetValues(typeof(TransactionType))
 2622                .Cast<TransactionType>()
 50223                .Where(t => t != TransactionType.All);
 24        }
 25
 26        /// <summary>
 27        /// Получает отображаемое имя типа транзакции
 28        /// </summary>
 29        /// <param name="transactionType">Тип транзакции</param>
 30        /// <returns>Отображаемое имя</returns>
 31        public static string GetTransactionDisplayName(this TransactionType transactionType)
 32        {
 433            return transactionType.GetDisplayName();
 34        }
 35
 36        /// <summary>
 37        /// Проверяет, является ли тип транзакции валидным (не All)
 38        /// </summary>
 39        /// <param name="transactionType">Тип транзакции</param>
 40        /// <returns>True, если тип валидный</returns>
 41        public static bool IsValidTransactionType(this TransactionType transactionType)
 42        {
 643            return transactionType != TransactionType.All;
 44        }
 45
 46        /// <summary>
 47        /// Получает тип транзакции по имени контроллера
 48        /// </summary>
 49        /// <param name="controllerName">Имя контроллера (например, "ReturnToSupplierTransactionController")</param>
 50        /// <returns>Тип транзакции или null, если не найден</returns>
 51        public static TransactionType? GetTransactionTypeByControllerName(string controllerName)
 52        {
 1253            if (string.IsNullOrWhiteSpace(controllerName))
 354                return null;
 55
 56            // Удаляем суффикс "TransactionController" или "Controller"
 957            var name = controllerName
 958                .Replace("TransactionController", "", StringComparison.OrdinalIgnoreCase)
 959                .Replace("Controller", "", StringComparison.OrdinalIgnoreCase);
 60
 61            // Маппинг имен контроллеров на типы транзакций
 962            var mapping = new Dictionary<string, TransactionType>(StringComparer.OrdinalIgnoreCase)
 963            {
 964                { "OrderToSupplier", TransactionType.OrderedToSupplier },
 965                { "OrderedToSupplier", TransactionType.OrderedToSupplier },
 966                { "ShippedBySupplier", TransactionType.ShippedBySupplier },
 967                { "ShippedToSeller", TransactionType.ShippedToSeller },
 968                { "OrderedToSeller", TransactionType.OrderedToSeller },
 969                { "ShippedToClient", TransactionType.ShippedToClient },
 970                { "Percentage", TransactionType.Percentage },
 971                { "AcceptedToWarehouse", TransactionType.AcceptedToWarehouse },
 972                { "ToCancellation", TransactionType.ToCancellation },
 973                { "Cancelled", TransactionType.Cancelled },
 974                { "CustomerReturn", TransactionType.CustomerReturn },
 975                { "WarehouseChange", TransactionType.WarehouseChange },
 976                { "ReturnToSupplier", TransactionType.ReturnToSupplier },
 977                { "ReturnToWarehouse", TransactionType.ReturnToWarehouse },
 978                { "ShippedToCommissioner", TransactionType.ShippedToCommissioner },
 979                { "ReturnTransfer", TransactionType.ReturnTransfer }
 980            };
 81
 982            return mapping.TryGetValue(name, out var type) ? type : null;
 83        }
 84
 85        /// <summary>
 86        /// Получает имя метода создания транзакции для типа транзакции
 87        /// </summary>
 88        /// <param name="transactionType">Тип транзакции</param>
 89        /// <returns>Имя метода</returns>
 90        public static string? GetCreateMethodName(this TransactionType transactionType)
 91        {
 692            var mapping = new Dictionary<TransactionType, string>
 693            {
 694                { TransactionType.OrderedToSupplier, "CreateOrderToSupplierTransaction" },
 695                { TransactionType.ShippedBySupplier, "CreateShippedBySupplierTransaction" },
 696                { TransactionType.ShippedToSeller, "CreateShippedToSellerTransaction" },
 697                { TransactionType.OrderedToSeller, "CreateOrderedToSellerTransaction" },
 698                { TransactionType.ShippedToClient, "CreateShippedToClientTransaction" },
 699                { TransactionType.Percentage, "CreatePercentageTransaction" },
 6100                { TransactionType.AcceptedToWarehouse, "AcceptedToWarehouseTransaction" },
 6101                { TransactionType.ToCancellation, "CreateToCancellationTransaction" },
 6102                { TransactionType.Cancelled, "CreateCancelledTransaction" },
 6103                { TransactionType.CustomerReturn, "CreateCustomerReturnTransaction" },
 6104                { TransactionType.WarehouseChange, "CreateWarehouseChangeTransaction" },
 6105                { TransactionType.ReturnToSupplier, "CreateReturnToSupplierTransaction" },
 6106                { TransactionType.ReturnToWarehouse, "CreateReturnToWarehouseTransaction" },
 6107                { TransactionType.ShippedToCommissioner, "CreateShippedToCommissionerTransaction" },
 6108                { TransactionType.ReturnTransfer, "CreateReturnTransferTransaction" }
 6109            };
 110
 6111            return mapping.TryGetValue(transactionType, out var methodName) ? methodName : null;
 112        }
 113
 114        /// <summary>
 115        /// Иконка FontAwesome для типа транзакции (как в списке операций на главной странице).
 116        /// </summary>
 117        public static string GetTransactionTypeIcon(this TransactionType transactionType)
 118        {
 4119            var mapping = new Dictionary<TransactionType, string>
 4120            {
 4121                { TransactionType.OrderedToSupplier, "fas fa-shopping-cart" },
 4122                { TransactionType.ShippedBySupplier, "fas fa-truck-loading" },
 4123                { TransactionType.ShippedToSeller, "fas fa-truck" },
 4124                { TransactionType.OrderedToSeller, "fas fa-handshake" },
 4125                { TransactionType.ShippedToClient, "fas fa-shipping-fast" },
 4126                { TransactionType.Percentage, "fas fa-percent" },
 4127                { TransactionType.ReceiptNote, "fas fa-file-invoice" },
 4128                { TransactionType.AcceptedToWarehouse, "fas fa-warehouse" },
 4129                { TransactionType.ToCancellation, "fas fa-hourglass-half" },
 4130                { TransactionType.Cancelled, "fas fa-times-circle" },
 4131                { TransactionType.CustomerReturn, "fas fa-undo" },
 4132                { TransactionType.WarehouseChange, "fas fa-edit" },
 4133                { TransactionType.ReturnToSupplier, "fas fa-reply-all" },
 4134                { TransactionType.ReturnToWarehouse, "fas fa-undo-alt" },
 4135                { TransactionType.WarehouseTransfer, "fas fa-exchange-alt" },
 4136                { TransactionType.ShippedToCommissioner, "fas fa-dolly" },
 4137                { TransactionType.ReturnTransfer, "fas fa-forward" }
 4138            };
 4139            return mapping.TryGetValue(transactionType, out var icon) ? icon : "fas fa-circle";
 140        }
 141
 142        /// <summary>
 143        /// Bootstrap link-* класс для типа транзакции (как в выпадающем меню операций на главной).
 144        /// </summary>
 145        public static string GetTransactionTypeCssClass(this TransactionType transactionType)
 146        {
 4147            var mapping = new Dictionary<TransactionType, string>
 4148            {
 4149                { TransactionType.OrderedToSupplier, "link-success" },
 4150                { TransactionType.OrderedToSeller, "link-secondary" },
 4151                { TransactionType.ShippedBySupplier, "link-info" },
 4152                { TransactionType.ShippedToSeller, "link-warning" },
 4153                { TransactionType.ShippedToClient, "link-success" },
 4154                { TransactionType.AcceptedToWarehouse, "link-info" },
 4155                { TransactionType.ToCancellation, "link-secondary" },
 4156                { TransactionType.Cancelled, "link-danger" },
 4157                { TransactionType.CustomerReturn, "link-warning" },
 4158                { TransactionType.WarehouseChange, "link-primary" },
 4159                { TransactionType.ReturnToSupplier, "link-warning" },
 4160                { TransactionType.ReturnToWarehouse, "link-info" },
 4161                { TransactionType.WarehouseTransfer, "link-primary" },
 4162                { TransactionType.ShippedToCommissioner, "link-primary" },
 4163                { TransactionType.Percentage, "link-secondary" },
 4164                { TransactionType.ReceiptNote, "link-secondary" },
 4165                { TransactionType.ReturnTransfer, "link-primary" }
 4166            };
 4167            return mapping.TryGetValue(transactionType, out var css) ? css : "link-secondary";
 168        }
 169    }
 170}
 171