Skip to content

Commit d706e15

Browse files
committed
chore: unit test updates
1 parent ba96dca commit d706e15

4 files changed

Lines changed: 41 additions & 28 deletions

File tree

src/KnightwareCoreTests/Collections/ListExtensionsTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void CopyToRemovesMissingItemsTest()
8383
(s, d) => d.Name = s.Name,
8484
removed => removedItem = removed);
8585

86-
Assert.AreEqual(1, destination.Count);
86+
Assert.HasCount(1, destination);
8787
Assert.IsNotNull(removedItem);
8888
Assert.AreEqual(2, removedItem.Id);
8989
}
@@ -105,7 +105,6 @@ public void CopyToWithNullSourceDoesNotThrowTest()
105105
public void CopyToWithNullDestinationDoesNotThrowTest()
106106
{
107107
var source = new List<SourceItem> { new SourceItem { Id = 1 } };
108-
109108
source.CopyTo<SourceItem, DestItem, int>(
110109
null,
111110
s => s.Id,
Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using System;
3-
using System.Collections.Generic;
4-
using System.Drawing;
53
using System.IO;
6-
using System.Text;
7-
84

95
namespace Knightware.Drawing
106
{
@@ -21,19 +17,43 @@ public void DrawSolidBitmapTest()
2117
const int width = 808;
2218
const int height = 402;
2319

24-
using (var stream = BitmapHelper.GenerateSolidColorBitmap(Primitives.Color.FromArgb(a, r, g, b), width, height))
25-
{
26-
stream.Seek(0, SeekOrigin.Begin);
20+
using var stream = BitmapHelper.GenerateSolidColorBitmap(Primitives.Color.FromArgb(a, r, g, b), width, height);
21+
stream.Seek(0, SeekOrigin.Begin);
22+
23+
// Parse BMP header directly (works cross-platform without System.Drawing)
24+
using var reader = new BinaryReader(stream);
25+
26+
// BMP Header (14 bytes)
27+
var signature = new string(reader.ReadChars(2));
28+
Assert.AreEqual("BM", signature, "Invalid BMP signature");
29+
30+
var fileSize = reader.ReadInt32();
31+
reader.ReadInt32(); // Reserved
32+
var dataOffset = reader.ReadInt32();
33+
34+
// DIB Header
35+
var dibHeaderSize = reader.ReadInt32();
36+
var bmpWidth = reader.ReadInt32();
37+
var bmpHeight = reader.ReadInt32();
38+
39+
Assert.AreEqual(width, bmpWidth, "Width was incorrect");
40+
Assert.AreEqual(height, bmpHeight, "Height was incorrect");
41+
42+
// Skip to pixel data and verify color
43+
reader.ReadInt16(); // planes
44+
var bitsPerPixel = reader.ReadInt16();
45+
Assert.AreEqual(24, bitsPerPixel, "Expected 24-bit BMP");
46+
47+
stream.Seek(dataOffset, SeekOrigin.Begin);
2748

28-
//Use System.Drawing bitmap to confirm
29-
using (var bitmap = Bitmap.FromStream(stream))
30-
{
31-
Assert.AreEqual(width, bitmap.Width, "Width was incorrect");
32-
Assert.AreEqual(height, bitmap.Height, "Height was incorrect");
49+
// Read first pixel (BGR order in BMP)
50+
byte pixelB = reader.ReadByte();
51+
byte pixelG = reader.ReadByte();
52+
byte pixelR = reader.ReadByte();
3353

34-
//TODO: Test all the pixels for the correct color
35-
}
36-
}
54+
Assert.AreEqual(b, pixelB, "Blue channel was incorrect");
55+
Assert.AreEqual(g, pixelG, "Green channel was incorrect");
56+
Assert.AreEqual(r, pixelR, "Red channel was incorrect");
3757
}
3858
}
39-
}
59+
}

src/KnightwareCoreTests/PropertyChangedBaseTests.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ public void PropertyChangedWithExplicitNameTest()
5959
Assert.AreEqual("Value", changedPropertyName);
6060
}
6161

62-
[TestMethod]
63-
public void PropertyChangedNotRaisedWithoutSubscriberTest()
64-
{
65-
var obj = new TestPropertyChangedClass();
66-
obj.Name = "Test";
67-
}
68-
6962
[TestMethod]
7063
public void MultiplePropertyChangedEventsTest()
7164
{

src/KnightwareCoreTests/Threading/Tasks/BatchProcessorTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,19 @@ await TestSimpleSetup(
228228
maximumCount: int.MaxValue);
229229

230230
//Run our test duration, adding items as needed
231+
List<Task> tasks = new();
231232
for(int i=0; i<expectedBatches; i++)
232233
{
233234
//We'll add a couple items, then wait for our min refresh time to elapse
234235
for (int j = 0; j < expectedItemsPerBatch; j++)
235236
{
236-
Task t1 = processor.EnqueueAsync(0);
237+
tasks.Add(processor.EnqueueAsync(0));
237238
}
238239
await Task.Delay(minMs * 2);
239240
}
240-
241+
241242
//Wait for last batch to finish...
242-
await Task.Delay(1000);
243+
await Task.WhenAll(tasks);
243244

244245
//Verify we processed the correct number of batches
245246
Assert.HasCount(expectedBatches, batchesSizesProcessed, "Incorrect number of batches processed");

0 commit comments

Comments
 (0)