public void GraphTrainPropertiesExtensionsClass_ToGraphTrainPropertiesModelMethod_ThrowsArgumentNullException_IfParameterIsNull() { GraphTrainProperties testObject = null; _ = testObject.ToGraphTrainPropertiesModel(); Assert.Fail(); }
public void GraphTrainPropertiesExtensionsClass_ToYamlGraphTrainPropertiesModelMethod_ReturnsObjectWithCorrectDashStyleNameProperty_IfParameterIsNotNull() { GraphTrainProperties testParam = GetTestObject(); GraphTrainPropertiesModel testOutput = testParam.ToYamlGraphTrainPropertiesModel(); Assert.AreEqual(testParam.DashStyle.ToString("g"), testOutput.DashStyleName); }
public void GraphTrainPropertiesExtensionsClass_ToYamlGraphTrainPropertiesModelMethod_ThrowsNullReferenceException_IfParameterIsNull() { GraphTrainProperties testParam = null; _ = testParam.ToYamlGraphTrainPropertiesModel(); Assert.Fail(); }
public void GraphTrainPropertiesModelExtensionsClass_ToGraphTrainPropertiesModel_ReturnsObjectWithCorrectColourProperty_IfColourPropertyOfParameterIsValid() { GraphTrainPropertiesModel testParam = GetModel(); GraphTrainProperties testOutput = testParam.ToGraphTrainProperties(); Assert.AreEqual(testParam.Colour, testOutput.Colour.ToArgb().ToString("X8", CultureInfo.InvariantCulture)); }
public void GraphTrainPropertiesModelExtensionsClassToGraphTrainPropertiesMethodReturnsNullIfParameterIsNull() { GraphTrainPropertiesModel testObject = null; GraphTrainProperties testResult = testObject.ToGraphTrainProperties(); Assert.IsNull(testResult); }
public void GraphTrainPropertiesExtensionsClass_ToYamlGraphTrainPropertiesModelMethod_ReturnsObjectWithCorrectWidthProperty_IfParameterIsNotNull() { GraphTrainProperties testParam = GetTestObject(); GraphTrainPropertiesModel testOutput = testParam.ToYamlGraphTrainPropertiesModel(); Assert.AreEqual(testParam.Width, testOutput.Width); }
public void GraphTrainPropertiesExtensionsClass_ToYamlGraphTrainPropertiesModelMethod_ReturnsObjectWithCorrectColourProperty_IfParameterIsNotNull() { GraphTrainProperties testParam = GetTestObject(); GraphTrainPropertiesModel testOutput = testParam.ToYamlGraphTrainPropertiesModel(); Assert.AreEqual(testParam.Colour.ToArgb().ToString("X8", CultureInfo.InvariantCulture), testOutput.Colour); }
public void GraphTrainPropertiesModelExtensionsClass_ToGraphTrainPropertiesModel_ReturnsObjectWithDashStylePropertyEqualToSolid_IfDashStyleNamePropertyOfParameterIsNotValid() { GraphTrainPropertiesModel testParam = GetModel(); testParam.DashStyleName = _rnd.NextDefinitelyInvalidString(_validDashStyles); GraphTrainProperties testOutput = testParam.ToGraphTrainProperties(); Assert.AreEqual(DashStyle.Solid, testOutput.DashStyle); }
public void GraphTrainPropertiesModelExtensionsClass_ToGraphTrainPropertiesModel_ReturnsObjectWithColourPropertyEqualToBlack_IfColourPropertyOfParameterIsNull() { GraphTrainPropertiesModel testParam = GetModel(); testParam.Colour = null; GraphTrainProperties testOutput = testParam.ToGraphTrainProperties(); Assert.AreEqual(Color.Black, testOutput.Colour); }
public void GraphTrainPropertiesModelExtensionsClass_ToGraphTrainPropertiesModel_ReturnsObjectWithColourPropertyEqualToBlack_IfColourPropertyOfParameterIsNotValid() { GraphTrainPropertiesModel testParam = GetModel(); testParam.Colour = _rnd.NextString("GHIJKLMNOPQRSTVWXYZ", _rnd.Next(20)); GraphTrainProperties testOutput = testParam.ToGraphTrainProperties(); Assert.AreEqual(Color.Black, testOutput.Colour); }
public void GraphTrainPropertiesModelExtensionsClass_ToGraphTrainPropertiesModel_ReturnsObjectWithWidthPropertyEqualTo1_IfWidthPropertyOfParameterIsNull() { GraphTrainPropertiesModel testParam = GetModel(); testParam.Width = null; GraphTrainProperties testOutput = testParam.ToGraphTrainProperties(); Assert.AreEqual(1f, testOutput.Width); }
public void GraphTrainPropertiesModelExtensionsClass_ToGraphTrainPropertiesModel_ReturnsObjectWithCorrectWidthProperty_IfWidthPropertyOfParameterIsNotNull() { GraphTrainPropertiesModel testParam = GetModel(); testParam.Width = (float)(_rnd.NextDouble() * 5); GraphTrainProperties testOutput = testParam.ToGraphTrainProperties(); Assert.AreEqual(testParam.Width, testOutput.Width); }
public void GraphTrainPropertiesModelExtensionsClass_ToGraphTrainPropertiesModel_ReturnsObjectWithDashStylePropertyEqualToSolid_IfDashStyleNamePropertyOfParameterIsNull() { GraphTrainPropertiesModel testParam = GetModel(); testParam.DashStyleName = null; GraphTrainProperties testOutput = testParam.ToGraphTrainProperties(); Assert.AreEqual(DashStyle.Solid, testOutput.DashStyle); }
public void GraphTrainPropertiesModelExtensionsClass_ToGraphTrainPropertiesModel_ReturnsObjectWithCorrectDashStyleProperty_IfDashStyleNamePropertyOfParameterIsValid() { GraphTrainPropertiesModel testParam = GetModel(); testParam.DashStyleName = _validDashStyles[_rnd.Next(_validDashStyles.Length)]; GraphTrainProperties testOutput = testParam.ToGraphTrainProperties(); Assert.AreEqual(testParam.DashStyleName, testOutput.DashStyle.ToString("g")); }
public void GraphTrainPropertiesModelExtensionsClassToGraphTrainPropertiesMethodReturnsObjectWithCorrectWidthProperty() { float testWidth = (float)(_random.NextDouble() * 10); GraphTrainPropertiesModel testObject = new GraphTrainPropertiesModel { Width = testWidth }; GraphTrainProperties testResult = testObject.ToGraphTrainProperties(); Assert.AreEqual(testWidth, testResult.Width); }
public void GraphTrainPropertiesModelExtensionsClassToGraphTrainPropertiesMethodReturnsObjectWithCorrectColourProperty() { Color testColour = Color.FromArgb(_random.Next()); GraphTrainPropertiesModel testObject = new GraphTrainPropertiesModel { ColourCode = testColour.ToArgb().ToString("X8", CultureInfo.InvariantCulture) }; GraphTrainProperties testResult = testObject.ToGraphTrainProperties(); Assert.AreEqual(testColour, testResult.Colour); }
public void GraphTrainPropertiesModelExtensionsClassToGraphTrainPropertiesMethodReturnsObjectWithCorrectDashStyleProperty() { DashStyle[] validDashStyles = new[] { DashStyle.Dash, DashStyle.DashDot, DashStyle.DashDotDot, DashStyle.Dot, DashStyle.Solid }; DashStyle testDashStyle = validDashStyles[_random.Next(validDashStyles.Length)]; GraphTrainPropertiesModel testObject = new GraphTrainPropertiesModel { DashStyleName = Enum.GetName(typeof(DashStyle), testDashStyle) }; GraphTrainProperties testResult = testObject.ToGraphTrainProperties(); Assert.AreEqual(testDashStyle, testResult.DashStyle); }
/// <summary> /// Convert a <see cref="GraphTrainPropertiesModel"/> instance into a <see cref="GraphTrainProperties"/> instance. /// </summary> /// <param name="gtp">The model object to load.</param> /// <returns>A <see cref="GraphTrainProperties"/> instance containing the same data as the model.</returns> public static GraphTrainPropertiesModel ToGraphTrainPropertiesModel(this GraphTrainProperties gtp) { if (gtp is null) { throw new ArgumentNullException(nameof(gtp)); } return(new GraphTrainPropertiesModel { ColourCode = gtp.Colour.ToArgb().ToString("X8", CultureInfo.InvariantCulture), DashStyleName = Enum.GetName(typeof(DashStyle), gtp.DashStyle), Width = gtp.Width, }); }
/// <summary> /// Converts a <see cref="GraphTrainProperties" /> instance to a <see cref="GraphTrainPropertiesModel" /> instance. /// </summary> /// <param name="properties">The object to be converted.</param> /// <returns>A <see cref="GraphTrainPropertiesModel" /> instance containing the same data in serialisable form.</returns> /// <exception cref="NullReferenceException">Thrown if the parameter is <c>null</c>.</exception> public static GraphTrainPropertiesModel ToYamlGraphTrainPropertiesModel(this GraphTrainProperties properties) { if (properties is null) { throw new NullReferenceException(); } return(new GraphTrainPropertiesModel { Colour = properties.Colour.ToArgb().ToString("X8", CultureInfo.InvariantCulture), DashStyleName = Enum.GetName(typeof(DashStyle), properties.DashStyle), Width = properties.Width, }); }
public void GraphTrainPropertiesExtensionsClass_ToGraphTrainPropertiesModelMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfParameterIsNull() { GraphTrainProperties testObject = null; try { _ = testObject.ToGraphTrainPropertiesModel(); Assert.Fail(); } catch (ArgumentNullException ex) { Assert.AreEqual("gtp", ex.ParamName); } }
/// <summary> /// Convert a <see cref="GraphTrainPropertiesModel" /> instance to a <see cref="GraphTrainProperties" /> instance. /// </summary> /// <param name="model">The object to be converted.</param> /// <returns>A <see cref="GraphTrainProperties" /> instance containing the same data as the original object.</returns> /// <exception cref="NullReferenceException">Thrown if the parameter is <c>null</c>.</exception> public static GraphTrainProperties ToGraphTrainProperties(this GraphTrainPropertiesModel model) { if (model is null) { throw new NullReferenceException(); } GraphTrainProperties gtp = new GraphTrainProperties { Width = model.Width ?? 1f }; if (int.TryParse(model.Colour, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int col)) { gtp.Colour = Color.FromArgb(col); } if (Enum.TryParse(model.DashStyleName, out DashStyle style)) { gtp.DashStyle = style; } return(gtp); }
/// <summary> /// Convert a <see cref="GraphTrainPropertiesModel"/> object into a <see cref="GraphTrainProperties"/> object. /// </summary> /// <param name="model">The data to be converted.</param> /// <returns>The <see cref="GraphTrainProperties"/> instance.</returns> public static GraphTrainProperties ToGraphTrainProperties(this GraphTrainPropertiesModel model) { if (model == null) { return(null); } GraphTrainProperties gtp = new GraphTrainProperties { Width = model.Width }; if (int.TryParse(model.ColourCode, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out int col)) { gtp.Colour = Color.FromArgb(col); } if (Enum.TryParse(model.DashStyleName, out DashStyle style)) { gtp.DashStyle = style; } return(gtp); }