Exemplo n.º 1
0
        public void NoDeltasPlusStartupRecap()
        {
            //Arrange
            var sut           = new RecapsQuery();
            var notifications = new List <NamedRecap>();

            //Act
            sut.Run(
                new ValueOrError <User>(User.Create("u1")), new RunTargets
            {
                FrontendNotifier = new StubIFrontendNotifier
                {
                    RecapStringRecap = (n, r) =>
                    {
                        notifications.Add(new NamedRecap {
                            Name = n, Recap = r
                        });
                    }
                },
                ErrorsInbox = new StubIErrorsInbox
                {
                    GetErrorsStream = () => Observable.Empty <ErrorPayload>()
                },
                ErrorsBacklogReader = new StubIErrorsBacklogReader
                {
                    GetSourcesRecapIEnumerableOfSource = apps => Task.FromResult(new ValueOrError <Recap>(new Recap(DateTime.UtcNow, Enumerable.Empty <Recap.Source>())))
                },
                VisibilityPersistor = new StubIVisibilityPersistor
                {
                    GetUserSourcesString = _ => Task.FromResult((IEnumerable <Source>) new[] { Source.Create("a1", "a1") })
                },
                VisibilityPublisher = new StubIVisibilityPublisher
                {
                    GetClusterSourcesSequence = () => Observable.Empty <Delta <Relationship <Cluster, Source> > >(),
                    GetClusterUsersSequence   = () => Observable.Empty <Delta <Relationship <Cluster, User> > >()
                }
            });

            //Assert
            Assert.Equal(1, notifications.Count());
        }
Exemplo n.º 2
0
        public void OneDeltaEachSourcePlusStartupRecap()
        {
            var scheduler = new TestScheduler();

            //Arrange
            var sut           = new RecapsQuery();
            var notifications = new List <NamedRecap>();

            //Act
            var user    = User.Create("u1");
            var source  = Source.Create("a1", "a1");
            var cluster = Cluster.Create("c1", new[] { user });

            var rca = Relationship.Create(cluster, source);
            var rcu = Relationship.Create(cluster, user);

            var clusterSourcesStream = scheduler.CreateColdObservable(
                Notification.CreateOnNext(Delta.Create(rca, DeltaType.Added)).RecordAt(1)
                );

            var clusterUsersStream = scheduler.CreateColdObservable(
                Notification.CreateOnNext(Delta.Create(rcu, DeltaType.Added)).RecordAt(2)
                );

            var errorsStream = scheduler.CreateColdObservable(
                Notification.CreateOnNext(new ErrorPayload(source.SourceId, new Error(), "e1", "")).RecordAt(5)
                );

            sut.Run(
                new ValueOrError <User>(user), new RunTargets
            {
                FrontendNotifier = new StubIFrontendNotifier
                {
                    RecapStringRecap = (n, r) =>
                    {
                        notifications.Add(new NamedRecap {
                            Name = n, Recap = r
                        });
                    }
                },
                ErrorsInbox = new StubIErrorsInbox
                {
                    GetErrorsStream = () => errorsStream
                },
                ErrorsBacklogReader = new StubIErrorsBacklogReader()
                {
                    GetSourcesRecapIEnumerableOfSource = apps => Task.FromResult(
                        new ValueOrError <Recap>(
                            new Recap(
                                DateTime.UtcNow,
                                Enumerable.Empty <Recap.Source>())))
                },
                VisibilityPersistor = new StubIVisibilityPersistor
                {
                    GetUserSourcesString = _ => Task.FromResult((IEnumerable <Source>) new[] { source })
                },
                VisibilityPublisher = new StubIVisibilityPublisher
                {
                    GetClusterSourcesSequence = () => clusterSourcesStream,
                    GetClusterUsersSequence   = () => clusterUsersStream
                }
            });


            //Asserts

            Assert.Equal(1, notifications.Count()); //first recap is received during the subscription

            scheduler.AdvanceBy(1);
            Assert.Equal(2, notifications.Count()); //1 for initial recap, 1 for adding app, 1 for adding user

            scheduler.AdvanceBy(1);
            Assert.Equal(3, notifications.Count()); //1 for initial recap, 1 for adding app, 1 for adding user

            scheduler.AdvanceBy(1);
        }