下面是一些使用参数类来包含Show()方法可能参数的代码.这个FooOption类中的值不是很相关.您可以通过查看Show()下面的实现来看到这一点.我知道这是错误的代码,但有没有与此相关的反模式?
class FooOptions {
public int? Id { get; set; }
public string BazContext { get; set; }
public int? BazId { get; set; }
}
class BarMgr {
public Bar Show(FooOptions options) {
if (options == null)
options = new FooOptions();
if (options.Id.HasValue)
return svc.GetBar(options.Id.Value);
if (!string.IsNullOrEmpty(options.BazContext) && options.BazId.HasValue)
return svc.GetBar(options.BazContext, options.BazId.Value);
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
更新:我知道参数对象不是反模式.根据我的经验,参数对象属性是相关的.这是我试图找到的可能的反模式.设置所有三个属性是没有意义的.
我正在尝试使用TeamCity在x64机器上为.net 4设置partcover.
测试已执行,但覆盖率报告显示0覆盖范围.
我在日志中收到以下消息:
No executable code was detected.
The issue could be caused by one of the following:
- Include / exclude patterns are incorrect
- Assemblies are compiled without debugging information
- .pdb files are not available
- Visual Studio code coverage is enabled for MSTest
- .testrunconfig is used for MSTest and Visual Studio code coverage is not disabled (CodeCoverage section with enable="true" is present)
Run Code Online (Sandbox Code Playgroud)
但包含模式是[*]*.
如果重要的话,我正在运行TeamCity 6.5.3.有没有人设法在该版本上运行partcover?
假设我有一些胖接口,无法更改.而且我还有一些客户端类只想使用胖接口中的少数方法.如何针对这种情况实现适配器模式,实现接口隔离原则?
c# oop design-patterns adapter interface-segregation-principle
遵循 CQRS(命令查询职责分离)的概念,我在我的 MVC 应用程序中直接引用 DAL,并通过 ViewModel 进行所有读取。然而,我的一位同事问我,当阅读时必须应用任何业务逻辑时,你会怎么做。例如,如果您需要在如下场景中计算百分比值:
//Employee domain object
class Employee
{
string EmpName;
Single Wages;
}
//Constant declared in some utility class. This could be stored in DB also.
const Single Tax = 15;
//View Model for the Employee Screen
class EmployeeViewModel
{
string EmpName;
Single GrossWages;
Single NetWages;
}
// Read Facade defined in the DAL
class ReadModel
{
List<EmployeeViewModel> GetEmployeeList()
{
List<EmployeeViewModel> empList = new List<EmployeeViewModel>;
string query = "SELECT EMP_NAME, WAGES FROM EMPLOYEE";
...
.. …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现责任链模式,但似乎我缺少一些东西,因为在具体的类中,setnexthandler没有设置下一个但总是相同的.我想我的错误是在else statems next.setNextHandler(next)中的processMalfunction()方法的具体类中; 我认为它应该是next.setNextHandler(Severity.Medium)的第一个.所以这是代码,如果你可以看看.这是代码.
public interface MalfunctionHandler
{
public void processMalfunction(Malfunction malfunciton);
public void setNextHandler(MalfunctionHandler handler);
}
public enum Severity
{
TRIVIAL, LOW, MEDIUM, HIGH
}
public class Malfunction
{
/**
* severity is a type of Severity
*/
Severity severity;
/**
* @param description describes the severity of the problem
*/
String description;
Malfunction(Severity severity, String description)
{
if(description == null)
{
description = "No description available. Probably serious.";
}
if(description.isEmpty())
{
description = "No description available. Probably serious."; …Run Code Online (Sandbox Code Playgroud) 我对使用哪种模式设计以下场景感到困惑,
Interface GearBox {
int upshift();
int downshift();
int reverse();
}
AutoGearBox implements GearBox{...}
ManualGearBox implements GearBox{...}
Run Code Online (Sandbox Code Playgroud)
现在我想将DualClutchGearBox添加到层次结构中.以前的所有变速箱都是单离合器.我该怎么做呢?
装饰师 - >
DualClutchDecorator implements GearBox{
DualClutchDecorator(GearBox box){...}
}
Run Code Online (Sandbox Code Playgroud)
用桥 - >
GearBox{
GearBoxImpl impl;
....
}
AutoGearBox implements GearBox{...}
ManualGearBox implements GearBox{...}
abstract class GearBoxImpl{}
SingleClutchImpl extends GearBoxImpl{...}
DualClutchImpl extends GearBoxImpl{...}
Run Code Online (Sandbox Code Playgroud)
哪一个更好,为什么?
我正在尝试TeamCity 6.5.6使用git带有一个子模块的repo进行构建,但是"无法启动构建".
.gitmodules 文件:
[submodule "src/shared-contracts"]
path = src/shared-contracts
url = gitolite@myserver:shared-contracts
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
Failed to start build: Server was not able to build correct patch, most likely due to VCS errors, will try again.
jetbrains.buildServer.agent.impl.patch.PatchDownloaderImpl$1: Server was not able to build correct patch, most likely due to VCS errors, will try again.
Caused by: jetbrains.buildServer.vcs.patches.UnsuccessfulPatchException: Failed to build patch for build #s5 {build id=19947}, VCS root: gitolite@myserver:myrepo#mapi-qa {instance id=1152, parent id=280}, due to error: Patch building …
我正在测试一个随机字符串生成器,该生成器需要两个单词数组,然后从中选择随机单词。我需要能够测试它实际上是随机的。例如:
FrostyMeadow.generate(:nouns => ["hello", "world"], :adjectives => ["hello","world"]
Run Code Online (Sandbox Code Playgroud)
应该生成以下字符串之一:
["hello world", "world world", "world hello", "hello hello"]
Run Code Online (Sandbox Code Playgroud)
有什么办法可以给rspec该数组并检查生成的字符串是否在其中?
我需要为压缩和解压缩ArraySegment对象的方法编写单元测试.这些方法中有很多奇怪的处理方法,我不需要理解.(他们也使用一些系统方法 - 我不知道他们的实现.)
问题在于如何实际测试这些东西.我可以检查具体输入的压缩方法的结果是什么Lorem ipsum dolor sit amet, consectetur adipisicing elit.- 并根据此实验创建一个测试用例,但此解决方案不测试任何边界情况.
我还可以测试在某些序列上进行压缩然后解压缩是否给出了第一个输入序列,但这不是纯粹的单元测试.
你遇到过这样的问题吗?它有什么好的解决方案吗?
我想从一个步骤传递2个字符串,如下面的代码所示:
testfeature.feature
Then Enter Text 'fName' <fname>
Then Enter Text 'mName' <mname>
Then Enter Text 'lName' <lname>
Examples:
| fname | mname | lname |
| FnameTest | FnameTest | FnameTest |
Run Code Online (Sandbox Code Playgroud)
testfeature.rb
Then /^Enter Text (.*) (.*)$/ do |fieldId|value|
@browser.text_field(:id, fieldId).set(value)
end
Run Code Online (Sandbox Code Playgroud)
这里fname/lname/mname取自Examples,我将页面元素传递给单引号字符串.
由于我是Ruby/Cucumber/Watir的新手,我无法理解应该如何处理它.
请注意 -
以前我为所有3个步骤编写了一个单独的正则表达式,但是为了优化我正在尝试这种方法.
期待所有快乐的想法:)
c# ×3
java ×2
ruby ×2
teamcity ×2
unit-testing ×2
.net ×1
adapter ×1
architecture ×1
bridge ×1
compression ×1
cqrs ×1
cucumber ×1
decorator ×1
git ×1
interface-segregation-principle ×1
oop ×1
partcover ×1
rspec ×1
teamcity-6 ×1
testcase ×1
testing ×1