public async ThreadingTask EmitsObservableEventsForTheNewRunningTimeEntryAndTheStoppedTimeEntry()
            {
                var durationAfterStopping = 100;
                var updatedObserver       = TestScheduler.CreateObserver <EntityUpdate <IThreadSafeTimeEntry> >();
                var createdObserver       = TestScheduler.CreateObserver <IThreadSafeTimeEntry>();
                var runningTimeEntry      = new MockTimeEntry {
                    Id = 1, Duration = null
                };
                var newTimeEntry = new MockTimeEntry {
                    Id = -2, Duration = null
                };

                Repository.GetAll(Arg.Any <Func <IDatabaseTimeEntry, bool> >())
                .Returns(Observable.Return(new IDatabaseTimeEntry[] { runningTimeEntry }));
                Repository.BatchUpdate(
                    Arg.Any <IEnumerable <(long, IDatabaseTimeEntry)> >(),
                    Arg.Any <Func <IDatabaseTimeEntry, IDatabaseTimeEntry, ConflictResolutionMode> >(),
                    Arg.Any <IRivalsResolver <IDatabaseTimeEntry> >())
                .Returns(Observable.Return(new IConflictResolutionResult <IDatabaseTimeEntry>[]
                {
                    new UpdateResult <IDatabaseTimeEntry>(runningTimeEntry.Id, runningTimeEntry.With(durationAfterStopping)),
                    new CreateResult <IDatabaseTimeEntry>(newTimeEntry)
                }));

                var timeEntriesSource = new TimeEntriesDataSource(Repository, TimeService);

                timeEntriesSource.Updated.Subscribe(updatedObserver);
                timeEntriesSource.Created.Subscribe(createdObserver);
                await timeEntriesSource.Create(newTimeEntry);

                updatedObserver.Messages.Single().Value.Value.Entity.Duration.Should().Be(durationAfterStopping);
                createdObserver.Messages.Single().Value.Value.Id.Should().Be(newTimeEntry.Id);
                createdObserver.Messages.Single().Value.Value.Duration.Should().BeNull();
            }
Exemplo n.º 2
0
            public TimeEntryDataSourceTest()
            {
                TimeEntriesSource = new TimeEntriesDataSource(IdProvider, Repository);

                IdProvider.GetNextIdentifier().Returns(-1);
                Repository.GetById(Arg.Is(DatabaseTimeEntry.Id)).Returns(Observable.Return(DatabaseTimeEntry));
                Repository.Create(Arg.Any <IDatabaseTimeEntry>())
                .Returns(info => Observable.Return(info.Arg <IDatabaseTimeEntry>()));
            }
            protected TimeEntryDataSourceTest()
            {
                TimeEntriesSource = new TimeEntriesDataSource(Repository, TimeService);

                IdProvider.GetNextIdentifier().Returns(-1);
                Repository.GetById(Arg.Is(TimeEntry.Id)).Returns(Observable.Return(TimeEntry));

                Repository.Create(Arg.Any <IDatabaseTimeEntry>())
                .Returns(info => Observable.Return(info.Arg <IDatabaseTimeEntry>()));

                Repository.Update(Arg.Any <long>(), Arg.Any <IDatabaseTimeEntry>())
                .Returns(info => Observable.Return(info.Arg <IDatabaseTimeEntry>()));
            }
Exemplo n.º 4
0
            public async ThreadingTask EmitsObservableEventsForTheNewlyCreatedRunningTimeEntry()
            {
                var itemsChangedObserver = TestScheduler.CreateObserver <Unit>();
                var newTimeEntry         = new MockTimeEntry {
                    Id = -1, Duration = null
                };

                Repository.BatchUpdate(
                    Arg.Any <IEnumerable <(long, IDatabaseTimeEntry)> >(),
                    Arg.Any <Func <IDatabaseTimeEntry, IDatabaseTimeEntry, ConflictResolutionMode> >(),
                    Arg.Any <IRivalsResolver <IDatabaseTimeEntry> >())
                .Returns(Observable.Return(new IConflictResolutionResult <IDatabaseTimeEntry>[]
                {
                    new CreateResult <IDatabaseTimeEntry>(newTimeEntry)
                }));

                var timeEntriesSource = new TimeEntriesDataSource(Repository, TimeService, AnalyticsService);

                timeEntriesSource.ItemsChanged.Subscribe(itemsChangedObserver);
                await timeEntriesSource.Create(newTimeEntry);

                itemsChangedObserver.SingleEmittedValue().Should().Be(Unit.Default);
            }
            public async ThreadingTask EmitsObservableEventsForTheNewlyCreatedRunningTimeEntry()
            {
                var createdObserver = TestScheduler.CreateObserver <IThreadSafeTimeEntry>();
                var newTimeEntry    = new MockTimeEntry {
                    Id = -1, Duration = null
                };

                Repository.BatchUpdate(
                    Arg.Any <IEnumerable <(long, IDatabaseTimeEntry)> >(),
                    Arg.Any <Func <IDatabaseTimeEntry, IDatabaseTimeEntry, ConflictResolutionMode> >(),
                    Arg.Any <IRivalsResolver <IDatabaseTimeEntry> >())
                .Returns(Observable.Return(new IConflictResolutionResult <IDatabaseTimeEntry>[]
                {
                    new CreateResult <IDatabaseTimeEntry>(newTimeEntry)
                }));

                var timeEntriesSource = new TimeEntriesDataSource(Repository, TimeService);

                timeEntriesSource.Created.Subscribe(createdObserver);
                await timeEntriesSource.Create(newTimeEntry);

                createdObserver.Messages.Single().Value.Value.Id.Should().Be(newTimeEntry.Id);
                createdObserver.Messages.Single().Value.Value.Duration.Should().BeNull();
            }
Exemplo n.º 6
0
 public UserDataSourceTest()
 {
     TimeEntriesSource = new TimeEntriesDataSource(Repository);
     Repository.Create(Arg.Any <IDatabaseTimeEntry>())
     .Returns(info => Observable.Return(info.Arg <IDatabaseTimeEntry>()));
 }