示例#1
0
 public void ProgramFailureTest()
 {
     using (AzureGatewaySemanticEventSource itemToTest = AzureGatewaySemanticEventSource.Log())
         using (EventListener lisner = new EventListener())
         {
             List <EventWrittenEventArgs> eventsList = new List <EventWrittenEventArgs>();
             lisner.EventWritten += (source, entry) => eventsList.Add(entry);
             Assert.AreEqual <int>(0, eventsList.Count);
             lisner.EnableEvents(itemToTest, EventLevel.LogAlways, EventKeywords.All);
             itemToTest.ProgramFailure("ClassName", "problem");
             Assert.AreEqual <int>(1, eventsList.Count);
             EventWrittenEventArgs eventArgs = eventsList[0];
             Assert.AreEqual <int>(1, eventArgs.EventId);
             Assert.AreEqual <string>("At ClassName.ProgramFailureTest encountered application failure: problem", String.Format(eventArgs.Message, eventArgs.Payload.Select <object, string>(x => x.ToString()).ToArray <string>()));
             Assert.AreEqual <EventChannel>(EventChannel.Admin, eventArgs.Channel);
             Assert.AreEqual <int>(1, eventArgs.EventId);
             Assert.AreEqual <string>(nameof(AzureGatewaySemanticEventSource.ProgramFailure), eventArgs.EventName);
             Assert.AreSame(AzureGatewaySemanticEventSource.Log(), eventArgs.EventSource);
             Assert.IsTrue((AzureGatewaySemanticEventSource.Keywords.Diagnostic & eventArgs.Keywords) > 0);
             Assert.AreEqual <EventLevel>(EventLevel.Error, eventArgs.Level);
             Assert.AreEqual <EventOpcode>(EventOpcode.Info, eventArgs.Opcode);
             Assert.AreEqual <EventTask>(AzureGatewaySemanticEventSource.Tasks.Code, eventArgs.Task);
             Assert.AreEqual <byte>(0x01, eventArgs.Version);
         }
 }
示例#2
0
        public void GetConsumerBindingSerializationTest()
        {
            using (AzureGatewaySemanticEventSource log = AzureGatewaySemanticEventSource.Log())
                using (EventListener lisner = new EventListener())
                {
                    //setup log instrumentation
                    List <EventWrittenEventArgs> eventsList = new List <EventWrittenEventArgs>();
                    lisner.EventWritten += (source, entry) => eventsList.Add(entry);
                    Assert.AreEqual <int>(0, eventsList.Count);
                    lisner.EnableEvents(log, EventLevel.LogAlways, EventKeywords.All);

                    PartBindingFactory newInstance    = new PartBindingFactory();
                    string             repositoryName = "RepositoryGroup -tHttp1 -dAzureDeviceId -sAzureScopeId -pAzurePrimaryKey -kAzureSecondaryKey -i2000";
                    IConsumerBinding   binding        = newInstance.GetConsumerBinding(repositoryName, "processValueName", new UATypeInfo(BuiltInType.String));
                    Assert.IsNotNull(binding);
                    binding.Assign2Repository("New value");
                    string dto = newInstance.GetDTO(repositoryName);
                    Debug.Write(dto);
                    Assert.AreEqual <int>(32, dto.Length);
                    Assert.AreEqual <string>("{\"processValueName\":\"New value\"}", dto);
                    Assert.AreEqual <int>(2, eventsList.Count);
                    EventWrittenEventArgs eventArgs = eventsList[0];
                    Assert.AreEqual <string>(nameof(AzureGatewaySemanticEventSource.EnteringMethodBinding), eventArgs.EventName);
                    Assert.AreEqual <string>("Entering method PartBindingFactory.GetConsumerBinding", String.Format(eventArgs.Message, eventArgs.Payload.Select <object, string>(x => x.ToString()).ToArray <string>()));
                    eventArgs = eventsList[1];
                    Assert.AreEqual <string>(nameof(AzureGatewaySemanticEventSource.EnteringMethodBinding), eventArgs.EventName);
                    Assert.AreEqual <string>("Entering method PartBindingFactory.GetDTO", String.Format(eventArgs.Message, eventArgs.Payload.Select <object, string>(x => x.ToString()).ToArray <string>()));
                }
        }
