Exemple #1
0
        public async Task TestViewModel()
        {
            // Read 'appSettings.json' for endpoint configuration
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appSettings.json", true)
                         .Build();

            var app = new UaApplicationBuilder()
                      .SetApplicationUri($"urn:{Dns.GetHostName()}:Workstation.UaClient.UnitTests")
                      .SetDirectoryStore(Path.Combine(
                                             Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                             "Workstation.UaClient.UnitTests",
                                             "pki"))
                      .SetIdentity(new UserNameIdentity("root", "secret"))
                      .AddMappedEndpoints(config)
                      .SetLoggerFactory(loggerFactory)
                      .ConfigureOptions(o => o.SessionTimeout = 30000)
                      .Build();

            app.Run();

            var vm = new MyViewModel();

            void onPropertyChanged(object s, PropertyChangedEventArgs e)
            {
            }

            vm.PropertyChanged += onPropertyChanged; // simulate xaml binding

            logger.LogInformation($"Created subscription.");

            await Task.Delay(5000);

            vm.PropertyChanged -= onPropertyChanged; // simulate un-binding
            app.Dispose();

            vm.CurrentTime
            .Should().NotBe(DateTime.MinValue);
            vm.CurrentTimeAsDataValue
            .Should().NotBeNull();
            vm.CurrentTimeQueue
            .Should().NotBeEmpty();
            vm.DemoStaticArraysVector
            .Should().NotBeEmpty();
            vm.VectorsAsObjects
            .Should().NotBeEmpty();
        }
        public async Task TestViewModel()
        {
            // Read 'appSettings.json' for endpoint configuration
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appSettings.json", true)
                         .Build();

            var app = new UaApplicationBuilder()
                      .SetApplicationUri($"urn:{Dns.GetHostName()}:Workstation.UaClient.UnitTests")
                      .SetDirectoryStore(Path.Combine(
                                             Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                             "Workstation.UaClient.UnitTests",
                                             "pki"))
                      .SetIdentity(new UserNameIdentity("root", "secret"))
                      .AddMappedEndpoints(config)
                      .SetLoggerFactory(this.loggerFactory)
                      .ConfigureOptions(o => o.SessionTimeout = 30000)
                      .Build();

            app.Run();

            var vm = new MyViewModel();
            // simulate a view <-> view-model
            var d = new PropertyChangedEventHandler((s, e) => { });

            vm.PropertyChanged += d;

            Console.WriteLine($"Created subscription.");

            await Task.Delay(5000);

            vm.PropertyChanged -= d;
            app.Dispose();

            vm.CurrentTime
            .Should().NotBe(DateTime.MinValue);
            vm.CurrentTimeAsDataValue
            .Should().NotBeNull();
            vm.CurrentTimeQueue
            .Should().NotBeEmpty();
        }
Exemple #3
0
        public async Task TestSubscription()
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appSettings.json", true)
                         .Build();

            var app = new UaApplicationBuilder()
                      .UseApplicationUri($"urn:{Dns.GetHostName()}:Workstation.UaClient.UnitTests")
                      .UseDirectoryStore(Path.Combine(
                                             Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                                             "Workstation.UaClient.UnitTests",
                                             "pki"))
                      .UseIdentity(new UserNameIdentity("root", "secret"))
                      .UseLoggerFactory(this.loggerFactory)
                      .Map(config)
                      .Build();

            app.Run();

            var sub = new MySubscription();
            var d   = new PropertyChangedEventHandler((s, e) => { });

            sub.PropertyChanged += d;

            Console.WriteLine($"Created subscription.");

            await Task.Delay(10000);

            sub.PropertyChanged -= d;
            await Task.Delay(5000);

            app.Dispose();

            Assert.IsTrue(sub.CurrentTime != DateTime.MinValue, "CurrentTime");
            Assert.IsTrue(sub.CurrentTimeAsDataValue != null, "CurrentTimeAsDataValue");
            Assert.IsTrue(sub.CurrentTimeQueue.Count > 0, "CurrentTimeQueue");
        }