namespace IoC.Tests.UsageScenarios { using System; using Moq; using Xunit; public class Observables { [Fact] public void Run() { // $visible=true // $tag=3 BCL types // $priority=01 // $description=Observables // $header=To resolve all possible instances of any tags of the specific type as an _IObservable<>_ instance just use the injection _IObservable_ // { using var container = Container .Create() .Bind().To() // Bind to the implementation #1 .Bind().Tag(1).To() // Bind to the implementation #2 .Bind().Tag(2).Tag("abc").To() // Bind to the implementation #3 .Bind().Tag(3).To() .Container; // Resolve the source for all appropriate instances var instancesSource = container.Resolve>(); // } // Create mock of the observer to check var observer = new Mock>(); using (instancesSource.Subscribe(observer.Object)) { // Check the number of resolved instances observer.Verify(o => o.OnNext(It.IsAny()), Times.Exactly(3)); // Check that the finishing event was received observer.Verify(o => o.OnCompleted(), Times.Once); } } } }