Пример #1
0
        public void ThrowsWhenRepositoryThrows()
        {
            var state = new PushState <IDatabaseTestModel, IThreadSafeTestModel>(dataSource);

            dataSource.GetAll(Arg.Any <Func <IDatabaseTestModel, bool> >())
            .Returns(Observable.Throw <IEnumerable <IThreadSafeTestModel> >(new Exception()));

            Action callingStart = () => state.Start().SingleAsync().Wait();

            callingStart.Should().Throw <Exception>();
        }
Пример #2
0
        public void ReturnsNothingToPushTransitionWhenTheRepositoryReturnsNoEntity()
        {
            var state = new PushState <IDatabaseTestModel, IThreadSafeTestModel>(dataSource);

            dataSource.GetAll(Arg.Any <Func <IDatabaseTestModel, bool> >())
            .Returns(Observable.Return(new IThreadSafeTestModel[0]));

            var transition = state.Start().SingleAsync().Wait();

            transition.Result.Should().Be(state.NothingToPush);
        }
Пример #3
0
        public void ReturnsPushEntityTransitionWhenTheRepositoryReturnsSomeEntity()
        {
            var state  = new PushState <IDatabaseTestModel, IThreadSafeTestModel>(dataSource);
            var entity = new TestModel(1, SyncStatus.SyncNeeded);

            dataSource.GetAll(Arg.Any <Func <IDatabaseTestModel, bool> >())
            .Returns(Observable.Return(new[] { entity }));

            var transition = state.Start().SingleAsync().Wait();
            var parameter  = ((Transition <IThreadSafeTestModel>)transition).Parameter;

            transition.Result.Should().Be(state.PushEntity);
            parameter.Should().BeEquivalentTo(entity, options => options.IncludingProperties());
        }
Пример #4
0
        public void ReturnsPushEntityTransitionWithTheOldestEntity()
        {
            var at     = new DateTimeOffset(2017, 9, 1, 12, 34, 56, TimeSpan.Zero);
            var state  = new PushState <IDatabaseTestModel, IThreadSafeTestModel>(dataSource);
            var entity = new TestModel {
                At = at, SyncStatus = SyncStatus.SyncNeeded
            };
            var entity2 = new TestModel {
                At = at.AddDays(-2), SyncStatus = SyncStatus.SyncNeeded
            };
            var entity3 = new TestModel {
                At = at.AddDays(-1), SyncStatus = SyncStatus.SyncNeeded
            };

            dataSource.GetAll(Arg.Any <Func <IDatabaseTestModel, bool> >())
            .Returns(Observable.Return(new[] { entity, entity2, entity3 }));

            var transition = state.Start().SingleAsync().Wait();
            var parameter  = ((Transition <IThreadSafeTestModel>)transition).Parameter;

            transition.Result.Should().Be(state.PushEntity);
            parameter.Should().BeEquivalentTo(entity2, options => options.IncludingProperties());
        }