예제 #1
0
        public void ClearRemovesAllDays()
        {
            DateTime dateTime1 = new DateTime(2015, 7, 28, 9, 58, 0);
            DateTime dateTime2 = new DateTime(2014, 1, 22, 23, 19, 0);

            msdyn_timeentry timeEntry1 = new msdyn_timeentry();

            timeEntry1.msdyn_timeentryId = new Guid();
            timeEntry1.msdyn_description = "entry 1";
            timeEntry1.msdyn_date        = dateTime1;
            timeEntry1.msdyn_duration    = 2;

            msdyn_timeentry timeEntry2 = new msdyn_timeentry();

            timeEntry2.msdyn_timeentryId = new Guid();
            timeEntry2.msdyn_description = "entry 2";
            timeEntry2.msdyn_date        = dateTime2;
            timeEntry2.msdyn_duration    = 2;

            TimeCollectionViewModel viewModel = new TimeCollectionViewModel();

            viewModel.AddTimeEntries(new msdyn_timeentry[] { timeEntry1, timeEntry2 });

            viewModel.ClearTimes();
            Assert.AreEqual(0, viewModel.Days.Count);
        }
예제 #2
0
        public async Tasks.Task ChangingFilterRefreshesList()
        {
            DataAccessTestable dataAccessTestable = new DataAccessTestable();

            TimeCollectionViewModel viewModel = new TimeCollectionViewModel();

            viewModel.DataAccess = dataAccessTestable;

            // Load
            await viewModel.LoadTimes();

            // Subscribe to update
            bool retrieved = false;

            dataAccessTestable.addRetrieveEntitiesHandler((q, e, b) =>
            {
                retrieved = true;
            });

            // change filter
            await viewModel.IncrementDateFilter();

            // Verify updated
            Assert.IsTrue(retrieved);
        }
예제 #3
0
        public void LoadTimesFromMultipleDays()
        {
            DateTime dateTime1 = new DateTime(2015, 7, 28, 9, 58, 0);
            DateTime dateTime2 = new DateTime(2014, 1, 22, 23, 19, 0);

            msdyn_timeentry timeEntry1 = new msdyn_timeentry();

            timeEntry1.msdyn_timeentryId = new Guid();
            timeEntry1.msdyn_description = "entry 1";
            timeEntry1.msdyn_date        = dateTime1;
            timeEntry1.msdyn_duration    = 2;

            msdyn_timeentry timeEntry2 = new msdyn_timeentry();

            timeEntry2.msdyn_timeentryId = new Guid();
            timeEntry2.msdyn_description = "entry 2";
            timeEntry2.msdyn_date        = dateTime2;
            timeEntry2.msdyn_duration    = 2;

            TimeCollectionViewModel viewModel = new TimeCollectionViewModel();

            viewModel.AddTimeEntries(new msdyn_timeentry[] { timeEntry1, timeEntry2 });

            // Validate
            IEnumerable <TimeCollection> days = viewModel.Days;

            Assert.AreEqual(2, days.Count(), "Incorrect number of days");
        }
예제 #4
0
        public void TimeEntryDurationValidationTest()
        {
            // Prepare the time entries for test purposes.
            DateTime dateTime = DateTime.Today;

            msdyn_timeentry timeEntry1 = new msdyn_timeentry();

            timeEntry1.msdyn_timeentryId = new Guid();
            timeEntry1.msdyn_description = "entry 1";
            timeEntry1.msdyn_date        = dateTime;
            timeEntry1.msdyn_duration    = 20 * 60; // 20 hours.

            msdyn_timeentry timeEntry2 = new msdyn_timeentry();

            timeEntry2.msdyn_timeentryId = new Guid();
            timeEntry2.msdyn_description = "entry 2";
            timeEntry2.msdyn_date        = dateTime;
            timeEntry2.msdyn_duration    = 4 * 60 + 1; // 4 hours and 1 minute.

            TimeViewModel           entry     = new TimeViewModel(timeEntry1);
            TimeCollectionViewModel viewModel = new TimeCollectionViewModel();

            viewModel.AddTimeEntries(new msdyn_timeentry[] { timeEntry1, timeEntry2 });

            Assert.IsFalse(entry.CanTimeBeSaved(timeEntry1), "The time entry should not be able to save since the total duration is 24:01");

            timeEntry1.msdyn_duration = 19 * 60 + 59;    // 19 hours and 59 minutes.
            Assert.IsTrue(entry.CanTimeBeSaved(timeEntry1), "The time entry should be able to save since the total duration is 24:00");
        }
