public void TestAssignSlotOffsetLength() { var placedArrayCaptor = new ArgumentCaptor <byte[]>(); var random = new Random(0); var data = new byte[100].With(random.NextBytes); testObj.AssignSlot(SLOT_INDEX, data, 10, 80); Verify(slotDestination).SetSlot(Eq(SLOT_INDEX), placedArrayCaptor.GetParameter(), Eq(10), Eq(80)); VerifyNoMoreInteractions(); AssertTrue(placedArrayCaptor.Value == data); }
public void TestWriteBytesOffsetLength() { var placedArrayCaptor = new ArgumentCaptor <byte[]>(); var random = new Random(0); var data = new byte[100].With(random.NextBytes); testObj.WriteBytes(SLOT_INDEX, data, 10, 80); Verify(slotDestination).SetSlot(Eq(SLOT_INDEX), placedArrayCaptor.GetParameter()); VerifyNoMoreInteractions(); AssertTrue(placedArrayCaptor.Value != data); AssertTrue(placedArrayCaptor.Value.SequenceEqual(data.Skip(10).Take(80))); }
public void ReadTypeTest() { var int32TypeId = (int)ReservedTypeId.TYPE_S32; var typeDescriptionCaptor = new ArgumentCaptor <PofTypeDescription>(); When(context.GetTypeOrNull(int32TypeId)).ThenReturn(typeof(int)); When(context.GetTypeFromDescription(typeDescriptionCaptor.GetParameter())).ThenReturn(typeof(int)); When(slotSource[kSlotIndex]).ThenReturn(BitConverter.GetBytes(int32TypeId)); AssertEquals(typeof(int), testObj.ReadType(kSlotIndex)); var typeDescription = typeDescriptionCaptor.Value; AssertEquals(1, typeDescription.All().Length); AssertEquals(typeof(int), typeDescription.All()[0]); }
public void TestType() { var type = typeof(int); var int32TypeId = (int)ReservedTypeId.TYPE_S32; When(context.GetTypeIdByType(typeof(int))).ThenReturn(int32TypeId); testObj.WriteType(SLOT_INDEX, type); var streamCaptor = new ArgumentCaptor <MemoryStream>(); Verify(context).GetTypeIdByType(typeof(int)); Verify(slotDestination).SetSlot(Eq(SLOT_INDEX), streamCaptor.GetParameter()); VerifyNoMoreInteractions(); var slotStream = streamCaptor.Value; AssertEquals(slotStream.ToArray(), BitConverter.GetBytes(int32TypeId)); }
public void RegisterHandler_Generic_Test() { object parameterObject = new object(); bool handlerExecuted = false; var handler = new Action <object>(o => { handlerExecuted = o == parameterObject; }); testObj.RegisterHandler(handler); var captor = new ArgumentCaptor <Action <object> >(); Verify(handlersByType).TryAdd(Eq(typeof(object)), captor.GetParameter()); VerifyNoMoreInteractions(); AssertFalse(handlerExecuted); captor.Value(parameterObject); AssertTrue(handlerExecuted); }
public void TestWriteString() { const string value = "There is no spoon!"; testObj.WriteString(SLOT_INDEX, value); byte[] data; using (var ms = new MemoryStream()) { using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) { writer.WriteNullTerminatedString(value); } data = ms.ToArray(); } var streamCaptor = new ArgumentCaptor <MemoryStream>(); Verify(slotDestination).SetSlot(Eq(SLOT_INDEX), streamCaptor.GetParameter()); VerifyNoMoreInteractions(); AssertTrue(Encoding.UTF8.GetString(streamCaptor.Value.ToArray()).Equals(value + "\0")); }