在类的设计中经常会有类或者方法要设置成private或者internal等方式,在使用中这么做无可厚非,但是对单元测试的影响也颇大

  1. 对于private方法,那只有做一个副本然后改成internal或public来测试
  2. 对于internal的类和方法可以直接利用[assembly]标签来指定该类可以被哪个dll/方案读取
 /*******************************************************************************
* File Name: SoftwareInfoHelper.cs
* Namespace:
*
* CreateTime: 2018/9/6 14:50
* Author: linkanyway
* Description: SoftwareInfoHelper
* Class Name: SoftwareInfoHelper
*
* Ver ChangeDate Author Description
* ───────────────────────────────────
* V0.01 2018/9/6 14:50 linkanyway draft
*
* Copyright (c) 2018 linkanyway
* Description: Framework
*
*********************************************************************************/ using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; [assembly: InternalsVisibleTo("TestProject.Nirvana.Infrastructure")
] namespace Nirvana.Infrastructure.Runtime
{
/// <summary>
/// SoftwareInfoHelper
/// </summary>
// ReSharper disable once UnusedMember.Global
public static class SoftwareInfoHelper
{
/// <summary>
/// Return correct .NET Core product name like ".NET Core 2.1.0" instead of ".NET Core 4.6.26515.07" returning by RuntimeInformation.FrameworkDescription
/// </summary>
/// <returns></returns>
// ReSharper disable once UnusedMember.Global
internal static string GetFrameworkDescription()
{
// ".NET Core 4.6.26515.07" => ".NET Core 2.1.0"
// var parts = RuntimeInformation.FrameworkDescription.Split([' '], StringSplitOptions.RemoveEmptyEntries);
var charSeparators = new[] {','};
var parts = RuntimeInformation.FrameworkDescription.Split(charSeparators,
StringSplitOptions.RemoveEmptyEntries);
var i = ;
for (; i < parts.Length; i++)
{
if (char.IsDigit(parts[i][]))
{
break;
}
} var productName = string.Join("", parts, , i);
return string.Join("", productName, " ", GetNetCoreVersion());
} /// <summary>
///
/// </summary>
/// <returns></returns>
internal static string GetNetCoreVersion()
{
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] {'/', '\\'}, StringSplitOptions.RemoveEmptyEntries);
var netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > && netCoreAppIndex < assemblyPath.Length - )
return assemblyPath[netCoreAppIndex + ];
return null;
} /// <summary>
///
/// </summary>
/// <returns></returns>
public static PlatformInformation GetPlatformInformation()
{
OSPlatform platform; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
platform = OSPlatform.Windows;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
platform = OSPlatform.Linux;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
platform = OSPlatform.OSX;
return new PlatformInformation()
{
Architecture = RuntimeInformation.OSArchitecture,
DotnetVersion = GetNetCoreVersion(),
Os = platform,
OsVersion = RuntimeInformation.OSDescription };
}
}
}

最新文章

  1. .NET跨平台之旅:成功将示例站点升级至ASP.NET Core RC2
  2. 小白如何进入IOS,答案就在这里
  3. 下载安装resin-3.X服务器并配置到myeclipse
  4. HDU 3555 数位dp入门
  5. hadoop2 作业执行过程之作业提交
  6. Android Mms 接收信息流程
  7. 面试知识:操作系统、计算机网络、设计模式、Linux编程,数据结构总结
  8. Redis的探究
  9. 空格&amp;amp;nbsp在不同浏览器中显示距离不一致问题解决方法
  10. mysql 自己定义存储过程和触发器
  11. 【百度地图API】如何给自定义覆盖物添加事件
  12. [html5] 学习笔记-编辑 API 之 Range 对象(一)
  13. PHP 页面静态化/纯静态化/伪静态化
  14. MySQL之爱之初体验
  15. Solr 06 - Solr中配置使用IK分词器 (配置schema.xml)
  16. __c语言__结构体、共用体、枚举__笔记
  17. Laravel 执行流程(一)之自动加载
  18. Windows Server 2008 R2终端服务器激活方法
  19. A1104. Sum of Number Segments
  20. 319. Bulb Switcher

热门文章

  1. restfull规范、DRF视图和路由
  2. DRF之频率限制、分页、解析器和渲染器
  3. 洛谷P1608路径统计
  4. JMeter测试(菜鸟级,高手莫点)
  5. Django_modelform组件
  6. python之路day01--变量
  7. Day041--CSS, 盒模型, 浮动
  8. Python终极coding
  9. Jenkins-在windows上配置自动化部署(Jenkins+Bonobo.Git.Server)
  10. java Ajax跨域请求COOKIE无法带上的解决办法