public void WriteError_ValueAsFormat_ShouldWriteFormatToTraceListener() { using (var context = new TraceContext(SourceLevels.Error)) { var expectations = Expectations.GetExceptionMessages(); foreach (var e in expectations) { CompositionTraceSource.WriteError(0, e, "arguments"); Assert.AreEqual(e, context.LastTraceEvent.Format); } } }
public void WriteError_ValueAsArgs_ShouldWriteArgsToTraceListener() { using (var context = new TraceContext(SourceLevels.Error)) { var expectations = Expectations.GetObjectArraysWithNull(); foreach (var e in expectations) { CompositionTraceSource.WriteError(0, "format", e); Assert.AreSame(e, context.LastTraceEvent.Args); } } }
public void WriteError_ValueAsTraceId_ShouldWriteIdToTraceListener() { using (var context = new TraceContext(SourceLevels.Error)) { var expectations = Expectations.GetEnumValues <CompositionTraceId>(); foreach (var e in expectations) { CompositionTraceSource.WriteError(e, "format", "arguments"); Assert.AreEqual(e, (CompositionTraceId)context.LastTraceEvent.Id); } } }
public void WriteError_WhenSwitchLevelGreaterThanOrEqualToError_ShouldWriteToTraceListener() { var levels = GetSourceLevelsGreaterThanOrEqualTo(SourceLevels.Error); foreach (var level in levels) { using (TraceContext context = new TraceContext(level)) { CompositionTraceSource.WriteError(0, "format", "arguments"); Assert.IsNotNull(context.LastTraceEvent); } } }
public void WriteError_WhenSwitchLevelLessThanError_ShouldThrowInternalError() { var levels = GetSourceLevelsLessThan(SourceLevels.Error); foreach (var level in levels) { using (TraceContext context = new TraceContext(level)) { ThrowsInternalError(() => { CompositionTraceSource.WriteError(0, "format", "arguments"); }); } } }
public void GetExports_WhenDefinitionIsResurrected_ShouldTraceInformation() { using (TraceContext context = new TraceContext(SourceLevels.Information)) { var part = PartFactory.CreateImporterExporter("Export", "Import"); var sourceProvider = ExportProviderFactory.CreateRecomposable(); var provider = CreateCatalogExportProvider(part); provider.SourceProvider = sourceProvider; ExceptionAssert.Throws<ImportCardinalityMismatchException>(() => { provider.GetExport<object>("Export"); }); // Add the required export to the source provider 'resurrect' the part sourceProvider.AddExport("Import", "Value"); provider.GetExport<object>("Export"); Assert.IsNotNull(context.LastTraceEvent); Assert.AreEqual(context.LastTraceEvent.EventType, TraceEventType.Information); Assert.AreEqual(context.LastTraceEvent.Id, TraceId.Rejection_DefinitionResurrected); } }
public void GetExports_WhenDefinitionIsRejected_ShouldTraceWarning() { using (TraceContext context = new TraceContext(SourceLevels.Warning)) { var part = PartFactory.CreateImporterExporter("Export", "Import"); var provider = CreateCatalogExportProvider(part); provider.SourceProvider = ExportProviderFactory.CreateRecomposable(); ExceptionAssert.Throws<ImportCardinalityMismatchException>(() => { provider.GetExport<object>("Export"); }); Assert.IsNotNull(context.LastTraceEvent); Assert.AreEqual(context.LastTraceEvent.EventType, TraceEventType.Warning); Assert.AreEqual(context.LastTraceEvent.Id, TraceId.Rejection_DefinitionRejected); } }
public void WriteError_ValueAsTraceId_ShouldWriteIdToTraceListener() { using (var context = new TraceContext(SourceLevels.Error)) { var expectations = Expectations.GetEnumValues<CompositionTraceId>(); foreach (var e in expectations) { CompositionTraceSource.WriteError(e, "format", "arguments"); Assert.AreEqual(e, (CompositionTraceId)context.LastTraceEvent.Id); } } }
public void WriteError_ShouldWriteCorrectSourceToTraceListener() { using (var context = new TraceContext(SourceLevels.Error)) { CompositionTraceSource.WriteError(0, "format", "arguments"); Assert.AreEqual("System.ComponentModel.Composition", context.LastTraceEvent.Source); } }
public void WriteError_ShouldWriteTraceEventTypeWarningToTraceListener() { using (var context = new TraceContext(SourceLevels.Error)) { CompositionTraceSource.WriteError(0, "format", "arguments"); Assert.AreEqual(TraceEventType.Error, context.LastTraceEvent.EventType); } }
public void WriteInformation_ShouldWriteTraceEventTypeInformationToTraceListener() { using (var context = new TraceContext(SourceLevels.Information)) { CompositionTraceSource.WriteInformation(0, "format", "arguments"); Assert.AreEqual(TraceEventType.Information, context.LastTraceEvent.EventType); } }
public void GetExports_WhenDefinitionsAreResurrected_ShouldTraceInformation() { using (TraceContext context = new TraceContext(SourceLevels.Information)) { var part1 = PartFactory.CreateImporterExporter("Export", "Import"); var part2 = PartFactory.CreateImporterExporter("Export", "Import"); var sourceProvider = ExportProviderFactory.CreateRecomposable(); var provider = CreateCatalogExportProvider(part1, part2); provider.SourceProvider = sourceProvider; EnumerableAssert.IsEmpty(provider.GetExports<object>("Export")); // Add the required export to the source provider 'resurrect' the part sourceProvider.AddExport("Import", "Value"); provider.GetExports<object>("Export"); Assert.AreEqual(4, context.TraceEvents.Count); // 2 for rejection, 2 for resurrection Assert.AreEqual(context.TraceEvents[2].EventType, TraceEventType.Information); Assert.AreEqual(context.TraceEvents[3].EventType, TraceEventType.Information); Assert.AreEqual(context.TraceEvents[2].Id, TraceId.Rejection_DefinitionResurrected); Assert.AreEqual(context.TraceEvents[3].Id, TraceId.Rejection_DefinitionResurrected); } }
public void ImportDefinitions_TypeWithMemberMarkedWithMultipleImports_ShouldTraceError() { var types = new Type[] { typeof(ClassWithMultipleParameterImports), typeof(ClassWithMultipleFieldImports), typeof(ClassWithMultiplePropertyImports), typeof(ClassWithMultipleCustomPropertyImports), typeof(ClassWithMultipleCustomPropertyImportManys), typeof(ClassWithMultipleCustomPropertyImportAndImportManys)}; foreach (Type type in types) { using (TraceContext context = new TraceContext(SourceLevels.Error)) { var definition = AttributedModelServices.CreatePartDefinition(type, null, true); definition.ImportDefinitions.Count(); Assert.IsNotNull(context.LastTraceEvent); Assert.AreEqual(context.LastTraceEvent.EventType, TraceEventType.Error); Assert.AreEqual(context.LastTraceEvent.Id, TraceId.Discovery_MemberMarkedWithMultipleImportAndImportMany); } } }