public Write ( byte buffer, int offset, int count ) : void | ||
buffer | byte | /// Buffer. /// |
offset | int | /// Offset. /// |
count | int | /// Count. /// |
return | void |
public void ResumeTest() { byte[] inputContent = new byte[100]; long offset = 100; using (var stream = new MemoryStream(inputContent)) using (var offsetstream = new OffsetStream(stream, offset)) { using (var progress = new ProgressStream(offsetstream)) { progress.PropertyChanged += delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var p = sender as ProgressStream; if (e.PropertyName == Utils.NameOf(() => p.Position)) { this.position = (long)p.Position; this.percent = p.Percent.GetValueOrDefault(); } }; progress.Seek(0, SeekOrigin.Begin); Assert.AreEqual(offset, this.position); Assert.AreEqual(50, this.percent); progress.Seek(10, SeekOrigin.Current); Assert.AreEqual(offset + 10, this.position); progress.Seek(0, SeekOrigin.End); Assert.AreEqual(100, this.percent); Assert.AreEqual(offset + inputContent.Length, this.position); progress.Seek(0, SeekOrigin.Begin); progress.WriteByte(0); Assert.AreEqual(offset + 1, this.position); Assert.AreEqual(50.5, this.percent); progress.WriteByte(0); Assert.AreEqual(offset + 2, this.position); Assert.AreEqual(51, this.percent); progress.Write(new byte[10], 0, 10); Assert.AreEqual(56, this.percent); } } }
public void Write() { using (var stream = new MemoryStream()) { byte[] buffer = new byte[10]; using (var progress = new ProgressStream(stream)) { progress.PropertyChanged += delegate(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var t = sender as ProgressStream; if (e.PropertyName == Utils.NameOf(() => t.Position)) { this.positionCalls++; this.position = (long)t.Position; this.percent = (double)t.Percent.GetValueOrDefault(); } }; progress.SetLength(buffer.Length * 10); progress.Write(buffer, 0, buffer.Length); Assert.AreEqual(buffer.Length, this.position); Assert.AreEqual(10, this.percent); progress.Write(buffer, 0, buffer.Length); Assert.AreEqual(buffer.Length * 2, this.position); Assert.AreEqual(20, this.percent); progress.Write(buffer, 0, buffer.Length); Assert.AreEqual(buffer.Length * 3, this.position); Assert.AreEqual(30, this.percent); progress.Write(buffer, 0, buffer.Length); Assert.AreEqual(buffer.Length * 4, this.position); Assert.AreEqual(40, this.percent); progress.Write(buffer, 0, buffer.Length / 2); Assert.AreEqual((buffer.Length * 4) + (buffer.Length / 2), this.position); Assert.AreEqual(45, this.percent); progress.Write(buffer, 0, buffer.Length); Assert.AreEqual((buffer.Length * 5) + (buffer.Length / 2), this.position); Assert.AreEqual(55, this.percent); progress.SetLength(buffer.Length * 100); progress.Write(buffer, 0, buffer.Length); Assert.AreEqual((buffer.Length * 6) + (buffer.Length / 2), this.position); Assert.AreEqual(6.5, this.percent); } } }