public void Parse_MixedCount_CorrectCount( [Random(10, 200, 5)]int w1Count, [Random(10, 200, 5)]int w2Count) { List<bool> arr = new List<bool>(new bool[w1Count + w2Count]); for (int i = 0; i < w1Count; i++) { arr[i] = true; } for (int i = 0; i < w2Count; i++) { arr[i + w1Count] = false; } string data = ""; while (arr.Count > 0) { var index = Random.Next(0, arr.Count); string code = (arr[index]) ? "001" : "002"; data += code + Guid.NewGuid().ToString().Substring(0, 3); arr.RemoveAt(index); } var wrappers = CompositeWrapper.Parse(data, WrapperMap); Assert.AreEqual(w1Count, wrappers.Where(w => w is WrapperStub1).Count()); Assert.AreEqual(w2Count, wrappers.Where(w => w is WrapperStub2).Count()); }
public void Parse_Normal_CorrectCount() { string data = "001AAA002BBB"; var wrappers = CompositeWrapper.Parse(data, WrapperMap); Assert.AreEqual(2, wrappers.Count); }
public void When_WrappedInCompsition_Ignore_Wrapper_Methods_In_Callstack() { //namespace en name of current method const string currentMethodFullName = "NLog.UnitTests.LayoutRenderers.CallSiteTests.When_WrappedInCompsition_Ignore_Wrapper_Methods_In_Callstack"; LogManager.Configuration = CreateConfigurationFromString(@" <nlog> <targets><target name='debug' type='Debug' layout='${callsite}|${message}' /></targets> <rules> <logger name='*' levels='Warn' writeTo='debug' /> </rules> </nlog>"); var logger = LogManager.GetLogger("A"); logger.Warn("direct"); AssertDebugLastMessage("debug", $"{currentMethodFullName}|direct"); CompositeWrapper wrappedLogger = new CompositeWrapper(); wrappedLogger.Log("wrapped"); AssertDebugLastMessage("debug", $"{currentMethodFullName}|wrapped"); }
public void Parse_TooLongString_Exception() { string data = "001" + Guid.NewGuid().ToString(); CompositeWrapper.Parse(data, WrapperMap); }
public void Parse_TooShortString_Exception() { string data = "001"; CompositeWrapper.Parse(data, WrapperMap); }
public void Parse_RandomCode_Exception() { string data = Guid.NewGuid().ToString(); var wrappers = CompositeWrapper.Parse(data, new Dictionary<string, Type>()); Assert.IsEmpty(wrappers); }
public void When_WrappedInCompsition_Ignore_Wrapper_Methods_In_Callstack() { //namespace en name of current method const string currentMethodFullName = "NLog.UnitTests.LayoutRenderers.CallSiteTests.When_WrappedInCompsition_Ignore_Wrapper_Methods_In_Callstack"; LogManager.Configuration = CreateConfigurationFromString(@" <nlog> <targets><target name='debug' type='Debug' layout='${callsite}|${message}' /></targets> <rules> <logger name='*' levels='Warn' writeTo='debug' /> </rules> </nlog>"); var logger = LogManager.GetLogger("A"); logger.Warn("direct"); AssertDebugLastMessage("debug", string.Format("{0}|direct", currentMethodFullName)); CompositeWrapper wrappedLogger = new CompositeWrapper(); wrappedLogger.Log("wrapped"); AssertDebugLastMessage("debug", string.Format("{0}|wrapped", currentMethodFullName)); }