fra*_*tal 4 tdd inotifypropertychanged ios mvvmcross
我正在使用Xamarin Studio使用MvvmCross开始TDD.我首先尝试测试发布的消息对视图模型的影响,以便仅在收到相应的消息时才执行逻辑.
我已经将Stuart的一些优秀教程混合在一起,导致成功传播位置数据,以查看模型,然后在IOS视图上更新一些文本控件,地图标记等.
但在我进一步深入研究之前,我想使用TDD进行编码.如何人工设置viewmodel并在我的测试工具中人为地将消息发布到它?:
public class MyViewModel : MvxViewModel
{
private readonly MvxSubscriptionToken _token;
public MyViewModel(ILocationService service, IMvxMessenger messenger)
{
//weak reference
_token = messenger.Subscribe<LocationMessage>(OnLocationMessage);
}
private void OnLocationMessage(LocationMessage locationMessage)
{
Lat = locationMessage.Lat;
Lng = locationMessage.Lng;
// Console.WriteLine("on loc msg {0:0.0000}, {1:0.0000}", Lat, Lng);
}
private double _lng;
public double Lng
{
get { return _lng; }
set
{
_lng = value;
RaisePropertyChanged(() => Lng);
}
}
private double _lat;
public double Lat
{
get { return _lat; }
set
{
_lat = value;
RaisePropertyChanged(() => Lat);
}
}
}
[TestFixture()]
public class LocTest
{
[Test()]
public void LocationMessageIsRecieved()
{
// im using nsubstitute to mock with
var locService = Substitute.For<ILocationService>();
var msgr = Substitute.For<IMvxMessenger>();
var vm = new Map2ViewModel(locService, msgr);
var locMsg = new LocationMessage(this, 1F, 2F);
msgr.Publish(locMsg);
var lat = vm.Lat;
Assert.AreEqual(2F, lat); // says lat is 0.0 and nunit doesnt let me debug the tests :(
}
}
Run Code Online (Sandbox Code Playgroud)
有关MvvmCross的TDD的任何精彩教程都会很棒
有关MvvmCross的TDD的任何精彩教程都会很棒
Greg Shackles在Evolve的演讲是一个很好的起点 - http://xamarin.com/evolve/2013#session-7wb0etd3r8
他的CodeCamp示例包含一组极好的单元测试示例 - http://www.gregshackles.com/2013/09/nyc-code-camp-8-mobile-apps/导致https://github.com/gshackles/ NycCodeCamp8 /树/主/ CodeCamp.Core /测试/ CodeCamp.Core.Tests/ViewModelTests
关于MvvmCross单元测试的教程 - 包括模拟 - 可在N = 29的http://mvvmcross.wordpress.com/上获得.
博客文章也可在http://blog.fire-development.com/2013/06/29/mvvmcross-enable-unit-testing/上找到.
| 归档时间: |
|
| 查看次数: |
1833 次 |
| 最近记录: |