private ImmutableTransaction BuildTestTransaction(string uri = null, string guid = null, int?statusCode = null, int?subStatusCode = null, IEnumerable <ErrorData> transactionExceptionDatas = null) { var transactionMetadata = new TransactionMetadata(); if (uri != null) { transactionMetadata.SetUri(uri); } if (statusCode != null) { transactionMetadata.SetHttpResponseStatusCode(statusCode.Value, subStatusCode, _errorService); } if (transactionExceptionDatas != null) { transactionExceptionDatas.ForEach(data => transactionMetadata.TransactionErrorState.AddExceptionData(data)); } var name = TransactionName.ForWebTransaction("foo", "bar"); var segments = Enumerable.Empty <Segment>(); var metadata = transactionMetadata.ConvertToImmutableMetadata(); guid = guid ?? Guid.NewGuid().ToString(); var attribDefSvc = new AttributeDefinitionService((f) => new AttributeDefinitions(f)); return(new ImmutableTransaction(name, segments, metadata, DateTime.UtcNow, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1), guid, false, false, false, 0.5f, false, string.Empty, null, attribDefSvc.AttributeDefs)); }
public void Getters_HttpResponseStatusCode() { var metadata = new TransactionMetadata(); Assert.IsNull(metadata.HttpResponseStatusCode); metadata.SetHttpResponseStatusCode(200, null, Mock.Create <IErrorService>()); Assert.AreEqual(200, metadata.HttpResponseStatusCode); metadata.SetHttpResponseStatusCode(400, null, Mock.Create <IErrorService>()); Assert.AreEqual(400, metadata.HttpResponseStatusCode); var immutableMetadata = metadata.ConvertToImmutableMetadata(); Assert.AreEqual(400, immutableMetadata.HttpResponseStatusCode); Assert.IsNull(immutableMetadata.HttpResponseSubStatusCode); metadata.SetHttpResponseStatusCode(404, 420, Mock.Create <IErrorService>()); Assert.AreEqual(404, metadata.HttpResponseStatusCode); immutableMetadata = metadata.ConvertToImmutableMetadata(); Assert.AreEqual(404, immutableMetadata.HttpResponseStatusCode); Assert.AreEqual(420, immutableMetadata.HttpResponseSubStatusCode); }