在类的设计中经常会有类或者方法要设置成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 };
}
}
}

单元测试如何覆盖internal的方法的更多相关文章

  1. 在C#中使用反射调用internal的方法

    MSDN上解释Internal如下: The internal keyword is an access modifier for types and type members. Internal t ...

  2. Python3解决棋盘覆盖问题的方法示例

    本文实例讲述了Python3解决棋盘覆盖问题的方法.分享给大家供大家参考,具体如下: 问题描述: 在2^k*2^k个方格组成的棋盘中,有一个方格被占用,用下图的4种L型骨牌覆盖所有棋盘上的其余所有方格 ...

  3. JavaScript 覆盖document.createElement 方法 解决window.close在火狐下不兼容问题)

    近期项目遇到了问题,有个asp.net web程序仅仅能在IE7 执行.如今xp都淘汰了,大家都用IE8-IE11,因此这个web app也须要升级 适应全部IE版本号.照成IE版本号不兼容的问题主要 ...

  4. JavaScript 覆盖document.createElement 方法

    最近项目遇到了问题,有个asp.net web程序只能在IE7 运行,现在xp都淘汰了,大家都用IE8-IE11,因此这个web app也需要升级 适应所有IE版本.照成IE版本不兼容的问题主要来致d ...

  5. C#单元测试:NUnit详细使用方法

    1. TDD的简介 首先什么是TDD呢?Kent Beck在他的<<测试驱动开发 >>(Addison-Wesley Professional,2003)一书中,使用下面2个原 ...

  6. 单元测试遇到的Mock重载方法问题

    测试某个异常抛出情况,单元测试输出为验证Logger的一条记录,该异常情况日志记录LogInfo,但是LogInfo中平时都用一个参数,在catch这个异常时调用了两个参数的重载方法,导致一直Mock ...

  7. 使用super调用被子类覆盖的父类方法

    1.没有super方法 /* * 子类方法覆盖父类方法,用super方法可以调用父类被覆盖的方法 */ class fruit{ public fruit() { System.out.println ...

  8. 下拉列表被flash覆盖的解决方法

    做鼎闻有一段时间了,有的banner轮播图的地方用flash替换的时候,就会导致上面的导航条下拉列表被flash覆盖,找了一段时间没有得到有效的解决方法,后来知道关键是flash的这一属性{ &quo ...

  9. 方法覆盖 和toString方法的作用

    当我们代码怎么编写的时候,在代码级别上构成了方法的覆盖呢? 两个类必须要有继承关系. 重写之后的方法和之前的方法具有:相同的返回值类型 相同的方法名 相同的形参列表 访问权限不能更高,只能更低 重写之 ...

随机推荐

  1. CF618G(利用浮点数精度+矩乘优化DP)

    这题真的太神辣,%了一发题解,原来还能这么搞QWQ 设\(A_{i,j}\)表示不加任何限制时,第\(i\)个格子会出现权值为\(j\)的史莱姆的概率,则有: \[A_{i,j}=A_{i,j-1}* ...

  2. nowcoder16450 托米的简单表示法

    题目链接 思路 仔细理解一下题意可以发现. 对于每个完整的括号序列都是独立的,然后就想到分治.高度是序列中所有括号序列的最大值,宽度是所有括号序列宽度和\(+1\). 然后仔细想了一下,这种分治应该是 ...

  3. 转载:ORA-12516 “TNS监听程序找不到符合协议堆栈要求的可用处理程序” 解决方案

    ORA-12516 “TNS监听程序找不到符合协议堆栈要求的可用处理程序” 解决方案   简单描述一下场景,总共两台应用服务器,每台安装3个tomcat进行集群,并通过nginx做了负载均衡,今天在生 ...

  4. GoLang-Rpc编程

    Rpc定义: RPC(Remote Procedure Call,远程过程调用)是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络细节的应用程序通信协议. RPC协议构建于TCP或UDP, ...

  5. 深入剖析Kubernetes学习笔记:开篇词(00)

    一.关于Kubernetes初学的疑惑 就在这场因"容器"而起的技术变革中,kubernetes项目已经成为容器技术的事实标准,重新定义了基础设置领域对应用编排与管理的种种可能 1 ...

  6. DirectX11 With Windows SDK--21 鼠标拾取

    前言 拾取是一项非常重要的技术,不论是电脑上用鼠标操作,还是手机的触屏操作,只要涉及到UI控件的选取则必然要用到该项技术.除此之外,一些类似魔兽争霸3.星际争霸2这样的3D即时战略游戏也需要通过拾取技 ...

  7. 如何清理Docker占用的磁盘空间?(转载)

    本文转载自https://blog.fundebug.com/2018/01/10/how-to-clean-docker-disk/ , 感谢原作者. 摘要:用了Docker,好处挺多的,但是有一个 ...

  8. split host

    # encoding:utf-8 _portprog = None def split_host_port(host): """ split the host :para ...

  9. 【codeforces 765F】Souvenirs

    Description Artsem is on vacation and wants to buy souvenirs for his two teammates. There are n souv ...

  10. ado.net 使用:ExecuteReader 无法获取输出参数

    解决方法: 要获取到输出参数.需要连接关闭之后才行. 一般都是用using把打开数据库连接的reader包起来