public void TestParseValidSide() { var coloredSide = ColoredSide.Parse("Red-7"); var expectedSide = new ColoredSide(Color.Red, 7); Assert.AreEqual(coloredSide, expectedSide); }
/// <summary> /// This method is creating a triangle from a string specified in a specific format /// </summary> /// <param name="triangle">Actual string</param> /// <returns>New instance of ColoredTriangle</returns> /// <exception cref="DomainException"> /// Is thrown when triangle string has an invalid format or the length of sides are invalid /// </exception> public static ColoredTriangle Parse(string triangle) { var fields = triangle.Split(FieldDelimiter); if (fields.Length < 3) { throw new DomainException($"Not enough sides for triangle ({fields.Length})"); } return(Create( ColoredSide.Parse(fields[0]), ColoredSide.Parse(fields[1]), ColoredSide.Parse(fields[2]) )); }
public void TestParseInvalidSide() { Assert.Throws <DomainException>(() => ColoredSide.Parse("Rdd-43")); }