{ "userName" : "requested user name", "karma" : 123, "lastModified" : "2014-09-01" }
public sealed class NonReactiveHabraClient { private IHttpClient HttpClient { get; set; } public NonReactiveHabraClient(IHttpClient httpClient) { HttpClient = httpClient; } public async Task<KarmaModel> GetKarmaForUser(string userName) { var karmaResponse = await HttpClient.Get(userName); if (!karmaResponse.IsSuccessful) { throw karmaResponse.Exception; } return karmaResponse.Data; } }
public interface ICache { bool HasCached(string userName); KarmaModel GetCachedItem(string userName); void Put(KarmaModel updatedKarma); }
Install-Package Rx-Main
public interface IHttpClient { Task<KarmaResponse> Get(string userName); } public class KarmaResponse { public bool IsSuccessful { get; set; } public KarmaModel Data { get; set; } public Exception Exception { get; set; } } public class KarmaModel { public string UserName { get; set; } public int Karma { get; set; } public DateTime LastModified { get; set; } }
public interface IHabraClient { IObservable<KarmaModel> GetKarmaForUser(string userName); }
public sealed class ReactiveHabraClient : IHabraClient { private ICache Cache { get; set; } private IHttpClient HttpClient { get; set; } private IScheduler Scheduler { get; set; } public ReactiveHabraClient(ICache cache, IHttpClient httpClient, IScheduler scheduler) { Cache = cache; HttpClient = httpClient; Scheduler = scheduler; } public IObservable<KarmaModel> GetKarmaForUser(string userName) { return Observable.Create<KarmaModel>(observer => Scheduler.Schedule(async () => { KarmaModel karma = null; if (Cache.HasCached(userName)) { karma = Cache.GetCachedItem(userName); observer.OnNext(karma); } var karmaResponse = await HttpClient.Get(userName); if (!karmaResponse.IsSuccessful) { observer.OnError(karmaResponse.Exception); return; } var updatedKarma = karmaResponse.Data; Cache.Put(updatedKarma); if (karma == null || updatedKarma.LastModified > karma.LastModified) { observer.OnNext(updatedKarma); } observer.OnCompleted(); })); } }
Observable
object, which immediately returns the cached data (if any) and then quietly asynchronously requests the updated values. If the data is updated (the LastModified
field has changed) we notify the subscribers again, save the data to the cache and end the sequence. public class MainViewModel { private IHabraClient HabraClient { get; set; } public MainViewModel(IHabraClient habraClient, string userName) { HabraClient = habraClient; Initialize(userName); } private void Initialize(string userName) { IsLoading = true; HabraClient.GetKarmaForUser(userName) .Subscribe(onNext: HandleData, onError: HandleException, onCompleted: () => IsLoading = false); } private void HandleException(Exception exception) { ErrorMessage = exception.Message; IsLoading = false; } private void HandleData(KarmaModel data) { Karma = data.Karma; } public bool IsLoading { get; set; } public int? Karma { get; set; } public string ErrorMessage { get; set; } }
OnNext
, OnError
and OnCompleted
are not executed in the UI stream). Imagine that your favorite MVVM framework took over these tasks. Install-Package Rx-Main Install-Package Rx-Testing Install-Package NUnit Install-Package Moq
ReactiveHabraClientTest
class inherited from ReactiveTest .ReactiveTest
is the base class that comes with the Rx-Testing package. It defines several methods that will be useful to us when writing tests.OnNext
and OnCompleted
.IHttpClient
, ICache
. We also need the TestScheduler class from the Rx-Test package.TestScheduler
implements the IScheduler interface and can be substituted for the platform-specific implementation of the scheduler. The class allows us to literally manage time and execute the asynchronous code step by step. For those who wish, I highly recommend the excellent article Testing Rx Queries using Virtual Time Scheduling . [SetUp] public void SetUp() { Model = new KarmaModel {Karma = 10, LastModified = new DateTime(2014, 09, 10, 1, 1, 1, 0), UserName = USER_NAME}; Cache = new Mock<ICache>(); Scheduler = new TestScheduler(); HttpClient = new Mock<IHttpClient>(); }
Cache.Setup(c => c.HasCached(It.IsAny<string>())).Returns(false); HttpClient.Setup(http => http.Get(USER_NAME)).ReturnsAsync(new KarmaResponse { Data = Model, IsSuccessful = true }); var client = new ReactiveHabraClient(Cache.Object, HttpClient.Object, Scheduler);
var expected = Scheduler.CreateHotObservable(OnNext(2, Model), OnCompleted<KarmaModel>(2));
OnNext(2, Model)
method is a method defined in ReactiveTest
. public static Recorded<Notification<T>> OnNext<T>(long ticks, T value)
TestScheduler
. Not a very beautiful solution, but quite understandable. In the “tick” number zero we create TestScheduler
, in the “tick” number one we subscribe to events, and in the “tick” number two the sequence of messages should go. var results = Scheduler.Start(() => client.GetKarmaForUser(USER_NAME), 0, 1, 10);
TestScheduler
, which creates a zero tick, and subscribes to client.GetKarmaForUser(USER_NAME)
in the first "tick". The last parameter is a “tick” on which Dispose will be called, but in this case this value is not important to us. ReactiveAssert.AreElementsEqual(expected.Messages, results.Messages); Cache.Verify(cache => cache.Put(Model), Times.Once);
MainViewModel
will be slightly different.IHabraClient
and declare a KarmaStream
type Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Subject:
[SetUp] public void SetUp() { Client = new Mock<IHabraClient>(); KarmaStream = new Subject<KarmaModel>(); }
Subject<T> IObservable
IObserver
. KarmaStream
GetKarmaForUser
OnNext
, OnCompleted
OnError
. "" c TestScheduler
.
:
[Test] public void KarmaValueSetToPropertyWhenOnNextCalled() { Client.Setup(client => client.GetKarmaForUser(USER_NAME)).Returns(KarmaStream); var viewModel = new MainViewModel(Client.Object, USER_NAME); KarmaStream.OnNext(new KarmaModel {Karma = 10}); Assert.AreEqual(10, viewModel.Karma); }
, GitHub .
Windows Phone, .Net 4.5. , WP SDK . , Class Library WP8 . , Rx PCL-.
. . , Windows Phone.
.
:
http://reactivex.io/ The Reactive Extensions (Rx)... EN " " RU Read-Through, Write-Through, Write-Behind, and Refresh-Ahead Caching EN Cache-Aside Pattern EN Testing Rx EN Testing Rx Queries using Virtual Time Scheduling EN Testing and Debugging Observable Sequences EN UDP C# Reactive Extensions RU https://www.websequencediagrams.com/
Source: https://habr.com/ru/post/237559/
All Articles