Exemple #1
0
        public void ExceptionDuring_MSG_AllocateMemoryBuffer_ReturnsAllocatedAsFalse()
        {
            // arrange
            Container.GetMock <IMarshalWrapper>()
            .Setup(x => x.PtrToStructure <MSG_AllocateBuffer_Request>(It.IsAny <IntPtr>()))
            .Returns(new MSG_AllocateBuffer_Request());

            var response = new MSG_AllocateBuffer_Response {
                allocated = true
            };

            Container.GetMock <IMarshalWrapper>()
            .Setup(x => x.StructureToPtr(It.IsAny <MSG_AllocateBuffer_Response>(), It.IsAny <IntPtr>(), It.IsAny <bool>()))
            .Callback <MSG_AllocateBuffer_Response, IntPtr, bool>((msg, ptr, b) => { response = msg; });

            uint bufferId;

            Container.GetMock <IMemoryManager>()
            .Setup(x => x.AllocateMemoryBuffer(It.IsAny <int>(), out bufferId))
            .Throws <NullReferenceException>();

            // act
            Instance.StandardMessage(MSG_Type.MSG_AllocateMemoryBuffer, _mockCommunicationBlock.Object,
                                     (i, block) => {  },
                                     block => { });

            // assert
            Assert.AreEqual(false, response.allocated);
        }
Exemple #2
0
        public void Handles_MSG_AllocateMemoryBuffer_WithMismatchedVersion()
        {
            // arrange
            var version = typeof(MSG_AllocateBuffer_Request).Assembly.GetName().Version;

            Container.GetMock <IMarshalWrapper>()
            .Setup(x => x.PtrToStructure <MSG_AllocateBuffer_Request>(It.IsAny <IntPtr>()))
            .Returns(new MSG_AllocateBuffer_Request()
            {
                version_high = 1,
                version_low  = 1
            });

            var response = new MSG_AllocateBuffer_Response {
                allocated = true
            };

            Container.GetMock <IMarshalWrapper>()
            .Setup(x => x.StructureToPtr(It.IsAny <MSG_AllocateBuffer_Response>(), It.IsAny <IntPtr>(), It.IsAny <bool>()))
            .Callback <MSG_AllocateBuffer_Response, IntPtr, bool>((msg, ptr, b) => { response = msg; });

            uint bufferId;

            Container.GetMock <IMemoryManager>()
            .Setup(x => x.AllocateMemoryBuffer(It.IsAny <int>(), out bufferId))
            .Returns(new ManagedBufferBlock());

            // act
            Instance.StandardMessage(MSG_Type.MSG_AllocateMemoryBuffer, _mockCommunicationBlock.Object, (i, block) => { }, block => { });

            // assert
            Assert.IsFalse(response.allocated);
            Assert.AreEqual(MSG_AllocateBufferFailure.ABF_ProfilerVersionMismatch, response.reason);
        }