Skip to content

Instantly share code, notes, and snippets.

@molnarm
Created August 19, 2016 07:11
Show Gist options
  • Save molnarm/8e7a0555d7e22e6bbbea23596c73f9d4 to your computer and use it in GitHub Desktop.
Save molnarm/8e7a0555d7e22e6bbbea23596c73f9d4 to your computer and use it in GitHub Desktop.
Sample test for an exception thrown from DynamicData. The test passes but the error is displayed in the output.
using System;
using DynamicData;
using DynamicData.Binding;
using NUnit.Framework;
[TestFixture]
public class DynamicDataTest
{
[Test]
public void TransformToNull()
{
var data = new Data { Id = 1, State = null };
var cache = new SourceCache<Data, int>(d => d.Id);
var items = new ObservableCollectionExtended<string>();
var subscription = cache.Connect()
.Transform(d => d.State)
.Bind(items)
.Subscribe(_ => { }, e => Console.WriteLine($"Error: {e.Message}"));
cache.AddOrUpdate(data);
data.State = "Changed";
cache.AddOrUpdate(data);
subscription.Dispose();
}
private class Data
{
public int Id { get; set; }
public string State { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment