Exemple #1
0
        public DateTemplateQuestionAttribute(string altText, string imageUrl, string data = "date", string mode = "date", string label = "選日期")
        {
            _Question = altText;
            if (!imageUrl.StartsWith("https"))
            {
                throw new Exception("imageUrl必須以https開頭...");
            }

            DateTimePickerAction dateTimePickerAction = new DateTimePickerAction()
            {
                data = data, label = label, mode = mode
            };
            List <ImageCarouselColumn> columns = new List <ImageCarouselColumn>();

            columns.Add(new ImageCarouselColumn()
            {
                action = dateTimePickerAction, imageUrl = new Uri(imageUrl)
            });

            imageCarouselTemplate = new ImageCarouselTemplate()
            {
                columns = columns,
                altText = altText
            };
        }
Exemple #2
0
            public void ShouldThrowExceptionWhenValueIsMoreThan300Chars()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Date);

                ExceptionAssert.Throws <InvalidOperationException>("The data cannot be longer than 300 characters.", () =>
                {
                    action.Data = new string('x', 301);
                });
            }
Exemple #3
0
            public void ShouldThrowExceptionWhenValueIsEmpty()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Date);

                ExceptionAssert.Throws <InvalidOperationException>("The data cannot be null or whitespace.", () =>
                {
                    action.Data = string.Empty;
                });
            }
            public void ShouldThrowExceptionWhenValueIsNull()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Date);

                ExceptionAssert.Throws <InvalidOperationException>("The label cannot be null or whitespace.", () =>
                {
                    action.Label = null;
                });
            }
Exemple #5
0
            public void ShouldThrowExceptionWhenLabelIsNull()
            {
                IAction action = new DateTimePickerAction(DateTimePickerMode.Date);

                ExceptionAssert.Throws <InvalidOperationException>("The label cannot be null.", () =>
                {
                    action.Validate();
                });
            }
            public void ShouldSetDateAndTimeWhenDateTimePickerActionModeIsDateTime()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.DateTime);

                var min = new DateTime(2018, 10, 08, 10, 30, 0);

                action.Min = min;

                Assert.AreEqual(min, action.Min);
            }
Exemple #7
0
            public void ShouldNotThrowExceptionWhenValid()
            {
                IAction action = new DateTimePickerAction(DateTimePickerMode.Date)
                {
                    Label = "Foo",
                    Data  = "Bar"
                };

                action.Validate();
            }
Exemple #8
0
            public void ShouldNotThrowExceptionWhenValueIs300Chars()
            {
                var value = new string('x', 300);

                var action = new DateTimePickerAction(DateTimePickerMode.Date)
                {
                    Data = value
                };

                Assert.AreEqual(value, action.Data);
            }
            public void ShouldThrowExceptionWhenMinIsEqualToMax()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Date);
                var now    = new DateTime(2018, 10, 8);

                ExceptionAssert.Throws <InvalidOperationException>("The min must be less than the max.", () =>
                {
                    action.Max = now;
                    action.Min = now;
                });
            }
Exemple #10
0
            public void ShouldThrowExceptionWhenInitialIsLessThanMin()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Date)
                {
                    Max = new DateTime(2018, 10, 8)
                };

                ExceptionAssert.Throws <InvalidOperationException>("The initial must be between the min and the max.", () =>
                {
                    action.Initial = new DateTime(2018, 10, 9);
                });
            }
            public void ShouldNotThrowExceptionWhenMinIsLessThanMax()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Date);
                var min    = new DateTime(2018, 10, 7);
                var max    = new DateTime(2018, 10, 8);

                action.Max = max;
                action.Min = min;

                Assert.AreEqual(action.Max, max);
                Assert.AreEqual(action.Min, min);
            }
Exemple #12
0
            public void ShouldThrowExceptionWhenDataIsNull()
            {
                IAction action = new DateTimePickerAction(DateTimePickerMode.Date)
                {
                    Label = "PostbackLabel"
                };

                ExceptionAssert.Throws <InvalidOperationException>("The data cannot be null.", () =>
                {
                    action.Validate();
                });
            }
Exemple #13
0
            public void ShouldThrowExceptionWhenMaxIsLessThanMin()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Date);
                var min    = new DateTime(2018, 10, 8);
                var max    = new DateTime(2018, 10, 7);

                ExceptionAssert.Throws <InvalidOperationException>("The max must be greater than the min.", () =>
                {
                    action.Min = min;
                    action.Max = max;
                });
            }
            public void ShouldThrowExceptionWhenMinAndMaxHaveDifferentDatesButModeIsTime()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Time);

                var min = new DateTime(2018, 10, 7, 11, 0, 0);
                var max = new DateTime(2018, 10, 8, 11, 0, 0);

                ExceptionAssert.Throws <InvalidOperationException>("The max must be greater than the min.", () =>
                {
                    action.Min = min;
                    action.Max = max;
                });
            }
            public void ShouldBeAdjustedWhenSet()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Date)
                {
                    Data    = "Foo",
                    Label   = "Bar",
                    Min     = new DateTime(2018, 10, 10),
                    Initial = new DateTime(2018, 10, 11),
                    Max     = new DateTime(2018, 10, 13)
                };

                action.Min = new DateTime(2018, 10, 9, 10, 30, 0);

                Assert.AreEqual(action.Min, new DateTime(2018, 10, 9));
            }
