我们有一个非常大的系统,过去常常用私人设置器将数据加载到属性中.对于使用测试特定方案,我曾经使用私有setter在这些属性中写入数据.
但是,由于系统变慢,并且正在加载无关紧要的东西,我们使用Lazy类将某些内容更改为延迟加载.但是,现在我不再能够将数据写入这些属性,因此很多单元测试将不再运行.
public class ComplexClass
{
public DateTime Date { get; private set; }
public ComplexClass()
{
// Sample data, eager loading data into variable
Date = DateTime.Now;
}
public string GetDay()
{
if (Date.Day == 1 && Date.Month == 1)
{
return "New year!";
}
return string.Empty;
}
}
Run Code Online (Sandbox Code Playgroud)
[Test]
public void TestNewyear()
{
var complexClass = new ComplexClass();
var newYear = new DateTime(2014, 1, 1);
ReflectionHelper.SetProperty(complexClass, "Date", newYear);
Assert.AreEqual("New year!", complexClass.GetDay());
}
Run Code Online (Sandbox Code Playgroud)
public …Run Code Online (Sandbox Code Playgroud) 几天前我在TechEd,我看到Kevin Pilch-Bisson的这个演讲(相关部分大约18分钟开始) ......我觉得很酷,所以我决定自己和Roslyn一起玩.
我正试图制定一个规则"必须声明访问修饰符"(Stylecop SA1400) - 意思是,
这违反了规则:
static void Main(string[] args)
{
}
Run Code Online (Sandbox Code Playgroud)
还行吧:
public static void Main(string[] args)
{
}
Run Code Online (Sandbox Code Playgroud)
它必须具有明确的内部关键字,公共关键字,私有关键字或受保护的关键字.
检测违规是相当容易的,但现在我正在尝试提供修复.我一直在尝试和搜索各处,但我无法找到如何添加访问修饰符.
这是我到目前为止:
public async Task<IEnumerable<CodeAction>> GetFixesAsync(Document document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var token = root.FindToken(span.Start);
var methodDeclaration = token.Parent as MethodDeclarationSyntax;
//var newModifiers = methodDeclaration.Modifiers.Add(SyntaxFactory.AccessorDeclaration(SyntaxKind.PublicKeyword));
//var newModifiers = new SyntaxTokenList() { new SyntaxToken() };
MethodDeclarationSyntax newMethodDeclaration = methodDeclaration.WithModifiers(methodDeclaration.Modifiers);
var newRoot = root.ReplaceNode(methodDeclaration, newMethodDeclaration);
var newDocument = document.WithSyntaxRoot(newRoot);
return …Run Code Online (Sandbox Code Playgroud) 我想知道,是否有可能创建自己的帮助器定义,使用?例如以下创建表单:
using (Html.BeginForm(params))
{
}
Run Code Online (Sandbox Code Playgroud)
我想做那样的自己的帮手.这是一个我想做的简单例子
using(Tablehelper.Begintable(id)
{
<th>content etc<th>
}
Run Code Online (Sandbox Code Playgroud)
这将在我的视图中输出
<table>
<th>content etc<th>
</table>
Run Code Online (Sandbox Code Playgroud)
这可能吗?如果是这样,怎么样?
谢谢
可能重复:
如何在不使用游标的情况下计算SQL中的运行总计?
这有点难以解释,所以我将通过一个例子展示我想要的东西:
可以说我们有以下表格命名MonthProfit:
[MonthId][Profit]
1, 10 -- January
2, 20 -- February
3, 30
4, 40
5, 50
6, 60
7, 70
8, 80
9, 90
10, 100
11, 110
12, 120 -- December
Run Code Online (Sandbox Code Playgroud)
列profit表示该月的利润.
但是,如果我们1月份有10个利润,2月份有20个,那么2月份我们的利润总额为30.
所以我想创建一个显示以下内容的视图:
[MonthId][Profit][ProfitTotal]
1, 10, 10 -- January
2, 20, 30 -- February
3, 30, 60
4, 40, 100
5, 50, 150
6, 60, 210
7, 70, 280
8, 80, 360
9, 90, 450
10, 100, 550
11, 110, 660 …Run Code Online (Sandbox Code Playgroud) 我目前正在使用TFS/Visual Studio Team Services(VS Online)建立持续集成,我正在使用Team Foundation Build 2015任务.所以不是XAML构建的.
我正在使用它来构建一个Xamarin Android项目,但我认为这是非常不敬的,
这个过程应该是这样的:
然后剩下的,构建部署到hockeyapp等
第一步都已配置完毕,但我正在努力完成提交部分.如何让TFS提交文件?我真的没有看到任何适合它的任务.我尝试过使用Copy and Publish Build Artifacts Utility - 但这似乎不起作用,我甚至不确定这是否是正确的实用程序
我正在使用默认的托管构建代理btw.任何帮助,将不胜感激
我正在使用Entity Framework开发一个应用程序.我有一个组合框,其中包含数据库中表的名称.我有以下代码:
string table = cbTables.SelectedItem.ToString();
using (var dbContext = new Entities()) {
if (table.Equals("Person")) {
List<Person> list = (from l in dbContext.People select l).ToList();
} else if (table.Equals("Student")) {
List<Student> list = (from u in dbContext.Student select u).ToList();
} else if (table.Equals("Grade")) {
List<Grade> list = (from p in dbContext.Grade select p).ToList();
}
Run Code Online (Sandbox Code Playgroud)
我怎么能避免所有这些if-else检查?是否可以从包含该名称的字符串中获取类的名称?
例:
string = "Person";
var str = //something
List<str> list = (from u in dbContext.str select u).ToList();
Run Code Online (Sandbox Code Playgroud) 我有一个非常大的应用程序,它使用了许多其他服务.对于测试场景,我不希望我的单元测试依赖于第三方系统,因此我想用假货或模拟或其他任何方式替换服务.
我已经完成了大部分的艰苦劳动,用一个替换了具体的服务IService.具体的服务与DI框架连接
现在我想用随机生成的假货替换那些.
public interface ISimpleService
{
int Fizz(int input);
string Buzz(string input);
}
Run Code Online (Sandbox Code Playgroud)
public interface ISimpleServiceFactory
{
ISimpleService Create();
}
Run Code Online (Sandbox Code Playgroud)
public static void Main(string[] args)
{
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var service = fixture.Create<ISimpleService>();
var fizzResult = service.Fizz(42);
var buzzResult = service.Buzz("I'd like something random...");
}
Run Code Online (Sandbox Code Playgroud)
这显示了我基本上想要的东西.我只想让autofixture为我创建一些动态代理对象,方法返回接口中指定类型的随机类...
请注意,我在这里使用过AutoMoq,因为默认情况下Fixture不想从接口创建对象,但我也尝试过其他框架:FakeItEasy,AutoRhinoMock
public static void Main(string[] args)
{
var fixture = new Fixture().Customize(new AutoMoqCustomization());
var serviceMock = fixture.Create<Mock<ISimpleService>>();
// These two lines …Run Code Online (Sandbox Code Playgroud) 我们有一个与 ASP Core API 通信的 React 前端。
有时我们会检测到前端有问题,包括 Service Worker、本地缓存之类的东西,所以我们想告诉客户端清理它。
我已经实现了Clear-Site-Data (dev-moz) (w3c)作为响应头,如"Clear-Site-Data": "cache", "cookies", "storage", "executionContexts"
在 Firefox 中对此进行测试时,它可以工作,并且在控制台中我看到:
Clear-Site-Data header found. Unknown value “"executionContexts"”. SignIn
Clear-Site-Data header forced the clean up of “cache” data. SignIn
Clear-Site-Data header forced the clean up of “cookies” data. SignIn
Clear-Site-Data header forced the clean up of “storage” data.
Run Code Online (Sandbox Code Playgroud)
在 Chrome 中做同样的事情时,它不起作用,我看到了消息
The request's credentials mode prohibits modifying cookies and other local data.
Run Code Online (Sandbox Code Playgroud)
我试图弄清楚如何修复它,但几乎没有任何参考。只有 7 个结果,主要来自浏览器集成测试日志
所有的文档都说这应该在 Chrome 中实现和工作......知道有什么问题吗?
c# ×5
.net ×1
autofixture ×1
azure-devops ×1
html-helper ×1
moq ×1
razor ×1
recursion ×1
reflection ×1
roslyn ×1
sql ×1
t-sql ×1
tfs ×1
unit-testing ×1