public static double GetMiniConversionConstant(this YarnType yarnType) { YarnTypePropertiesAttribute yarnTypePropertiesAttribute = GetYarnTypeProperties(yarnType); double conversionConstant = yarnTypePropertiesAttribute.MiniConversionConstant; return(conversionConstant); }
public static YarnType GetCorrespondingMiniType(this YarnType yarnType) { YarnTypePropertiesAttribute yarnTypePropertiesAttribute = GetYarnTypeProperties(yarnType); YarnType miniType = yarnTypePropertiesAttribute.CorrespondingMiniType; return(miniType); }
public void CreateYarnTypeCodeFromTextShouldReturnYarnTypeCodeAsBFLSock() { String typeCode = "BSK"; YarnType yarnType = YarnFactory.CreateYarnTypeFromText(typeCode); Assert.AreEqual(YarnType.BFLSock, yarnType); }
public void ModifyValuesForMiniSkeinsShouldNotModifyValuesWhenDescriptionDoesNotContainANumber() { string yarnDescription = "Classy S.W. Merino Worsted"; double quantity = 2; YarnType yarnType = YarnType.Classy; (YarnType updatedYarnType, double updatedQuantity) = YarnFactory.ModifyValuesForMiniSkeins(yarnDescription, quantity, yarnType); Assert.AreEqual(YarnType.Classy, updatedYarnType); Assert.AreEqual(2, updatedQuantity); }
public void ModifyValuesForMiniSkeinsShouldModifyValuesWhenDescriptionContainsANumber() { string yarnDescription = "Classy 5- 50yd.minis @ $2.90 per skein"; double quantity = 2; YarnType yarnType = YarnType.Classy; (YarnType updatedYarnType, double updatedQuantity) = YarnFactory.ModifyValuesForMiniSkeins(yarnDescription, quantity, yarnType); Assert.AreEqual(YarnType.MiniClassy, updatedYarnType); Assert.AreEqual(10, updatedQuantity); }
public static (YarnType, double) ModifyValuesForMiniSkeins(string yarnDescription, double quantity, YarnType yarnType) { if (Yarn.DetermineIfMiniSkein(yarnDescription)) { double conversionConstant = yarnType.GetMiniConversionConstant(); quantity *= conversionConstant; YarnType miniType = yarnType.GetCorrespondingMiniType(); return(miniType, quantity); } return(yarnType, quantity); }
public static String GetTextRepresentation(this YarnType yarnType) { YarnTypePropertiesAttribute yarnTypePropertiesAttribute = GetYarnTypeProperties(yarnType); String textRepresentation = yarnTypePropertiesAttribute.TextRepresentation; if (textRepresentation != String.Empty) { return(textRepresentation); } else { return(yarnType.ToString()); } }
public static Yarn CreateYarnFromText(CsvReader reader) { double quantity = reader.GetField <double>(1); YarnType yarnType = YarnFactory.CreateYarnTypeFromText(reader.GetField <String>(2)); String yarnTypeDescription = reader.GetField <String>(3); (yarnType, quantity) = YarnFactory.ModifyValuesForMiniSkeins(yarnTypeDescription, quantity, yarnType); Yarn yarn = new Yarn(quantity, yarnType, yarnTypeDescription); if (reader.TryGetField <String>(4, out String colorName)) { yarn.Color = colorName; } return(yarn); }
public static Yarn CreateYarnFromText(string inputText) { inputText = inputText.TrimStart(','); String[] inputs = inputText.Split(','); double quantity = double.Parse(inputs[0]); YarnType yarnType = YarnFactory.CreateYarnTypeFromText(inputs[1]); String yarnTypeDescription = inputs[2]; (yarnType, quantity) = YarnFactory.ModifyValuesForMiniSkeins(yarnTypeDescription, quantity, yarnType); Yarn yarn = new Yarn(quantity, yarnType, yarnTypeDescription); if (inputs.Length > 3) { yarn.Color = inputs[3]; } return(yarn); }
private static YarnTypePropertiesAttribute GetYarnTypeProperties(YarnType yarnType) { Type type = yarnType.GetType(); string name = Enum.GetName(type, yarnType); if (name != null) { FieldInfo field = type.GetField(name); if (field != null) { YarnTypePropertiesAttribute yarnTypeProperties = Attribute.GetCustomAttribute(field, typeof(YarnTypePropertiesAttribute)) as YarnTypePropertiesAttribute; if (yarnTypeProperties != null) { return(yarnTypeProperties); } } } throw new ArgumentException(); }
public Yarn(double numberOfSkeins, YarnType yarnType, String yarnTypeDescription) { NumberOfSkeins = numberOfSkeins; YarnType = yarnType; YarnTypeDescription = yarnTypeDescription; }
public YarnTypePropertiesAttribute(double miniConversionConstant, YarnType miniType, string textRepresentation = "") { MiniConversionConstant = miniConversionConstant; CorrespondingMiniType = miniType; TextRepresentation = textRepresentation; }