Exemple #16
0
            public void ShouldFormatDateTimesAsTimesWhenModeIsTime()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Time)
                {
                    Label   = "Select date",
                    Data    = "storeId=12345",
                    Initial = new DateTime(2017, 12, 25, 14, 0, 0),
                    Max     = new DateTime(2018, 01, 24, 16, 0, 0),
                    Min     = new DateTime(2017, 12, 25, 13, 0, 0)
                };

                string serialized = JsonConvert.SerializeObject(action);

                Assert.AreEqual(@"{""type"":""datetimepicker"",""mode"":""time"",""data"":""storeId=12345"",""label"":""Select date"",""initial"":""14:00"",""max"":""16:00"",""min"":""13:00""}", serialized);
            }
            public void ShouldFormatDateTimesAsDateTimesWhenModeIsDateTime()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.DateTime)
                {
                    Label   = "Select date",
                    Data    = "storeId=12345",
                    Initial = new DateTime(2017, 12, 25, 0, 0, 0),
                    Max     = new DateTime(2018, 01, 24, 23, 59, 0),
                    Min     = new DateTime(2017, 12, 25, 0, 0, 0)
                };

                string serialized = JsonSerializer.SerializeObject(action);

                Assert.AreEqual(@"{""mode"":""datetime"",""type"":""datetimepicker"",""data"":""storeId=12345"",""label"":""Select date"",""initial"":""2017-12-25T00:00"",""max"":""2018-01-24T23:59"",""min"":""2017-12-25T00:00""}", serialized);
            }
Exemple #18
0
            public void ShouldNotThrowExceptionWhenInitialIsBetweenMinAndMax()
            {
                var min     = new DateTime(2018, 10, 7);
                var initial = new DateTime(2018, 10, 8);
                var max     = new DateTime(2018, 10, 9);

                var action = new DateTimePickerAction(DateTimePickerMode.Date)
                {
                    Min     = min,
                    Initial = initial,
                    Max     = max
                };

                Assert.AreEqual(min, action.Min);
                Assert.AreEqual(initial, action.Initial);
                Assert.AreEqual(max, action.Max);
            }
            public void ShouldCreateSerializeableObject()
            {
                var initial = new DateTime(2018, 10, 8, 10, 30, 0);
                var min     = new DateTime(2018, 10, 8, 10, 00, 0);
                var max     = new DateTime(2018, 10, 8, 11, 00, 0);

                var action = new DateTimePickerAction(DateTimePickerMode.DateTime)
                {
                    Label   = "Foo",
                    Data    = "Bar",
                    Initial = initial,
                    Min     = min,
                    Max     = max
                };
                string serialized = JsonConvert.SerializeObject(action);

                Assert.AreEqual(@"{""type"":""datetimepicker"",""mode"":""datetime"",""data"":""Bar"",""label"":""Foo"",""initial"":""2018-10-08T10:30"",""max"":""2018-10-08T11:00"",""min"":""2018-10-08T10:00""}", serialized);
            }
            public void ShouldSetTimeOnlyWhenDateTimePickerActionModeIsTime()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Time);

                var minTime     = new DateTime(DateTime.MinValue.Year, DateTime.MinValue.Month, DateTime.MinValue.Day, 10, 30, 0);
                var maxTime     = new DateTime(DateTime.MinValue.Year, DateTime.MinValue.Month, DateTime.MinValue.Day, 11, 00, 0);
                var initialTime = new DateTime(DateTime.MinValue.Year, DateTime.MinValue.Month, DateTime.MinValue.Day, 10, 45, 0);

                var minDateTime     = new DateTime(2018, 10, 08, 10, 30, 0);
                var maxDateTime     = new DateTime(2018, 10, 08, 11, 0, 0);
                var initialDateTime = new DateTime(2018, 10, 08, 10, 45, 0);

                action.Min     = minDateTime;
                action.Max     = maxDateTime;
                action.Initial = initialDateTime;

                Assert.AreEqual(minTime, action.Min);
                Assert.AreEqual(maxTime, action.Max);
                Assert.AreEqual(initialTime, action.Initial);
            }
            public void ShouldNotThrowExceptionWhenActionIsDateTimePickerAction()
            {
                var action = new DateTimePickerAction(DateTimePickerMode.Date);

                IActionExtensions.CheckActionType(action);
            }