public void ObservableDictionaryExtensions_First_ThrowsExceptionIfObservableDictionaryIsEmpty()
        {
            var dictionary = new ObservableDictionary <Int32, String>();

            Assert.That(() => dictionary.First(),
                        Throws.TypeOf <InvalidOperationException>());
        }
        public void ObservableDictionaryExtensions_First_ReturnsFirstItemInObservableDictionary()
        {
            var dictionary = new ObservableDictionary <Int32, String>()
            {
                { 1, "A" },
                { 2, "B" },
                { 3, "C" },
            };

            var result = dictionary.First();

            TheResultingValue(result).ShouldBe(new KeyValuePair <Int32, String>(1, "A"));
        }
예제 #3
0
        /// <summary>
        /// Gather all the courses a specific teacher teaches
        /// </summary>
        /// <param name="teacher">The teacher to use</param>
        private void GatherTeacherCourses(Teacher teacher)
        {
            // Reset the Courses collection to fit the current teacher
            Courses = new ObservableDictionary <int, string>(TeacherCoursesHandler.GetTeacherCoursesNames(teacher, true));

            // Automatically select a course if possible
            if (Courses.Count() > 0)
            {
                SelectedCourse = Courses.First().Key;
            }
            else
            {
                SelectedCourse = NOT_ASSIGNED;
            }

            // For some reason the selections are not updated properly in the view unless called again
            OnPropertyChanged("SelectedCourse");
        }
예제 #4
0
        public bool Validate()
        {
            Validator.Reset();
            Validator.RemoveAllRules();

            // return true;
            ErrorSummary = string.Empty;

            //Final Result
            var final = SelectedFinalTestResult.ItemId;

            Validator.AddRule(
                "Final Result",
                () => RuleResult.Assert(
                    !final.IsNullOrEmpty(),
                    $"Final Result is required"
                    )
                );

            //Results Given
            var given = SelectedResultGiven.ItemId;

            Validator.AddRule(
                "Result Given",
                () => RuleResult.Assert(
                    !given.IsNullOrEmpty(),
                    $"Result Given is required"
                    )
                );


            if (EnableSelfTestOption)
            {
                // Accepted to partner listing

                var pnsaccepted = SelectedSelfTest.ItemId;

                Validator.AddRule(
                    "Partner Listing",
                    () => RuleResult.Assert(
                        !pnsaccepted.IsNullOrEmpty(),
                        $"Partner Listing is required"
                        )
                    );
            }

            if (EnablePnsDeclined)
            {
                //Decline
                var declined = SelectedPnsDeclined.ItemId;

                Validator.AddRule(
                    "Decline Reason",
                    () => RuleResult.Assert(
                        !declined.IsNullOrEmpty(),
                        $"Decline Reason is required"
                        )
                    );
            }

            var result = Validator.ValidateAll();

            Errors = result.AsObservableDictionary();
            if (null != Errors && Errors.Count > 0)
            {
                ErrorSummary = Errors.First().Value;
            }
            return(result.IsValid);
        }
        public void ObservableDictionaryExtensions_First_ThrowsExceptionIfObservableDictionaryIsEmpty()
        {
            var dictionary = new ObservableDictionary<Int32, String>();

            Assert.That(() => dictionary.First(),
                Throws.TypeOf<InvalidOperationException>());
        }
        public void ObservableDictionaryExtensions_First_ReturnsFirstItemInObservableDictionary()
        {
            var dictionary = new ObservableDictionary<Int32, String>()
            {
                { 1, "A" },
                { 2, "B" },
                { 3, "C" },
            };

            var result = dictionary.First();

            TheResultingValue(result).ShouldBe(new KeyValuePair<Int32, String>(1, "A"));
        }
