Пример #1
0
 /// <summary>
 /// Find discoverer.
 /// </summary>
 /// <param name="service"></param>
 /// <param name="discovererId"></param>
 /// <param name="ct"></param>
 /// <returns></returns>
 public static async Task <DiscovererModel> FindDiscovererAsync(
     this IDiscovererRegistry service, string discovererId,
     CancellationToken ct = default)
 {
     try {
         return(await service.GetDiscovererAsync(discovererId, ct));
     }
     catch (ResourceNotFoundException) {
         return(null);
     }
 }
        public void GetDiscovererThatExists()
        {
            CreateDiscovererFixtures(out _, out var discoverers, out var modules);

            using (var mock = AutoMock.GetLoose()) {
                mock.Provide <IIoTHubTwinServices>(IoTHubServices.Create(modules));
                IDiscovererRegistry service = mock.Create <DiscovererRegistry>();

                // Run
                var result = service.GetDiscovererAsync(discoverers.First().Id).Result;

                // Assert
                Assert.True(result.IsSameAs(discoverers.First()));
            }
        }
        public void GetDiscovererThatDoesNotExist()
        {
            CreateDiscovererFixtures(out _, out _, out var modules);

            using (var mock = AutoMock.GetLoose()) {
                mock.Provide <IIoTHubTwinServices>(IoTHubServices.Create(modules));
                IDiscovererRegistry service = mock.Create <DiscovererRegistry>();

                // Run
                var t = service.GetDiscovererAsync("test");

                // Assert
                Assert.NotNull(t.Exception);
                Assert.IsType <AggregateException>(t.Exception);
                Assert.IsType <ResourceNotFoundException>(t.Exception.InnerException);
            }
        }
Пример #4
0
        public void GetDiscovererThatExists()
        {
            CreateDiscovererFixtures(out _, out var discoverers, out var modules);

            using (var mock = AutoMock.GetLoose(builder => {
                var hub = IoTHubServices.Create(modules);
                builder.RegisterType <NewtonSoftJsonConverters>().As <IJsonSerializerConverterProvider>();
                builder.RegisterType <NewtonSoftJsonSerializer>().As <IJsonSerializer>();
                builder.RegisterInstance(hub).As <IIoTHubTwinServices>();
            })) {
                IDiscovererRegistry service = mock.Create <DiscovererRegistry>();

                // Run
                var result = service.GetDiscovererAsync(discoverers.First().Id).Result;

                // Assert
                Assert.True(result.IsSameAs(discoverers.First()));
            }
        }
Пример #5
0
        public void GetDiscovererThatDoesNotExist()
        {
            CreateDiscovererFixtures(out _, out _, out var modules);

            using (var mock = AutoMock.GetLoose(builder => {
                var hub = IoTHubServices.Create(modules);
                builder.RegisterType <NewtonSoftJsonConverters>().As <IJsonSerializerConverterProvider>();
                builder.RegisterType <NewtonSoftJsonSerializer>().As <IJsonSerializer>();
                builder.RegisterInstance(hub).As <IIoTHubTwinServices>();
            })) {
                IDiscovererRegistry service = mock.Create <DiscovererRegistry>();

                // Run
                var t = service.GetDiscovererAsync("test");

                // Assert
                Assert.NotNull(t.Exception);
                Assert.IsType <AggregateException>(t.Exception);
                Assert.IsType <ResourceNotFoundException>(t.Exception.InnerException);
            }
        }