在类的设计中经常会有类或者方法要设置成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. 配置启动MySQL的Docker容器

    docker run -d -p : --name mysql -e MYSQL_ROOT_PASSWORD= mysql:

  2. 作业二:Git的安装与使用

    作业的要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 分布式版本控制系统Git的安装与使用 1.下载安装配置用户名 ...

  3. POJChallengeRound2 Tree 【数学期望】

    题目分析: 我们令$G(x)$表示前$x$个点的平均深度,$F(x)$表示第$x$个点的期望深度. 有$F(x) = G(x-1)+1$,$G(x) = G(x-1)+\frac{1}{x}$ 所以答 ...

  4. [luogu3380][bzoj3196]【模板】二逼平衡树【树套树】

    题目地址 [洛谷传送门] 题目大意 区间查询k的排名,查找k排名的数,单点修改,区间前驱,区间后继. 感想 真的第一次写树套树,整个人都不对了.重构代码2次,发现样例都过不了,splay直接爆炸,可能 ...

  5. bzoj3051[WC2013]平面图(树上倍增+平面图转对偶图+扫描线)

    简要题意:二维平面上n个点,点之间有一些连线,连线不在点之外的地方相交,将平面分为若干个区域.给出一些询问点对,问从这个点所在的区域走到另一个点所在的区域的最小代价. 题解:这道题首先可以把平面图转对 ...

  6. 第十八节、基于传统图像处理的目标检测与识别(HOG+SVM附代码)

    其实在深度学习中我们已经介绍了目标检测和目标识别的概念.为了照顾一些没有学过深度学习的童鞋,这里我重新说明一次:目标检测是用来确定图像上某个区域是否有我们要识别的对象,目标识别是用来判断图片上这个对象 ...

  7. Python Pandas 简单使用之 API熟悉

    1.read_csv li_index = ['round_id', 'index', 'c-sequen' ] dataset = pd.read_csv(file, low_memory=Fals ...

  8. 点评cat系列-简介

    面上有很多优秀的 OS 级监控系统 (比如 falcon), 这些监控系统主要聚焦在 CPU/IO/Mem/Disk 和应用端口, falcon 甚至可以监控到 JVM. 但对于应用系统内部的一些监控 ...

  9. vue父路由默认选中第一个子路由,切换子路由让父路由高亮不会消失

    vue父路由默认选中第一个子路由,切换子路由让父路由高亮不会消失 正常默认会有 .router-active-class 识别高亮 达到以上注意: 1. exact 不要加 注意是不要加,exact ...

  10. 如何使用多数据源,同时使用jpa和jdbctemplate

    spring: datasource: first: type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://xx.xx.xx.x ...