예제 #7
0
        public TimeNumberInquirerResultPresenterViewModel(PluginInfo m)
        {
            this.m = m;
            this.m.PropertyChanged += new PropertyChangedEventHandler((sender, e) =>
            {
                switch (e.PropertyName)
                {
                case nameof(m.CurrentTextBox):
                    CurrentTextBox = (InputControlTextBox)m.CurrentTextBox;
                    break;

                case nameof(m.TimeNumberInquirerStatus):
                    if (m.TimeNumberInquirerStatus == TimeNumberInquirerStatus.Sent)
                    {
                        GameName   = m.Times.Count > 0 ? m.Times[0].Game.GetEnumDisplayName() : "";
                        Times      = m.Times.ConvertAll(t => t.String);
                        Visibility = Visibility.Visible;
                    }
                    else
                    {
                        Visibility = Visibility.Hidden;
                    }
                    break;
                }
            });

            m.TextBoxes.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
            {
                try
                {
                    TextBoxes[(InputControlTextBox)e.OldStartingIndex] = m.TextBoxes[e.NewStartingIndex];
                }
                catch { }
            });

            TextBoxes = new ObservableDictionary <InputControlTextBox, string>();
            foreach (InputControlTextBox i in Enum.GetValues(typeof(InputControlTextBox)))
            {
                TextBoxes.Add(i, "");
            }

            TextBoxes.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
            {
                try
                {
                    KeyValuePair <InputControlTextBox, string> textBox = TextBoxes.First(t => m.TextBoxes[(int)t.Key] != t.Value);
                    m.TextBoxes[(int)textBox.Key] = textBox.Value;
                }
                catch { }

                if (TextBoxes[CurrentTextBox].Length == 2)
                {
                    CurrentTextBox++;
                }
            });

            GotFocus = new DelegateCommand <string>(param =>
            {
                CurrentTextBox = (InputControlTextBox)Enum.Parse(typeof(InputControlTextBox), param);
            });

            Cancel = new DelegateCommand(() =>
            {
                m.TimeNumberInquirerStatus = TimeNumberInquirerStatus.Hidden;
            });

            Finish = new DelegateCommand(() =>
            {
                m.TextBoxes[(int)InputControlTextBox.Service] = m.Times[SelectedTimeIndex].Game.GetEnumDisplayName();
                m.TextBoxes[(int)InputControlTextBox.Number]  = Strings.StrConv(m.Times[SelectedTimeIndex].TimeNumber.ToString(), VbStrConv.Wide);
                m.TimeNumberInquirerStatus = TimeNumberInquirerStatus.Hidden;
            }, () => SelectedTimeIndex != -1).ObservesProperty(() => SelectedTimeIndex);
        }
        public void ObservableDictionaryExtensions_First_ThrowsExceptionIfObservableDictionaryIsEmpty()
        {
            var dictionary = new ObservableDictionary<Int32, String>();

            dictionary.First();
        }
        public TimeNumberInquirerViewModel(PluginInfo m)
        {
            this.m = m;
            this.m.PropertyChanged += new PropertyChangedEventHandler((sender, e) =>
            {
                switch (e.PropertyName)
                {
                case nameof(m.CurrentTextBox):
                    CurrentTextBox = (InputControlTextBox)m.CurrentTextBox;
                    break;

                case nameof(m.TimeNumberInquirerStatus):
                    if (m.TimeNumberInquirerStatus == TimeNumberInquirerStatus.PreparingToSend)
                    {
                        DateTime now = DateTime.Now;
                        TextBoxes[InputControlTextBox.TimeNumberInquirerStartHour]   = Strings.StrConv(now.Hour.ToString(), VbStrConv.Wide);
                        TextBoxes[InputControlTextBox.TimeNumberInquirerStartMinute] = Strings.StrConv(now.Minute.ToString(), VbStrConv.Wide);

                        Visibility     = Visibility.Visible;
                        CurrentTextBox = InputControlTextBox.TimeNumberInquirerEndHour;
                    }
                    else
                    {
                        Visibility = Visibility.Hidden;
                    }
                    break;
                }
            });

            m.TextBoxes.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
            {
                try
                {
                    TextBoxes[(InputControlTextBox)e.OldStartingIndex] = m.TextBoxes[e.NewStartingIndex];
                }
                catch { }
            });

            TextBoxes = new ObservableDictionary <InputControlTextBox, string>();
            foreach (InputControlTextBox i in Enum.GetValues(typeof(InputControlTextBox)))
            {
                TextBoxes.Add(i, "");
            }

            TextBoxes.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
            {
                try
                {
                    KeyValuePair <InputControlTextBox, string> textBox = TextBoxes.First(t => m.TextBoxes[(int)t.Key] != t.Value);
                    m.TextBoxes[(int)textBox.Key] = textBox.Value;
                }
                catch { }

                if (TextBoxes[CurrentTextBox].Length == 2)
                {
                    CurrentTextBox++;
                }
            });

            GotFocus = new DelegateCommand <string>(param =>
            {
                CurrentTextBox = (InputControlTextBox)Enum.Parse(typeof(InputControlTextBox), param);
            });

            Cancel = new DelegateCommand(() =>
            {
                m.TimeNumberInquirerStatus = TimeNumberInquirerStatus.Hidden;
            });

            Send = new DelegateCommand(() =>
            {
                m.Times = ((Sender)m.Sender).InquireTimeNumbers((Game)(SelectedGameIndex + 1));
                m.TimeNumberInquirerStatus = m.Times == null ? TimeNumberInquirerStatus.Hidden : TimeNumberInquirerStatus.Sent;
            });
        }
