我一直在努力坚持TDD方法.所以我做了一些测试,但都失败了.现在我正在实施.但是现在我正在实现我已经看到这些方法太简单而不能失败.特别是我实现了观察者模式,所有发生的事情是我通知所有注册的观察者.因此,对每个循环使用a并调用notify.这当然听起来太简单了.既然我在某些地方进行了测试,我应该删除它们吗?这似乎也有点浪费时间.那么我应该尝试预测一些过于简单的方法吗?
我希望彼得或鲁本看到这个问题,因为他们似乎是关于Ninject的人.我需要创建一个自定义提供程序,因为我有一个需要4个参数的类.可以注入两个,因为它们是类型,但另外两个是配置参数并且是整数.它们以毫秒为单位引用超时.
[SingleInstance]
MyClass
{
ISomething something;
IOther other;
int timeout;
int delay;
[Inject]
MyClass(ISomething something, IOther other, int timeout, int delay)
{
this.something = something;
this.other = other;
this.timeout = timeout;
this.delay = delay;
}
}
Run Code Online (Sandbox Code Playgroud)
我以前依赖于我创建的工厂来获取超时和延迟的配置设置以及注入其他内容.现在它似乎正确,我将不得不创建自己的自定义提供程序.哪个我没关系.
几点加分:
所以,我最后的问题:
更新:代码样本按要求
然后,我认为我的提供者想要这样的东西:
class MyClassProvider : SimpleProvider<MyClass> {
protected override MyClass CreateInstance(IContext context) {
int timeout= ConfigurationManager.AppSettings.Get("timeout");
int delay= ConfiguraionManager.AppSettings.Get("delay");
ISomething something = new SomethingImpl();
IOther other = new OtherImpl();
MyClass newOne = New MyClass(something, other, timeout, delay); …Run Code Online (Sandbox Code Playgroud) 我想在根记录器中添加一个内存appender,以便我可以连接到应用程序并获取最后10个事件.我只想保留最后的10.我担心这个appender消耗了太多的内存.该应用程序旨在24/7运行.或者还有另一种方式吗?
我尝试安装 Consolas 字体包,以便可以在 VS 2005 中使用它。出于某种原因,它看起来比Wikipedia和Jeff Atwood 的示例大胆得多。我读过一些有关抗锯齿的内容,现在正在尝试。关于如何让它看起来又薄又时尚有什么想法吗?
编辑:抱歉发现了。它与 ClearType 字体有关。打开它解决了我所有的问题。
位置数据基本上是树形结构.因此,当您向某人询问他们的地址时,您想知道他们居住的地区/郊区,城市/城镇,州/省和国家/地区.
希望这些数据只能设置一次,只需要很少的修改.大多数电子商务网站和许多其他网站都需要存储这类信息,但我很难找到它.也许是因为我没有寻找合适的术语,但我认为这将是一个已经解决的常见问题.
这引出了另一个问题.我在哪里可以获得这类信息,例如哪个地区属于哪个城市,哪些城市属于哪些州以及哪些州属于哪些国家/地区?
编辑:为了使事情变得更复杂,我希望能够提供一种通用的解决方案,因为例如一些国家不使用邮政编码,他们使用邮政编码,它有点相同但不完全相同.我的主要愿望是拥有区/郊区 - >城市/城镇 - >地区/省/州 - >国家.我可能正在尝试不可能的事情.
EDIT2:对不起,我可能不够清楚,但我不需要邮政编码.只是郊区/地区名称 - >城市........
例如,我们调用BeginReceive并具有BeginReceive完成后执行的回调方法.如果那个回调方法再次在我的脑海中调用BeginReceive,那将非常类似于递归.这怎么会导致stackoverflow异常.来自MSDN的示例代码:
private static void Receive(Socket client) {
try {
// Create the state object.
StateObject state = new StateObject();
state.workSocket = client;
// Begin receiving the data from the remote device.
client.BeginReceive( state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
}
private static void ReceiveCallback( IAsyncResult ar ) {
try {
// Retrieve the state object and the client socket
// from the asynchronous state object.
StateObject state = (StateObject) ar.AsyncState;
Socket client = …Run Code Online (Sandbox Code Playgroud) 我想构建某种接口来监控我们的实时路由/交换系统.我想提供大量的视觉反馈,以便能够直观地监控其状态.我们的系统和客户端不在同一地点,因此需要通过TCP/IP进行连接.
我希望能够为任意数量的监控客户端提供服务(尽管这可能只有4-6个客户端).我想过使用SilverLight,但似乎有一两个技巧涉及让SilverLight连接回运行在不同端口上的应用程序.
我还想过使用HTML5 canvas和websockets.另一种方法是使用普通的Window Forms和WPF来创建客户端.但这意味着要监控应用程序,客户端必须先下载.我更喜欢像网络应用程序一样容易访问的东西?
有哪些更常见的应用程序堆栈可以实现这一目标?我应该注意什么?
编辑:
只是添加:这将只是一个内部工具.但我们在几个地方都设有办事处.
这可能是重复的,但我在这里看了很多其他问题,他们通常会以某种方式错过我正在寻找的东西.他们主要谈论他们自己创造的服务.我能做到并做到了.我试图覆盖我的模拟注入的角度.我认为它会是相同的,但由于某些原因,当我单步执行代码时,它始终是角度$ cookieStore而不是我的模拟.
我对jasmine和angularjs的经验非常有限.我来自C#背景.我经常编写单元测试moq(C#的模拟框架).我习惯看到这样的事情
[TestClass]
public PageControllerTests
{
private Mock<ICookieStore> mockCookieStore;
private PageController controller;
[TestInitialize]
public void SetUp()
{
mockCookieStore = new Mock<ICookieStore>();
controller = new PageController(mockCookieStore.Object);
}
[TestMethod]
public void GetsCarsFromCookieStore()
{
// Arrange
mockCookieStore.Setup(cs => cs.Get("cars"))
.Return(0);
// Act
controller.SomeMethod();
// Assert
mockCookieStore.VerifyAll();
}
}
Run Code Online (Sandbox Code Playgroud)
我想模拟我在我的一个控制器中使用的$ cookieStore服务.
app.controller('PageController', ['$scope', '$cookieStore', function($scope, $cookieStore) {
$scope.cars = $cookieStore.get('cars');
if($scope.cars == 0) {
// Do other logic here
.
}
$scope.foo = function() {
.
.
}
}]);
Run Code Online (Sandbox Code Playgroud)
我想确保使用'garage'参数调用$ cookieStore.get方法.我也希望能够控制它的回馈.我希望它返回0然后我的控制器必须做一些其他逻辑.
这是我的测试.
describe('Controller: …Run Code Online (Sandbox Code Playgroud) 不确定如何表达问题所以请编辑,如果你能想出更好的东西.我有以下指令:
app.directive('foo', function() {
return {
restrict: 'A',
require: "?ngModel",
link: function (scope, element, attrs, controller) {
scope.$watch(attrs.ngModel, function () {
console.log("Changed to " + scope[attrs.ngModel]);
});
}
};
});
Run Code Online (Sandbox Code Playgroud)
当我有这个它很好,并正确记录
<input type="text" ng-model="bar" />
app.controller('fooController', function($scope) {
$scope.bar = 'ice cream';
});
Run Code Online (Sandbox Code Playgroud)
当我以这种方式尝试它时,它不起作用.它不断记录'Changed to undefined'
<input type="text" ng-model="model.bar" />
app.controller('fooController', function($scope) {
$scope.model = { bar: 'ice cream' };
});
Run Code Online (Sandbox Code Playgroud)
如何使它适用于这两种情况.看起来正确的角度让你可以使用两者.
我正在尝试在DelegatingHandler中实现身份验证.以下是一个例子.
public class AuthHandler: DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var auth = request.Headers.Authorization;
if (!auth.Scheme.Equals("UberSecureScheme"))
{
return new Task<HttpResponseMessage>(() => new HttpResponseMessage(HttpStatusCode.Unauthorized)
{
Content = new StringContent("You have no token")
});
}
return base.SendAsync(request, cancellationToken);
}
}
Run Code Online (Sandbox Code Playgroud)
这永远不会执行任务,也不会返回任何响应.如果我改变代码来做一些任务延续的事情,比如我已经看过一些例子,那么首先执行Controller.
return base.SendAsync(request, cancellationToken)
.ContinueWith(task =>
{
var response = task.Result;
response.StatusCode = HttpStatusCode.Unauthorized;
return response;
});
Run Code Online (Sandbox Code Playgroud)
这显然是一场灾难.我不能让某人删除,然后告诉他们他们是未经授权的.
我也遇到过有人说只是抛出一个HTTPResponseException.无论我在那里放置什么状态代码(404,401,无论如何),浏览器总是会收到500内部服务器错误.
.net ×4
unit-testing ×3
angularjs ×2
asynchronous ×1
c# ×1
fonts ×1
ide ×1
jasmine ×1
log4net ×1
logging ×1
monitoring ×1
ninject ×1
tdd ×1