示例#3
0
 public void ConstructorTest()
 {
     using (AzureGatewaySemanticEventSource itemToTest = AzureGatewaySemanticEventSource.Log())
     {
         Assert.IsNotNull(itemToTest);
         Assert.IsNull(itemToTest.ConstructionException);
         Assert.AreEqual <Guid>(Guid.Parse("BC7E8C08-C708-4E3C-A27E-237F093F175C"), itemToTest.Guid);
         Assert.AreEqual <string>("UAOOI.Networking.DataRepository.AzureGateway.Diagnostic", itemToTest.Name);
         Assert.AreEqual <EventSourceSettings>(EventSourceSettings.EtwManifestEventFormat, itemToTest.Settings);
         Assert.IsFalse(itemToTest.IsEnabled());
         Assert.AreSame(itemToTest, AzureGatewaySemanticEventSource.Log());
     }
 }
示例#4
0
 public void DisposeTestMethod()
 {
     try
     {
         AzureGatewaySemanticEventSource itemToTest = AzureGatewaySemanticEventSource.Log();
         itemToTest.Dispose();
         Assert.IsNotNull(itemToTest);
         Assert.AreNotSame(itemToTest, AzureGatewaySemanticEventSource.Log());
     }
     finally
     {
         AzureGatewaySemanticEventSource.Log().Dispose();
     }
 }
示例#5
0
 public void EventListenerTest()
 {
     using (AzureGatewaySemanticEventSource itemToTest = AzureGatewaySemanticEventSource.Log())
         using (EventListener lisner = new EventListener())
         {
             List <EventSourceCreatedEventArgs> sourceList = new List <EventSourceCreatedEventArgs>();
             List <EventWrittenEventArgs>       eventsList = new List <EventWrittenEventArgs>();
             lisner.EventSourceCreated += (o, es) => sourceList.Add(es);
             lisner.EventWritten       += (source, entry) => eventsList.Add(entry);
             foreach (EventSourceCreatedEventArgs item in sourceList)
             {
                 Debug.WriteLine($"{item.EventSource.Name}:{item.EventSource.Guid}; Is enabled: {item.EventSource.IsEnabled()}");
             }
             int esCount = sourceList.Count;
             Assert.AreEqual <int>(0, eventsList.Count);
             lisner.EnableEvents(itemToTest, EventLevel.LogAlways, EventKeywords.All);
             Assert.AreEqual <int>(esCount, sourceList.Count);
             Assert.AreEqual <int>(0, eventsList.Count);
         }
 }
示例#6
0
 public void GetProducerBindingTest()
 {
     using (AzureGatewaySemanticEventSource log = AzureGatewaySemanticEventSource.Log())
         using (EventListener lisner = new EventListener())
         {
             //setup log instrumentation
             List <EventWrittenEventArgs> eventsList = new List <EventWrittenEventArgs>();
             lisner.EventWritten += (source, entry) => eventsList.Add(entry);
             Assert.AreEqual <int>(0, eventsList.Count);
             lisner.EnableEvents(log, EventLevel.LogAlways, EventKeywords.All);
             //start testing
             PartBindingFactory newInstance = new PartBindingFactory();
             Assert.ThrowsException <NotImplementedException>(() => newInstance.GetProducerBinding("any repository random name", "any process variable random name", new UATypeInfo(BuiltInType.String)));
             //examine the results
             Assert.AreEqual <int>(1, eventsList.Count);
             EventWrittenEventArgs eventArgs = eventsList[0];
             Assert.AreEqual <string>(nameof(AzureGatewaySemanticEventSource.EnteringMethodBinding), eventArgs.EventName);
             Assert.AreEqual <string>("Entering method PartBindingFactory.GetProducerBinding", String.Format(eventArgs.Message, eventArgs.Payload.Select <object, string>(x => x.ToString()).ToArray <string>()));
         }
 }