예제 #10
0
        public InputControlViewModel(PluginInfo m)
        {
            this.m = m;
            this.m.PropertyChanged += new PropertyChangedEventHandler((sender, e) =>
            {
                switch (e.PropertyName)
                {
                case nameof(m.PluginHost):
                    ((BindableBase)this.m.PluginHost).PropertyChanged += new PropertyChangedEventHandler((hsender, he) =>
                    {
                        switch (he.PropertyName)
                        {
                        case nameof(m.PluginHost.CurrentTicket):
                            Visibility = m.PluginHost.CurrentTicket == this.m ? Visibility.Visible : Visibility.Hidden;
                            break;
                        }
                    });
                    break;

                case nameof(m.CurrentTextBox):
                    CurrentTextBox = (InputControlTextBox)m.CurrentTextBox;
                    break;
                }
            });

            m.TextBoxes.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
            {
                try
                {
                    TextBoxes[(InputControlTextBox)e.OldStartingIndex] = m.TextBoxes[e.NewStartingIndex];
                }
                catch { }
            });

            TextBoxes = new ObservableDictionary <InputControlTextBox, string>();
            foreach (InputControlTextBox i in Enum.GetValues(typeof(InputControlTextBox)))
            {
                TextBoxes.Add(i, "");
            }

            TextBoxes.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) =>
            {
                if ((InputControlTextBox)e.NewStartingIndex == InputControlTextBox.Month || (InputControlTextBox)e.NewStartingIndex == InputControlTextBox.Day)
                {
                    int month        = WideStringToInt(TextBoxes[InputControlTextBox.Month]);
                    int date         = WideStringToInt(TextBoxes[InputControlTextBox.Day]);
                    string dayOfWeek = " ";
                    try
                    {
                        DateTime today    = DateTime.Today;
                        DateTime dateTime = new DateTime(today.Year, month, date);
                        if (dateTime < today)
                        {
                            dateTime.AddYears(1);
                        }
                        dayOfWeek = week[(int)dateTime.DayOfWeek];
                    }
                    catch { }
                    DayOfWeek = dayOfWeek;
                }

                try
                {
                    KeyValuePair <InputControlTextBox, string> textBox = TextBoxes.First(t => m.TextBoxes[(int)t.Key] != t.Value);
                    m.TextBoxes[(int)textBox.Key] = textBox.Value;
                }
                catch { }

                if (CurrentTextBox != InputControlTextBox.Child && TextBoxes[CurrentTextBox].Length == 2)
                {
                    CurrentTextBox++;
                }
            });

            SideMenu = new DelegateCommand(() =>
            {
                m.PluginHost.GoToSideMenu();
            });

            GotFocus = new DelegateCommand <string>(param =>
            {
                CurrentTextBox = (InputControlTextBox)Enum.Parse(typeof(InputControlTextBox), param);
            });
        }