Exemplo n.º 1
0
            protected CalendarViewModelTest()
            {
                CalendarInteractor = Substitute.For <IInteractor <IObservable <IEnumerable <CalendarItem> > > >();

                var workspace = new MockWorkspace {
                    Id = DefaultWorkspaceId
                };
                var timeEntry = new MockTimeEntry {
                    Id = TimeEntryId
                };

                TimeService.CurrentDateTime.Returns(Now);

                InteractorFactory
                .GetCalendarItemsForDate(Arg.Any <DateTime>())
                .Returns(CalendarInteractor);

                InteractorFactory
                .GetDefaultWorkspace()
                .Execute()
                .Returns(Observable.Return(workspace));

                InteractorFactory
                .CreateTimeEntry(Arg.Any <ITimeEntryPrototype>())
                .Execute()
                .Returns(Observable.Return(timeEntry));

                InteractorFactory
                .UpdateTimeEntry(Arg.Any <EditTimeEntryDto>())
                .Execute()
                .Returns(Observable.Return(timeEntry));
            }
            public async ThreadingTask RemovesCurrentlyRunningTimeEntryWhenItIsDeleted()
            {
                DataSource.TimeEntries.Returns(TimeEntriesSource);
                var runningTimeEntriesHistory = new List <IThreadSafeTimeEntry>();
                var user = Substitute.For <IThreadSafeUser>();

                user.Id.Returns(10);
                DataSource.User.Current.Returns(Observable.Return(user));
                TimeEntriesSource.CurrentlyRunningTimeEntry
                .Subscribe(te => runningTimeEntriesHistory.Add(te));
                var prototype = new MockTimeEntryPrototype
                {
                    WorkspaceId = WorkspaceId,
                    StartTime   = Now,
                    Description = "Some description",
                    IsBillable  = true,
                    ProjectId   = ProjectId
                };

                prepareBatchUpdate();
                var timeEntry = Models.TimeEntry.From(await InteractorFactory.CreateTimeEntry(prototype).Execute());

                Repository.Update(Arg.Is(timeEntry.Id), Arg.Is(timeEntry)).Returns(Observable.Return(timeEntry));

                TimeEntriesSource.SoftDelete(timeEntry).Wait();

                runningTimeEntriesHistory.Should().HaveCount(3);
                runningTimeEntriesHistory[0].Should().Be(null); // originally there is no running time entry (in the repository)
                runningTimeEntriesHistory[1].Id.Should().Be(timeEntry.Id);
                runningTimeEntriesHistory[2].Should().Be(null);
            }
Exemplo n.º 3
0
            public async Task CreatesATimeEntryUsingTheCalendarItemInfo()
            {
                ViewModel.Init(eventId);

                await InteractorFactory
                .CreateTimeEntry(Arg.Is <ITimeEntryPrototype>(p => p.Description == calendarItem.Description))
                .Received()
                .Execute();
            }
Exemplo n.º 4
0
            public async Task CreatesATimeEntryInTheDefaultWorkspace()
            {
                ViewModel.Init(eventId);

                await InteractorFactory
                .CreateTimeEntry(Arg.Is <ITimeEntryPrototype>(p => p.WorkspaceId == DefaultWorkspaceId))
                .Received()
                .Execute();
            }
                public async Task CreatesATimeEntryInTheDefaultWorkspace()
                {
                    await ViewModel.OnItemTapped.Execute(CalendarItem);

                    await InteractorFactory
                    .CreateTimeEntry(Arg.Is <ITimeEntryPrototype>(p => p.WorkspaceId == DefaultWorkspaceId))
                    .Received()
                    .Execute();
                }
                public async Task CreatesATimeEntryUsingTheCalendarItemInfo()
                {
                    await ViewModel.OnItemTapped.Execute(CalendarItem);

                    await InteractorFactory
                    .CreateTimeEntry(Arg.Is <ITimeEntryPrototype>(p => p.Description == CalendarItem.Description))
                    .Received()
                    .Execute();
                }
Exemplo n.º 7
0
            public async Task CreatesATimeEntryInTheDefaultWorkspace()
            {
                ViewModel.OnItemTapped.Execute(CalendarItem);
                TestScheduler.Start();

                await InteractorFactory
                .CreateTimeEntry(Arg.Is <ITimeEntryPrototype>(p => p.WorkspaceId == DefaultWorkspaceId), TimeEntryStartOrigin.CalendarEvent)
                .Received()
                .Execute();
            }
Exemplo n.º 8
0
            public async Task CreatesATimeEntryUsingTheCalendarItemInfo()
            {
                ViewModel.OnItemTapped.Execute(CalendarItem);
                TestScheduler.Start();

                await InteractorFactory
                .CreateTimeEntry(Arg.Is <ITimeEntryPrototype>(p => p.Description == CalendarItem.Description), TimeEntryStartOrigin.CalendarEvent)
                .Received()
                .Execute();
            }
            public async Task CreatesATimeEntryInTheDefaultWorkspace()
            {
                var now      = DateTimeOffset.UtcNow;
                var duration = TimeSpan.FromMinutes(30);
                var tuple    = (now, duration);

                await ViewModel.OnDurationSelected.Execute(tuple);

                await InteractorFactory
                .CreateTimeEntry(Arg.Is <ITimeEntryPrototype>(p => p.WorkspaceId == DefaultWorkspaceId))
                .Received()
                .Execute();
            }
            public async Task CreatesATimeEntryWithTheSelectedStartDate()
            {
                var now      = DateTimeOffset.UtcNow;
                var duration = TimeSpan.FromMinutes(30);
                var tuple    = (now, duration);

                await ViewModel.OnDurationSelected.Execute(tuple);

                await InteractorFactory
                .CreateTimeEntry(Arg.Is <ITimeEntryPrototype>(p => p.StartTime == now))
                .Received()
                .Execute();
            }
Exemplo n.º 11
0
            public async Task CreatesATimeEntryWithTheSelectedDuration()
            {
                var now      = DateTimeOffset.UtcNow;
                var duration = TimeSpan.FromMinutes(30);
                var tuple    = (now, duration);

                ViewModel.OnDurationSelected.Execute(tuple);
                TestScheduler.Start();

                await InteractorFactory
                .CreateTimeEntry(Arg.Is <ITimeEntryPrototype>(p => p.Duration == duration), TimeEntryStartOrigin.CalendarTapAndDrag)
                .Received()
                .Execute();
            }
Exemplo n.º 12
0
 protected override IObservable <IDatabaseTimeEntry> CallInteractor(ITimeEntryPrototype prototype)
 => InteractorFactory.CreateTimeEntry(prototype).Execute();
Exemplo n.º 13
0
 protected override IObservable <IDatabaseTimeEntry> CallInteractor(ITimeEntryPrototype prototype)
 => InteractorFactory.CreateTimeEntry(prototype, prototype.Duration.HasValue ? TimeEntryStartOrigin.Manual : TimeEntryStartOrigin.Timer).Execute();