-
-
Save MikeBild/3716031 to your computer and use it in GitHub Desktop.
var sut = Observable.Start(() => | |
{ | |
return "Demo"; | |
}); | |
var testScheduler = new Microsoft.Reactive.Testing.TestScheduler(); | |
var actual = testScheduler.Start(() => sut); | |
Microsoft.Reactive.Testing.ReactiveAssert.AreElementsEqual(actual.Messages, new[] { | |
new Recorded<Notification<string>>(200, Notification.CreateOnNext("Demo")), | |
new Recorded<Notification<string>>(200, Notification.CreateOnCompleted<string>()), | |
}); |
Ich bekomme das Beispiel nicht so richtig umgesetzt. Gegenbeispiel mit MSpec:
public class Journal : IJournal
{
readonly Subject<JournalEntry> _journalEntry = new Subject<JournalEntry>();
public IObservable<JournalEntry> JournalEntries { get { return _journalEntry.AsObservable(); } }
public void AddEntry(JournalEntry entry)
{
_journalEntry.OnNext(entry);
}
}
public class StudioFilesReader : IReadStudioFiles
{
readonly IJournal _journal;
public StudioFilesReader(IJournal journal)
{
_journal = journal;
}
public IObservable<StudioSolution> ReadSolutionFile(string fileName)
{
return Observable.Start(() => ParseSolutionFile(fileInfo));
}
StudioSolution ParseSolutionFile(FileInfo fileInfo)
{
var solution = new StudioSolution();
_journal.AddEntry(new JournalEntry());
return solution;
}
[Subject(typeof (StudioFilesReader))]
internal class When_reading_project : WithFakes
{
Establish context = () =>
{
_journalEntries = new List<JournalEntry>();
_journal = new Journal();
_subject = new StudioFilesReader(_journal);
};
Because of = () =>
{
using (_journal.JournalEntries.Subscribe(x => _journalEntries.Add(x)))
{
_project = _subject.ReadProjectFile(FileName).First();
}
It should_add_projects_visit_to_journal = () =>
_journalEntries.ShouldContain(...);
};
Hier gehts nur mit .First(), oder?
Ich bin mir nicht ganz sicher, was Du eigentlich testen wolltest. Ich hab das jetzt mal, ohne eigenen verifizierten Lauf, mal zusammen kopiert. Vielleicht kannst Du das auch nochmal per Spec beschreiben?!?
Establish context = () => { var testScheduler = new Microsoft.Reactive.Testing.TestScheduler(); _sut_journal = new Journal(); _sut_subject = new StudioFilesReader(_sut_journal); }; Because of = () => { _actual = testScheduler.Start(() => _sut_subject.ReadProjectFile(FileName)); //Hier ist Deinem Beispiel dann ReadSolutionFile gemeint oder? } It should_add_projects_visit_to_journal = () => Microsoft.Reactive.Testing.ReactiveAssert.AreElementsEqual(actual.Messages, new[] { new Recorded<Notification<StudioSolution>>(200, Notification.CreateOnNext(new StudioSolution() { ... })), new Recorded<Notification<StudioSolution>>(200, Notification.CreateOnCompleted<StudioSolution>()), }); }; It should_contains_a_journal_entry = () => Microsoft.Reactive.Testing.ReactiveAssert.AreElementsEqual(_sut_journal.Messages, new[] { new Recorded<Notification<JournalEntry>>(200, Notification.CreateOnNext(new JournalEntry() { ... })), new Recorded<Notification<JournalEntry>>(200, Notification.CreateOnCompleted<JournalEntry>()), }); };
Ich freue mich schon auf den Workshop beim netos ;)