コード例 #1
0
 public void TheTest()
 {
     new InvalidResponseException(404).GetObjectData(Info, Context);
     Result = (InvalidResponseException)typeof(InvalidResponseException)
              .GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic)
              .First()
              .Invoke(new object[] { Info, Context });
 }
コード例 #2
0
        public async Task InsertAsync_WhenUserFetchingDataFromServerAndGetInvalidResponse()
        {
            var expectedInvalidResponseException = new InvalidResponseException("The error message");

            await TestSendingRequestAndThenResponseHasErrors(
                expectedInvalidResponseException,
                "ErrorMessageJsonRespone",
                async() => await _serviceUnderTest.InsertAsync(new InsertPhotoGralleryRequest()));
        }
コード例 #3
0
        private void ValidateStatusCode(HttpStatusCode statusCode)
        {
            int statusCodeNumber = (int)statusCode;

            if (statusCodeNumber > 299 && statusCodeNumber < 400)
            {
                InvalidResponseException.ThrowFromInvalidResponse();
            }
        }
コード例 #4
0
        public async Task DeleteAsync_WhenUserFetchingDataFromServerAndGetInvalidResponse()
        {
            var expectedInvalidResponseException = new InvalidResponseException("The error message");

            await TestSendingRequestAndThenResponseHasErrors(
                expectedInvalidResponseException,
                "ErrorMessageJsonRespone",
                async() => await _serviceUnderTest.DeleteAsync(new DeleteRequest {
                Id = "1"
            }));
        }
コード例 #5
0
        public async Task InsertAsync_WhenUserFetchingDataFromServerAndGetInvalidResponseWithModelStateErrors()
        {
            var expectedInvalidResponseException = new InvalidResponseException(new Dictionary <string, string[]>
            {
                { "Name", new[] { "The Name field is required." } }
            });

            await TestSendingRequestAndThenResponseHasErrors(
                expectedInvalidResponseException,
                "ModelStateErrorResponseTestData",
                async() => await _serviceUnderTest.InsertAsync(new InsertPhotoGralleryRequest()));
        }
コード例 #6
0
        //Should return a byte[] after being passed to returnPossiblePrevValue(Transport t) in final implementation
        public byte[] executeOperation(Transport transport)
        {
            byte status = sendPutOperation(transport, HotRodConstants.PUT_REQUEST, HotRodConstants.PUT_RESPONSE);

            if (status != HotRodConstants.NO_ERROR_STATUS)
            {
                InvalidResponseException e = new InvalidResponseException("Unexpected response status: " + status);
                logger.Warn(e);
                throw e;
            }
            return(returnPossiblePrevValue(transport));
        }
コード例 #7
0
        public byte readHeader(Transport trans, HeaderParams param)
        {
            byte magic = trans.readByte(); //Reads magic byte: indicates whether the header is a request or a response

            if (magic != HotRodConstants.RESPONSE_MAGIC)
            {
                String message             = "Invalid magic number! Expected " + HotRodConstants.RESPONSE_MAGIC + "received " + magic;
                InvalidResponseException e = new InvalidResponseException(message);
                logger.Warn(e);
                throw e;
            }

            long receivedMessageId = trans.readVLong(); //Reads the message ID. Should be similar to the msg ID of the request


            if (receivedMessageId != param.Messageid && receivedMessageId != 0)
            {
                String message             = "Invalid Message ID! Expected " + param.Messageid + "received " + receivedMessageId;
                InvalidResponseException e = new InvalidResponseException(message);
                logger.Warn(e);
                throw new InvalidResponseException(message);
            }

            byte receivedOpCode = trans.readByte(); //Reads the OP Code

            logger.Trace(String.Format("response code recieved = " + receivedOpCode));
            if (receivedOpCode != param.OpRespCode)                   //Checks whether the recieved OP code is the corrsponding OPCode for the request sent
            {
                if (receivedOpCode == HotRodConstants.ERROR_RESPONSE) //In case of any error indication by the server
                {
                    logger.Warn(String.Format("Error Response Recieved : " + receivedOpCode));
                    throw new NotImplementedException("Error Response Recieved");
                }

                logger.Warn(String.Format("Invalid Response Recieved : Expected " + param.OpRespCode + " Recieved " + receivedOpCode));
                throw new InvalidResponseException("Invalid Response Operation.");
            }


            byte status = trans.readByte();    //Reads the status

            byte topchange = trans.readByte(); //Reads the Topology change byte. Equals 0 for No Change in topology

            logger.Trace(String.Format("Topology change indicator value : " + topchange));


            return(status);
        }
コード例 #8
0
        private async Task TestSendingRequestAndThenResponseHasErrors(
            InvalidResponseException expectedInvalidResponseException,
            string jsonFilename,
            Func <Task> doHttpRequestWorkAsync)
        {
            MockSendAsyncMethod(HttpStatusCode.BadRequest, GetContent(jsonFilename));

            try
            {
                await doHttpRequestWorkAsync();

                throw new Exception(
                          $"Expected that the method {nameof(PhotoGaleryHttpService.GetAllAsync)} throws error, but noting happen");
            }
            catch (InvalidResponseException invalidResponseException)
            {
                invalidResponseException.ModelStateErrors.Should().BeEquivalentTo(expectedInvalidResponseException.ModelStateErrors);
                invalidResponseException.Message.Should().Be(expectedInvalidResponseException.Message);
            }
        }