Exemple #1
0
            public async ThreadingTask EmitsANewEventOnTheTimeEntryUpdatedObservable()
            {
                var observer = TestScheduler.CreateObserver <(long Id, IDatabaseTimeEntry Entity)>();

                TimeEntriesSource.TimeEntryUpdated.Subscribe(observer);

                await TimeEntriesSource.Stop(ValidTime);

                observer.Messages.Single().Value.Value.Id.Should().Be(CurrentRunningId);
                observer.Messages.Single().Value.Value.Entity.Stop.Should().Be(ValidTime);
            }
            public async ThreadingTask SetsTheCurrentlyRunningTimeEntryToNull()
            {
                var observer = TestScheduler.CreateObserver <ITimeEntry>();

                TimeEntriesSource.CurrentlyRunningTimeEntry.Subscribe(observer);
                Repository.Update(Arg.Any <long>(), Arg.Any <IDatabaseTimeEntry>()).Returns(callInfo => Observable.Return(callInfo.Arg <IDatabaseTimeEntry>()));

                await TimeEntriesSource.Stop(Now);

                observer.Messages.Single().Value.Value.Should().BeNull();
            }
            public async ThreadingTask EmitsANewEventOnTheTimeEntryUpdatedObservable()
            {
                var observer = TestScheduler.CreateObserver <EntityUpdate <IThreadSafeTimeEntry> >();

                TimeEntriesSource.Updated.Subscribe(observer);

                await TimeEntriesSource.Stop(Now);

                var tuple = observer.Messages.Single().Value.Value;

                tuple.Id.Should().Be(CurrentRunningId);
                tuple.Entity.Duration.Should().Be((long)(Now - tuple.Entity.Start).TotalSeconds);
            }
Exemple #4
0
            public void ThrowsIfThereAreNoRunningTimeEntries()
            {
                var timeEntries = new List <IDatabaseTimeEntry>
                {
                    DatabaseTimeEntry.With(DateTimeOffset.UtcNow),
                    DatabaseTimeEntry.With(DateTimeOffset.UtcNow),
                    DatabaseTimeEntry.With(DateTimeOffset.UtcNow)
                };

                Repository
                .GetAll(Arg.Any <Func <IDatabaseTimeEntry, bool> >())
                .Returns(callInfo =>
                         Observable
                         .Return(timeEntries)
                         .Select(x => x.Where(callInfo.Arg <Func <IDatabaseTimeEntry, bool> >())));

                var observer   = new TestScheduler().CreateObserver <ITimeEntry>();
                var observable = TimeEntriesSource.Stop(ValidTime);

                observable.Subscribe(observer);

                observer.Messages.Single().Value.Exception.Should().BeOfType <InvalidOperationException>();
            }
            public void ThrowsIfThereAreNoRunningTimeEntries()
            {
                long duration    = (long)(Now - TimeEntry.Start).TotalSeconds;
                var  timeEntries = new List <IDatabaseTimeEntry>
                {
                    TimeEntry.With(duration),
                    TimeEntry.With(duration),
                    TimeEntry.With(duration)
                };

                Repository
                .GetAll(Arg.Any <Func <IDatabaseTimeEntry, bool> >())
                .Returns(callInfo =>
                         Observable
                         .Return(timeEntries)
                         .Select(x => x.Where(callInfo.Arg <Func <IDatabaseTimeEntry, bool> >())));

                var observer   = TestScheduler.CreateObserver <ITimeEntry>();
                var observable = TimeEntriesSource.Stop(Now);

                observable.Subscribe(observer);

                observer.Messages.Single().Value.Exception.Should().BeOfType <NoRunningTimeEntryException>();
            }
            public async ThreadingTask UpdatesTheTimeEntryMakingItSyncNeeded()
            {
                await TimeEntriesSource.Stop(Now);

                await Repository.Received().Update(Arg.Any <long>(), Arg.Is <IDatabaseTimeEntry>(te => te.SyncStatus == SyncStatus.SyncNeeded));
            }
 public async ThreadingTask UpdatesTheTimeEntrySettingItsDuration()
 {
     await TimeEntriesSource.Stop(Now); 

     await Repository.Received().Update(Arg.Any <long>(), Arg.Is <IDatabaseTimeEntry>(te => te.Duration == (long)(Now - te.Start).TotalSeconds));
 }
Exemple #8
0
            public async ThreadingTask UpdatesTheTimeEntryMakingItDirty()
            {
                await TimeEntriesSource.Stop(ValidTime);

                await Repository.Received().Update(Arg.Is <IDatabaseTimeEntry>(te => te.IsDirty));
            }
Exemple #9
0
 public async ThreadingTask UpdatesTheTimeEntrySettingItsStopTime()
 {
     await TimeEntriesSource.Stop(ValidTime); 

     await Repository.Received().Update(Arg.Is <IDatabaseTimeEntry>(te => te.Stop == ValidTime)); 

 }