public void DocumentOptionsModelExtensionsClassToDocumentOptionsMethodReturnsDocumentOptionsObjectWithCorrectClockTypePropertyIfArgumentClockTypeNamePropertyEqualsTwentyFourHourClock()
        {
            DocumentOptionsModel testObject = new DocumentOptionsModel {
                ClockTypeName = "TwentyFourHourClock"
            };

            DocumentOptions resultObject = testObject.ToDocumentOptions();

            Assert.AreEqual(ClockType.TwentyFourHourClock, resultObject.ClockType);
        }
        public void DocumentOptionsModelExtensionsClassToDocumentOptionsMethodReturnsDocumentOptionsObjectWithGraphEditStylePropertyEqualToPreserveSectionTimesIfArgumentGraphEditStylePropertyIsEmptyString()
        {
            DocumentOptionsModel testObject = new DocumentOptionsModel {
                GraphEditStyle = ""
            };

            DocumentOptions resultObject = testObject.ToDocumentOptions();

            Assert.AreEqual(GraphEditStyle.PreserveSectionTimes, resultObject.GraphEditStyle);
        }
        private DocumentOptionsModel GetModel()
        {
            DocumentOptionsModel model = new DocumentOptionsModel
            {
                DisplayTrainLabelsOnGraphs = _rnd.NextNullableBoolean(),
                ClockTypeName  = _rnd.NextPotentiallyValidString(_validClockTypes),
                GraphEditStyle = _rnd.NextPotentiallyValidString(_validGraphEditStyles),
            };

            return(model);
        }
        public void DocumentOptionsModelExtensionsClass_ToDocumentOptionsMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfParameterIsNull()
        {
            DocumentOptionsModel testObject = null;

            try
            {
                _ = testObject.ToDocumentOptions();
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("model", ex.ParamName);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Convert a <see cref="DocumentOptionsModel"/> instance into a <see cref="DocumentOptions"/> instance.
        /// </summary>
        /// <param name="model">The data to be converted.</param>
        /// <returns>The<see cref="DocumentOptions"/> instance.</returns>
        public static DocumentOptions ToDocumentOptions(this DocumentOptionsModel model)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            DocumentOptions options = new DocumentOptions
            {
                DisplayTrainLabelsOnGraphs = model.DisplayTrainLabelsOnGraphs ?? true
            };

            if (Enum.TryParse(model.ClockTypeName, out ClockType ct))
            {
                options.ClockType = ct;
            }

            if (Enum.TryParse(model.GraphEditStyle, out GraphEditStyle ges))
            {
                options.GraphEditStyle = ges;
            }

            return(options);
        }