Exemplo n.º 1
0
            protected TimeEntryDataSourceObservableTest()
            {
                var startTime = now.AddHours(-2);

                var observable = Enumerable.Range(1, InitialAmountOfTimeEntries)
                                 .Select(i =>
                                         new MockTimeEntry {
                    Id          = i,
                    Start       = startTime.AddHours(i * 2),
                    Duration    = (long)TimeSpan.FromHours(i * 2 + 2).TotalSeconds,
                    UserId      = 11,
                    WorkspaceId = 12,
                    Description = "",
                    At          = now,
                    TagIds      = new long[] { 1, 2, 3 },
                    Workspace   = new MockWorkspace {
                        IsInaccessible = false
                    }
                }
                                         )
                                 .Apply(Observable.Return);

                InteractorFactory.GetAllTimeEntriesVisibleToTheUser().Execute().Returns(observable);
                DataSource.TimeEntries.Created.Returns(TimeEntryCreatedSubject.AsObservable());
                DataSource.TimeEntries.Updated.Returns(TimeEntryUpdatedSubject.AsObservable());
                DataSource.TimeEntries.Deleted.Returns(TimeEntryDeletedSubject.AsObservable());
            }
Exemplo n.º 2
0
            private Gen <TimeEntriesViewModel> generatorForTimeEntriesViewModel(Func <int, bool> filter)
            {
                var now             = new DateTimeOffset(2017, 08, 13, 08, 01, 23, TimeSpan.Zero);
                var monthsGenerator = Gen.Choose(1, 12).Where(filter);
                var yearGenerator   = Gen.Choose(2007, now.Year);

                return(Arb.Default
                       .Array <DateTimeOffset>()
                       .Generator
                       .Select(dateTimes =>
                {
                    var viewModel = CreateViewModel();
                    var year = yearGenerator.Sample(0, 1).First();

                    var observable = dateTimes
                                     .Select(newDateWithGenerator(monthsGenerator, year))
                                     .Select(d => TimeEntry.Builder
                                             .Create(-1)
                                             .SetUserId(-2)
                                             .SetWorkspaceId(-3)
                                             .SetStart(d)
                                             .SetDescription("")
                                             .SetAt(now).Build())
                                     .Apply(Observable.Return);

                    InteractorFactory.GetAllTimeEntriesVisibleToTheUser().Execute().Returns(observable);

                    return viewModel;
                }));
            }
            public async ThreadingTask NeverReturnsDeletedTimeEntries()
            {
                var result = Enumerable
                             .Range(0, 20)
                             .Select(i =>
                {
                    var isDeleted = i % 2 == 0;
                    var timeEntry = Substitute.For <IThreadSafeTimeEntry>();
                    timeEntry.Id.Returns(i);
                    timeEntry.IsDeleted.Returns(isDeleted);
                    return(timeEntry);
                });

                DataSource
                .TimeEntries
                .GetAll(Arg.Any <Func <IDatabaseTimeEntry, bool> >(), true)
                .Returns(callInfo =>
                         Observable
                         .Return(result)
                         .Select(x => x.Where(callInfo.Arg <Func <IThreadSafeTimeEntry, bool> >())));

                var timeEntries = await InteractorFactory.GetAllTimeEntriesVisibleToTheUser().Execute()
                                  .Select(tes => tes.Where(x => x.Id > 10));

                timeEntries.Should().HaveCount(5);
            }
            public void ThrowsIfDataSourceThrows()
            {
                DataSource.TimeEntries.GetAll(Arg.Any <Func <IDatabaseTimeEntry, bool> >(), true)
                .Returns(Observable.Throw <IEnumerable <IThreadSafeTimeEntry> >(new Exception()));

                Action tryGetAll = () => InteractorFactory.GetAllTimeEntriesVisibleToTheUser().Execute().Wait();

                tryGetAll.Should().Throw <Exception>();
            }
            public async Task RemovesAllDeletedTimeEntries()
            {
                DataSource.TimeEntries.GetAll(Arg.Any <Func <IDatabaseTimeEntry, bool> >(), true)
                .Returns(callInfo => Observable.Return(timeEntries.Where <IThreadSafeTimeEntry>(
                                                           callInfo.Arg <Func <IDatabaseTimeEntry, bool> >())));

                var finteredTimeEntries = await InteractorFactory.GetAllTimeEntriesVisibleToTheUser().Execute();

                finteredTimeEntries.Should().HaveCount(5);
                finteredTimeEntries.Select(te => te.IsDeleted).Should().BeEquivalentTo(new[] { false, false, false, false, false });
            }
Exemplo n.º 6
0
            public async ThreadingTask RemovesTheTimeEntryIfItWasNotRemovedPreviously()
            {
                await ViewModel.Initialize();

                var timeEntryCollection = await InteractorFactory.GetAllTimeEntriesVisibleToTheUser().Execute().FirstAsync();

                var timeEntryToDelete = timeEntryCollection.First();

                TimeEntryDeletedSubject.OnNext(timeEntryToDelete.Id);

                ViewModel.TimeEntries.All(c => c.All(te => te.Id != timeEntryToDelete.Id)).Should().BeTrue();
                ViewModel.TimeEntries.Aggregate(0, (acc, te) => acc + te.Count).Should().Be(InitialAmountOfTimeEntries - 1);
            }
Exemplo n.º 7
0
            protected void PrepareTimeEntry()
            {
                var timeEntry = Substitute.For <IThreadSafeTimeEntry>();

                timeEntry.Id.Returns(123);
                timeEntry.Start.Returns(DateTimeOffset.Now);
                timeEntry.Duration.Returns(100);
                InteractorFactory.GetAllTimeEntriesVisibleToTheUser().Execute()
                .Returns(Observable.Return(new[] { timeEntry }));
                DataSource
                .TimeEntries
                .Updated
                .Returns(Observable.Never <EntityUpdate <IThreadSafeTimeEntry> >());
            }