Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #103 from tomasr/WcfFixBuild
Browse files Browse the repository at this point in the history
Fix globalization errors from fxcop
  • Loading branch information
Sergey Kanzhelev committed Mar 13, 2017
2 parents 25b4ee7 + dae802c commit 424addb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
30 changes: 18 additions & 12 deletions WCF/Shared.Tests/WcfEventSourceTests.cs
Expand Up @@ -9,20 +9,26 @@
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

namespace Microsoft.ApplicationInsights.Wcf.Tests
{
[TestClass]
public class WcfEventSourceTests
{
private void CheckMessage(WcfEventListener listener, String format, params object[] args)
{
Assert.AreEqual(String.Format(CultureInfo.CurrentCulture, format, args), listener.FirstEventMessage);

}
[TestMethod]
public void InitializationFailure_Message()
{
using ( var listener = new WcfEventListener() )
{
var msg = "Exception message";
WcfEventSource.Log.InitializationFailure(msg);
Assert.AreEqual(String.Format(WcfEventSource.InitializationFailure_Message, msg), listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.InitializationFailure_Message, msg);
}
}

Expand All @@ -34,7 +40,7 @@ public void TelemetryModuleExecutionStarted_Message()
var typeName = "MyType";
var stageName = "MyStage";
WcfEventSource.Log.TelemetryModuleExecutionStarted(typeName, stageName);
Assert.AreEqual(String.Format(WcfEventSource.TelemetryModuleExecutionStarted_Message, typeName, stageName), listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.TelemetryModuleExecutionStarted_Message, typeName, stageName);
}
}

Expand All @@ -46,7 +52,7 @@ public void TelemetryModuleExecutionStopped_Message()
var typeName = "MyType";
var stageName = "MyStage";
WcfEventSource.Log.TelemetryModuleExecutionStopped(typeName, stageName);
Assert.AreEqual(String.Format(WcfEventSource.TelemetryModuleExecutionStopped_Message, typeName, stageName), listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.TelemetryModuleExecutionStopped_Message, typeName, stageName);
}
}

Expand All @@ -59,7 +65,7 @@ public void TelemetryModuleExecutionFailed_Message()
var stageName = "MyStage";
var exception = "MyException";
WcfEventSource.Log.TelemetryModuleExecutionFailed(typeName, stageName, exception);
Assert.AreEqual(String.Format(WcfEventSource.TelemetryModuleExecutionFailed_Message, typeName, stageName, exception), listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.TelemetryModuleExecutionFailed_Message, typeName, stageName, exception);
}
}

Expand All @@ -69,7 +75,7 @@ public void NoOperationContextFound_Message()
using ( var listener = new WcfEventListener() )
{
WcfEventSource.Log.NoOperationContextFound();
Assert.AreEqual(WcfEventSource.NoOperationContextFound_Message, listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.NoOperationContextFound_Message);
}
}

Expand All @@ -82,7 +88,7 @@ public void OperationIgnored_Message()
var contractNamespace = "MyNS";
var operationName = "MyOperation";
WcfEventSource.Log.OperationIgnored(contractName, contractNamespace, operationName);
Assert.AreEqual(String.Format(WcfEventSource.OperationIgnored_Message, contractName, contractNamespace, operationName), listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.OperationIgnored_Message, contractName, contractNamespace, operationName);
}
}

Expand All @@ -93,7 +99,7 @@ public void WcfTelemetryInitializerLoaded_Message()
{
var typeName = "MyType";
WcfEventSource.Log.WcfTelemetryInitializerLoaded(typeName);
Assert.AreEqual(String.Format(WcfEventSource.WcfTelemetryInitializerLoaded_Message, typeName), listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.WcfTelemetryInitializerLoaded_Message, typeName);
}
}

Expand All @@ -104,7 +110,7 @@ public void LocationIdSet_Message()
{
var ip = "10.0.0.1";
WcfEventSource.Log.LocationIdSet(ip);
Assert.AreEqual(String.Format(WcfEventSource.LocationIdSet_Message, ip), listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.LocationIdSet_Message, ip);
}
}

Expand All @@ -116,7 +122,7 @@ public void OperationContextCreated_Message()
var operationId = "abcdef";
var ownsContext = true;
WcfEventSource.Log.OperationContextCreated(operationId, ownsContext);
Assert.AreEqual(String.Format(WcfEventSource.OperationContextCreated_Message, operationId, ownsContext), listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.OperationContextCreated_Message, operationId, ownsContext);
}
}

Expand All @@ -128,7 +134,7 @@ public void RequestMessageClosed_Message()
var action = "reading property";
var argument = "Myproperty";
WcfEventSource.Log.RequestMessageClosed(action, argument);
Assert.AreEqual(String.Format(WcfEventSource.RequestMessageClosed_Message, action, argument), listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.RequestMessageClosed_Message, action, argument);
}
}

Expand All @@ -140,7 +146,7 @@ public void ResponseMessageClosed_Message()
var action = "reading property";
var argument = "Myproperty";
WcfEventSource.Log.ResponseMessageClosed(action, argument);
Assert.AreEqual(String.Format(WcfEventSource.ResponseMessageClosed_Message, action, argument), listener.FirstEventMessage);
CheckMessage(listener, WcfEventSource.ResponseMessageClosed_Message, action, argument);
}
}

Expand All @@ -161,7 +167,7 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
lock ( lockObj )
{
var str = String.Format(eventData.Message, eventData.Payload.ToArray());
var str = String.Format(CultureInfo.CurrentCulture, eventData.Message, eventData.Payload.ToArray());
AllMessages.Add(str);
if ( String.IsNullOrEmpty(FirstEventMessage) )
{
Expand Down
2 changes: 1 addition & 1 deletion WCF/Shared/RequestTrackingTelemetryModule.cs
Expand Up @@ -105,7 +105,7 @@ void IWcfTelemetryModule.OnEndRequest(IOperationContext operation, Message reply
telemetry.ResponseCode = responseCode.ToString("d");
if ( telemetry.Url != null )
{
telemetry.Properties.Add("Protocol", telemetry.Url.Scheme);
telemetry.Properties["Protocol"] = telemetry.Url.Scheme;
}
// if the Microsoft.ApplicationInsights.Web package started
// tracking this request before WCF handled it, we
Expand Down
11 changes: 10 additions & 1 deletion WCF/Shared/ServiceTelemetryAttribute.cs
Expand Up @@ -40,9 +40,18 @@ void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescriptio
}

var contractFilter = BuildFilter(serviceDescription);
var interceptor = new WcfInterceptor(configuration, contractFilter);
WcfInterceptor interceptor = null;
foreach ( ChannelDispatcher channelDisp in serviceHost.ChannelDispatchers )
{
if ( channelDisp.ErrorHandlers.OfType<WcfInterceptor>().Any() )
{
// already added, ignore
continue;
}
if ( interceptor == null )
{
interceptor = new WcfInterceptor(configuration, contractFilter);
}
channelDisp.ErrorHandlers.Insert(0, interceptor);
foreach ( var ep in channelDisp.Endpoints )
{
Expand Down

0 comments on commit 424addb

Please sign in to comment.