/// <summary> /// This method executes a builtin types test. /// </summary> /// <param name="testCaseContext">This parameter stores the test case parameter values.</param> /// <param name="testCase">This parameter stores the test case related data.</param> /// <param name="iteration">This parameter stores the current iteration number.</param> /// <param name="input">Input value.</param> /// <returns>A variant of the type scalar value.</returns> /// <remarks> /// The test parameters required for this test case are of the /// following types: /// <list type="bullet"> /// <item>MaxStringLength <see cref="TestCaseContext.MaxStringLength"/></item> /// </list> /// </remarks> private CompositeTestType ExecuteTest_BuiltInTypes(TestCaseContext testCaseContext, TestCase testCase, int iteration, CompositeTestType input) { bool isSetupStep = TestUtils.IsSetupIteration(iteration); if (!isSetupStep) { m_logger.LogStartEvent(testCase, iteration); } try { if (isSetupStep) { // No verification for the input is required. return(null); } else { m_random.Start( (int)(testCase.Seed + iteration), (int)m_sequenceToExecute.RandomDataStepSize, testCaseContext); CompositeTestType expectedInput = m_random.GetCompositeTestType(); try { if (!Compare.CompareCompositeTestType(input, expectedInput)) { throw new ServiceResultException( StatusCodes.BadInvalidState, Utils.Format("'{0}' is not equal to '{1}'.", input, expectedInput)); } } catch (Exception e) { throw ServiceResultException.Create( StatusCodes.BadInvalidState, e, "'{0}' is not equal to '{1}'.", input, expectedInput); } m_random.Start((int)( testCase.ResponseSeed + iteration), (int)m_sequenceToExecute.RandomDataStepSize, testCaseContext); return(m_random.GetCompositeTestType()); } } finally { if (!isSetupStep) { m_logger.LogCompleteEvent(testCase, iteration); } } }
/// <summary> /// This method executes a test. /// </summary> /// <param name="testCaseContext">This parameter stores the test case parameter values.</param> /// <param name="testCase">This parameter stores the test case related data.</param> /// <param name="iteration">This parameter stores the current iteration number.</param> /// <param name="input">Input value.</param> /// <returns>Output value.</returns> private CompositeTestType ExecuteTest(TestCaseContext testCaseContext, TestCase testCase, int iteration, CompositeTestType input) { CompositeTestType output = null; switch (testCase.Name) { case TestCases.BuiltInTypes: { output = ExecuteTest_BuiltInTypes(testCaseContext, testCase, iteration, input); break; } default: { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "Unsupported test case : " + testCase.Name); } } return(output); }
/// <summary> /// This method invokes the TestStackEx service. /// </summary> /// <param name="requestHeader">Request Header.</param> /// <param name="testId">Test Case Id.</param> /// <param name="iteration">This parameter stores the current iteration number.</param> /// <param name="input">Input Value.</param> /// <param name="output">Output Value.</param> /// <returns>Exception or Response based on the conditions.</returns> public override ResponseHeader TestStackEx( RequestHeader requestHeader, uint testId, int iteration, CompositeTestType input, out CompositeTestType output) { TestCase testCase = null; lock (m_lock) { if (!m_logger.IsOpened) { m_logger.Open(SecureChannelContext.Current.SecureChannelId, m_configuration.TestFilePath, m_configuration.RandomFilePath); } if (iteration == TestCases.TestSetupIteration) { Interlocked.Increment(ref m_activeTestCasesCount); } } try { testCase = ValidateTestCase(testId, iteration); } catch (Exception e) { m_logger.LogNotValidatedEvent(testId, iteration, e); throw; } try { try { ValidateRequest(requestHeader); TestCaseContext context = TestUtils.GetExecutionContext(testCase); output = ExecuteTest(context, testCase, iteration, input); return(CreateResponse(requestHeader, StatusCodes.Good)); } catch (Exception e) { if (testCase.Name == TestCases.ServerFault) { throw e; } else { m_logger.LogErrorEvent(testCase, iteration, e); throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, e, "Test {0}, Iteration {1} Failed.", testCase.Name, iteration); } } } finally { lock (m_lock) { if (iteration == TestCases.TestCleanupIteration) { Interlocked.Decrement(ref m_activeTestCasesCount); } if (iteration == TestCases.TestCleanupIteration && TestUtils.IsLastTestCase(m_sequenceToExecute, testCase) && m_activeTestCasesCount == 0) { if (m_logger.IsOpened) { m_logger.Close(); } } } } }
/// <summary> /// This method executes a test. /// </summary> /// <param name="testCaseContext">This parameter stores the test case parameter values.</param> /// <param name="testCase">This parameter stores the test case related data.</param> /// <param name="iteration">This parameter stores the current iteration number.</param> /// <param name="input">Input value.</param> /// <returns>Output value.</returns> private CompositeTestType ExecuteTest(TestCaseContext testCaseContext, TestCase testCase, int iteration, CompositeTestType input) { CompositeTestType output = null; switch (testCase.Name) { case TestCases.BuiltInTypes: { output = ExecuteTest_BuiltInTypes(testCaseContext, testCase, iteration, input); break; } default: { throw ServiceResultException.Create(StatusCodes.BadConfigurationError, "Unsupported test case : " + testCase.Name); } } return output; }
/// <summary> /// This method invokes the TestStackEx service. /// </summary> /// <param name="requestHeader">Request Header.</param> /// <param name="testId">Test Case Id.</param> /// <param name="iteration">This parameter stores the current iteration number.</param> /// <param name="input">Input Value.</param> /// <param name="output">Output Value.</param> /// <returns>Exception or Response based on the conditions.</returns> public override ResponseHeader TestStackEx( RequestHeader requestHeader, uint testId, int iteration, CompositeTestType input, out CompositeTestType output) { TestCase testCase = null; lock (m_lock) { if (!m_logger.IsOpened) { m_logger.Open(SecureChannelContext.Current.SecureChannelId, m_configuration.TestFilePath, m_configuration.RandomFilePath); } if (iteration == TestCases.TestSetupIteration) { Interlocked.Increment(ref m_activeTestCasesCount); } } try { testCase = ValidateTestCase(testId, iteration); } catch (Exception e) { m_logger.LogNotValidatedEvent(testId, iteration, e); throw; } try { try { ValidateRequest(requestHeader); TestCaseContext context = TestUtils.GetExecutionContext(testCase); output = ExecuteTest(context, testCase, iteration, input); return CreateResponse(requestHeader, StatusCodes.Good); } catch (Exception e) { if (testCase.Name == TestCases.ServerFault) { throw e; } else { m_logger.LogErrorEvent(testCase, iteration, e); throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, e, "Test {0}, Iteration {1} Failed.", testCase.Name, iteration); } } } finally { lock (m_lock) { if (iteration == TestCases.TestCleanupIteration) { Interlocked.Decrement(ref m_activeTestCasesCount); } if (iteration == TestCases.TestCleanupIteration && TestUtils.IsLastTestCase(m_sequenceToExecute, testCase) && m_activeTestCasesCount == 0 ) { if (m_logger.IsOpened) { m_logger.Close(); } } } } }
/// <summary> /// Finishes an asynchronous invocation of the TestStackEx service. /// </summary> public ResponseHeader EndTestStackEx( IAsyncResult result, out CompositeTestType output) { TestStackExResponse response = null; try { if (UseTransportChannel) { IServiceResponse genericResponse = TransportChannel.EndSendRequest(result); if (genericResponse == null) { throw new ServiceResultException(StatusCodes.BadUnknownResponse); } ValidateResponse(genericResponse.ResponseHeader); response = (TestStackExResponse)genericResponse; } else { TestStackExResponseMessage responseMessage = InnerChannel.EndTestStackEx(result); if (responseMessage == null || responseMessage.TestStackExResponse == null) { throw new ServiceResultException(StatusCodes.BadUnknownResponse); } response = responseMessage.TestStackExResponse; ValidateResponse(response.ResponseHeader); } output = response.Output; } finally { RequestCompleted(null, response, "TestStackEx"); } return response.ResponseHeader; }
/// <summary> /// Begins an asynchronous invocation of the TestStackEx service. /// </summary> public IAsyncResult BeginTestStackEx( RequestHeader requestHeader, uint testId, int iteration, CompositeTestType input, AsyncCallback callback, object asyncState) { TestStackExRequest request = new TestStackExRequest(); request.RequestHeader = requestHeader; request.TestId = testId; request.Iteration = iteration; request.Input = input; UpdateRequestHeader(request, requestHeader == null, "TestStackEx"); if (UseTransportChannel) { return TransportChannel.BeginSendRequest(request, callback, asyncState); } return InnerChannel.BeginTestStackEx(new TestStackExMessage(request), callback, asyncState); }
/// <summary> /// Invokes the TestStackEx service. /// </summary> public virtual ResponseHeader TestStackEx( RequestHeader requestHeader, uint testId, int iteration, CompositeTestType input, out CompositeTestType output) { TestStackExRequest request = new TestStackExRequest(); TestStackExResponse response = null; request.RequestHeader = requestHeader; request.TestId = testId; request.Iteration = iteration; request.Input = input; UpdateRequestHeader(request, requestHeader == null, "TestStackEx"); try { if (UseTransportChannel) { IServiceResponse genericResponse = TransportChannel.SendRequest(request); if (genericResponse == null) { throw new ServiceResultException(StatusCodes.BadUnknownResponse); } ValidateResponse(genericResponse.ResponseHeader); response = (TestStackExResponse)genericResponse; } else { TestStackExResponseMessage responseMessage = InnerChannel.TestStackEx(new TestStackExMessage(request)); if (responseMessage == null || responseMessage.TestStackExResponse == null) { throw new ServiceResultException(StatusCodes.BadUnknownResponse); } response = responseMessage.TestStackExResponse; ValidateResponse(response.ResponseHeader); } output = response.Output; } finally { RequestCompleted(request, response, "TestStackEx"); } return response.ResponseHeader; }
/// <summary> /// This method returns CompositeTestType. /// </summary> public CompositeTestType GetCompositeTestType() { CompositeTestType value = new CompositeTestType(); value.Field1 = GetScalarTestType(); value.Field2 = GetArrayTestType(); return value; }
/// <summary> /// Invokes the TestStackEx service. /// </summary> public virtual ResponseHeader TestStackEx( RequestHeader requestHeader, uint testId, int iteration, CompositeTestType input, out CompositeTestType output) { output = null; ValidateRequest(requestHeader); // Insert implementation. return CreateResponse(requestHeader, StatusCodes.BadServiceUnsupported); }
/// <summary> /// This method executes a builtin types test. /// </summary> /// <param name="testCaseContext">This parameter stores the test case parameter values.</param> /// <param name="testCase">This parameter stores the test case related data.</param> /// <param name="iteration">This parameter stores the current iteration number.</param> /// <param name="input">Input value.</param> /// <returns>A variant of the type scalar value.</returns> /// <remarks> /// The test parameters required for this test case are of the /// following types: /// <list type="bullet"> /// <item>MaxStringLength <see cref="TestCaseContext.MaxStringLength"/></item> /// </list> /// </remarks> private CompositeTestType ExecuteTest_BuiltInTypes(TestCaseContext testCaseContext, TestCase testCase, int iteration, CompositeTestType input) { bool isSetupStep = TestUtils.IsSetupIteration(iteration); if (!isSetupStep) { m_logger.LogStartEvent(testCase, iteration); } try { if (isSetupStep) { // No verification for the input is required. return null; } else { m_random.Start( (int)(testCase.Seed + iteration), (int)m_sequenceToExecute.RandomDataStepSize, testCaseContext); CompositeTestType expectedInput = m_random.GetCompositeTestType(); try { if (!Compare.CompareCompositeTestType(input, expectedInput)) { throw new ServiceResultException( StatusCodes.BadInvalidState, Utils.Format("'{0}' is not equal to '{1}'.", input, expectedInput)); } } catch (Exception e) { throw ServiceResultException.Create( StatusCodes.BadInvalidState, e, "'{0}' is not equal to '{1}'.", input, expectedInput); } m_random.Start((int)( testCase.ResponseSeed + iteration), (int)m_sequenceToExecute.RandomDataStepSize, testCaseContext); return m_random.GetCompositeTestType(); } } finally { if (!isSetupStep) { m_logger.LogCompleteEvent(testCase, iteration); } } }