예제 #5
0
        public async Tasks.Task HasItemsFalseWhenNoEntriesExist()
        {
            TimeCollectionViewModel vm = new TimeCollectionViewModel();

            vm.DataAccess = new DataAccessTestable();

            // DataAccessTestable gives back an empty list of entities by default, no need to add any overrides here.
            await vm.LoadTimes();

            Assert.IsFalse(vm.HasItems);
        }
예제 #6
0
        public void CreateTimeCollectionViewModel()
        {
            TimeCollectionViewModel viewModel = new TimeCollectionViewModel();

            Assert.IsNotNull(viewModel);

            // initial values
            Assert.AreEqual("My Time", viewModel.Title, "Incorrect value for title.");

            // viewModel has never been updated.
            Assert.AreEqual(DateTime.MinValue, viewModel.LastUpdatedDateTime);
        }
예제 #7
0
        public async Tasks.Task DefaultDateFromCurrentFilter()
        {
            msdyn_timeentry timeEntry = new msdyn_timeentry();
            // Today - the day of the week (gives sunday) + 7 = Sunday next week.
            DateTime expectedDate = DateTime.Today - TimeSpan.FromDays((int)DateTime.Today.DayOfWeek) + TimeSpan.FromDays(7);

            // Act.
            TimeCollectionViewModel viewModel = new TimeCollectionViewModel();

            viewModel.DataAccess = new DataAccessTestable();
            await viewModel.IncrementDateFilter();

            // Assert.
            viewModel.DefaultDateFromCurrentFilter(timeEntry);
        }
예제 #8
0
        public TimeTabbedPage(TimeCollectionViewModel viewModel) : base()
        {
            this.viewModel = viewModel;

            // Main layout
            StackLayout mainLayout = new StackLayout();

            mainLayout.Spacing           = 0;
            mainLayout.VerticalOptions   = LayoutOptions.FillAndExpand;
            mainLayout.HorizontalOptions = LayoutOptions.FillAndExpand;

            // Title only on windows phone. There is a title added for the other platforms.
            Device.OnPlatform(WinPhone: () =>
            {
                Label header = new Label();
                header.SetBinding(Label.TextProperty, "Title");
                header.BackgroundColor = TimeApp.PAGE_HEADER_COLOR;
                header.Style           = (Style)Application.Current.Resources["Label_PageHeader"];

                mainLayout.Children.Add(header);
            });

            // Period switcher
            periodSwitcher = new TimePeriodSwitcher(this.viewModel);

            // List view
            this.initializeListView();

            // No items found label
            noItemsLabel = new Label
            {
                Text = AppResources.NoEntries,
                HorizontalOptions = LayoutOptions.Center,
                IsVisible         = false,
                HeightRequest     = 50
            };

            mainLayout.Children.Add(periodSwitcher);
            mainLayout.Children.Add(noItemsLabel);
            mainLayout.Children.Add(listView);

            this.Content = mainLayout;

            // We only update the visibility bindings once the first load completes
            this.viewModel.LoadTimesCompleted += this.ViewModel_LoadTimesCompleted;
        }
        public TimePeriodSwitcher(TimeCollectionViewModel parentViewModel) : base()
        {
            viewModel = parentViewModel;

            Orientation       = StackOrientation.Horizontal;
            BackgroundColor   = Color.FromHex("f8f8f8");
            HeightRequest     = Device.OnPlatform <int>(50, 50, 70);
            HorizontalOptions = LayoutOptions.FillAndExpand;

            rightButton = new Button
            {
                Text              = LabelHandler.GREATERTHAN_SYMBOL,
                Font              = Font.SystemFontOfSize(NamedSize.Medium),
                BorderWidth       = 0,
                WidthRequest      = 70,
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };
            rightButton.Clicked += RightButtonClicked;

            leftButton = new Button
            {
                Text              = LabelHandler.LESSTHAN_SYMBOL,
                Font              = Font.SystemFontOfSize(NamedSize.Medium),
                BorderWidth       = 0,
                WidthRequest      = 70,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };
            leftButton.Clicked += LeftButtonClicked;

            rangeLabel = new Label
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };
            rangeLabel.SetBinding(Label.TextProperty, new Binding("Filter.FilterText"));

            Children.Add(leftButton);
            Children.Add(rangeLabel);
            Children.Add(rightButton);
        }
