/// <summary> /// Initializes a new instance of the <see cref="MonthlyValue"/> class. /// </summary> /// <param name="bandwidth"> /// The monthly bandwidth. /// </param> public MonthlyValue(MonthlyBandwidth bandwidth) { this.bandwidth = bandwidth; this.Year = bandwidth.Year; this.Month = bandwidth.Month; this.ChangeTransferUnit(TransferUnit.Gigabytes); }
private static MonthlyBandwidth CreateMonhtlyBandwidth(string rawValue, string page) { var values = rawValue.Split(',').ToList(); if (3 != values.Count) { var msg = "Cannot parse monthly bandwidth from <{0}> because it does not contain exactly three elements separated by comma." .FormatWith(rawValue); throw new ParseException(msg, page); } try { // Time conversion is directly from the javascript. // .NET does not support >>> (shift right zero fill). var tempTime = Convert.ToInt32(ParserHelper.TrimInvalidCharacters(values[0]), 16); var year = ((tempTime >> 16) & 0xFF) + 1900; var month = (Common.LogicalRightShift(tempTime, 8) & 0xFF) + 1; var download = ParserHelper.ToKilobytes(values[1]); var upload = ParserHelper.ToKilobytes(values[2]); var monthly = new MonthlyBandwidth(year, month, download, upload); return monthly; } catch (Exception exp) { throw new ParseException("Failed to parse single monthly bandwidth information", page, rawValue, exp); } }
private void AssertSingleMonth(MonthlyBandwidth bandwidth, int expectedYear, int expectedMonth, uint expectedDownload, uint expectdUpload) { Assert.AreEqual(expectedYear, bandwidth.Year, "Year is invaldi"); Assert.AreEqual(expectedMonth, bandwidth.Month, "Month is invalid"); Assert.AreEqual(expectedDownload, bandwidth.Download.Kilobytes, "Download is invalid"); Assert.AreEqual(expectdUpload, bandwidth.Upload.Kilobytes, "Upload is invalid"); }