コード例 #1
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>()));
                }
        }
コード例 #2
0
        public void ConstructorTest()
        {
            PartBindingFactory _newInstance = new PartBindingFactory();

            Assert.ThrowsException <KeyNotFoundException>(() => _newInstance.GetDTO("random name"));
        }