예제 #10
0
        public async Tasks.Task HasItemsTrueWhenEntriesFound()
        {
            DataAccessTestable da = new DataAccessTestable();

            TimeCollectionViewModel vm = new TimeCollectionViewModel();

            vm.DataAccess = da;

            List <msdyn_timeentry> timeEntries = new List <msdyn_timeentry>();

            timeEntries.Add(new msdyn_timeentry()
            {
                msdyn_date     = DateTime.Today,
                msdyn_duration = 4
            });

            da.setRetrieveEntitiesResult(from entry in timeEntries select(Entity) entry);

            await vm.LoadTimes();

            Assert.IsTrue(vm.HasItems);
        }
예제 #11
0
        public TimePreview(TimeCollectionViewModel timeCollectionViewModel = null)
        {
            Orientation          = StackOrientation.Vertical;
            Padding              = 0;
            Spacing              = 0;
            this.BackgroundColor = BaseApp.PAGE_BACKGROUND_COLOR;

            StackLayout rootLayout = new StackLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Spacing           = 10,
                Padding           = 6,
                Orientation       = StackOrientation.Horizontal,
            };

            this.Children.Add(rootLayout);

            if (timeCollectionViewModel != null)
            {
                selectedIcon                   = ControlFactory.CreateIcon(null, ControlFactory.Medium_Label_Icon);
                selectedIcon.TextColor         = Color.Black;
                selectedIcon.FontSize          = Device.OnPlatform(10, 12, 16);
                selectedIcon.VerticalOptions   = LayoutOptions.CenterAndExpand;
                selectedIcon.HorizontalOptions = LayoutOptions.Start;
                selectedIcon.SetBinding(LabelIcon.IsVisibleProperty, new Binding()
                {
                    Source = timeCollectionViewModel,
                    Path   = "MultiselectModeEnabled"
                });
                selectedIcon.SetBinding(LabelIcon.TextProperty, "Selected", converter: new BooleanToSelectedIconConverter());

                rootLayout.Children.Add(selectedIcon);
            }

            entryTypeIcon = ControlFactory.CreateIcon(null, ControlFactory.Medium_Label_Icon);
            entryTypeIcon.SetBinding(Label.TextProperty, new Binding("msdyn_type", BindingMode.OneWay, new TimeEntryTypeToIconConverter()));
            entryTypeIcon.SetBinding(Label.TextColorProperty, new Binding(".", BindingMode.OneWay, new TimeEntryToColorConverter()));
            entryTypeIcon.VerticalOptions = LayoutOptions.Center;

            projectNameLabel = ControlFactory.CreateLabel(".", valueConverter: new TimeEntryToTitleConverter());
            projectNameLabel.HorizontalOptions = LayoutOptions.FillAndExpand;
            projectNameLabel.VerticalOptions   = LayoutOptions.FillAndExpand;

            timeLabel        = ControlFactory.CreateLabel("msdyn_duration", "{0}", null, new DurationToStringConverter());
            timeLabel.XAlign = TextAlignment.End;
            timeLabel.MinimumWidthRequest = 100;

            statusLabel                 = ControlFactory.CreateLabel("msdyn_entryStatus", "{0}", ControlFactory.Label_Indicator, new OptionSetConverter <msdyn_timeentry_msdyn_entrystatus>());
            statusLabel.XAlign          = TextAlignment.End;
            statusLabel.VerticalOptions = LayoutOptions.End;

            StackLayout timeAndStatusLayout = new StackLayout
            {
                HorizontalOptions = LayoutOptions.End,
                Orientation       = StackOrientation.Vertical,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Padding           = 0,
                Spacing           = 0,
                Children          =
                {
                    timeLabel,
                    statusLabel
                }
            };

            rootLayout.Children.Add(entryTypeIcon);
            rootLayout.Children.Add(projectNameLabel);
            rootLayout.Children.Add(timeAndStatusLayout);
            rootLayout.Children.Add(new Grid
            {
                Padding         = 0,
                WidthRequest    = Device.OnPlatform <double>(15, 0, 0),
                BackgroundColor = Color.Transparent
            });

            this.Children.Add(new Grid
            {
                Padding         = 0,
                HeightRequest   = 1,
                BackgroundColor = Color.FromHex("dddddd")
            });
        }
예제 #12
0
        public void MultiselectModeDefaultsFalse()
        {
            TimeCollectionViewModel vm = new TimeCollectionViewModel();

            Assert.IsFalse(vm.MultiselectModeEnabled);
        }
예제 #13
0
        public void HasItemsFalseInitially()
        {
            TimeCollectionViewModel vm = new TimeCollectionViewModel();

            Assert.IsFalse(vm.HasItems);
        }