public async Task SmokeTest() { var store1 = new RouteStore(); RouterConfig config = await store1.GetRouterConfigAsync("hub", CancellationToken.None); Assert.Equal(0, config.Routes.Count); Endpoint endpoint1 = new NullEndpoint("endpoint1"); Endpoint endpoint2 = new NullEndpoint("endpoint2"); IEnumerable <Endpoint> allEndpoints = new List <Endpoint> { endpoint1, endpoint2 }; var route1 = new Route("id1", "true", "hub", TelemetryMessageSource.Instance, new HashSet <Endpoint> { endpoint1 }); var route2 = new Route("id2", "false", "hub", TelemetryMessageSource.Instance, new HashSet <Endpoint> { endpoint2 }); IEnumerable <Route> allRoutes = new List <Route> { route1, route2 }; var store2 = new RouteStore( new Dictionary <string, RouterConfig> { { "hub", new RouterConfig(allEndpoints, allRoutes) } }); RouterConfig config2 = await store2.GetRouterConfigAsync("hub", CancellationToken.None); Assert.True(config2.Routes.SetEquals(new HashSet <Route> { route1, route2 })); RouterConfig config3 = await store2.GetRouterConfigAsync("hub2", CancellationToken.None); Assert.Equal(0, config3.Routes.Count); }
public async Task ProcessDeviceMessageBatch_ConvertsMessages() { // Create a mock endpoint capable of returning a mock processor var processor = Mock.Of <IProcessor>(); var endpoint = new Mock <Endpoint>("myId"); endpoint.Setup(ep => ep.CreateProcessor()).Returns(processor); endpoint.SetupGet(ep => ep.Id).Returns("myId"); // Create a mock endpoint executor factory to create the endpoint executor to verify invocation var endpointExecutor = Mock.Of <IEndpointExecutor>(); Mock.Get(endpointExecutor).SetupGet(ee => ee.Endpoint).Returns(() => endpoint.Object); var endpointExecutorFactory = Mock.Of <IEndpointExecutorFactory>(); Mock.Get(endpointExecutorFactory).Setup(eef => eef.CreateAsync(It.IsAny <Endpoint>(), new List <uint>() { 0 })).ReturnsAsync(endpointExecutor); // Create a route to map to the message var route = new Route("myRoute", "true", "myIotHub", TelemetryMessageSource.Instance, endpoint.Object, 0, 3600); // Create a router var routerConfig = new RouterConfig(new[] { route }); Router router = await Router.CreateAsync("myRouter", "myIotHub", routerConfig, endpointExecutorFactory); // Create mock message converter to generate a message with source matching the route var message = Mock.Of <Devices.Routing.Core.IMessage>(); Mock.Get(message).SetupGet(m => m.MessageSource).Returns(() => TelemetryMessageSource.Instance); var messageConverter = Mock.Of <Core.IMessageConverter <Devices.Routing.Core.IMessage> >(); Mock.Get(messageConverter).Setup(mc => mc.FromMessage(It.IsAny <IMessage>())).Returns(message); // Create mock for IConnectionManager var connectionManager = Mock.Of <IConnectionManager>(); // Mock of twin manager var twinManager = Mock.Of <ITwinManager>(); // Test Scenario var routingEdgeHub = new RoutingEdgeHub( router, messageConverter, connectionManager, twinManager, "testEdgeDevice", Mock.Of <IInvokeMethodHandler>(), Mock.Of <ISubscriptionProcessor>(), Mock.Of <IDeviceScopeIdentitiesCache>()); var identity = new Mock <IIdentity>(); identity.SetupGet(id => id.Id).Returns("something"); EdgeMessage[] messages = { new EdgeMessage.Builder(new byte[0]).Build() }; await routingEdgeHub.ProcessDeviceMessageBatch(identity.Object, messages); // Verify Expectation Mock.Get(endpointExecutor).Verify(e => e.Invoke(It.IsAny <Devices.Routing.Core.IMessage>(), 0, 3600), Times.Once); }
/// <summary> /// Creates a new <see cref="Akka.Actor.Props" /> with a given router. /// /// <note> /// This method is immutable and returns a new instance of <see cref="Akka.Actor.Props" />. /// </note> /// </summary> /// <param name="routerConfig">The router used when deploying the actor.</param> /// <returns>A new <see cref="Akka.Actor.Props" /> with the provided <paramref name="routerConfig" />.</returns> public Props WithRouter(RouterConfig routerConfig) { Props copy = Copy(); copy.Deploy = Deploy.WithRouterConfig(routerConfig); return(copy); }
async Task UpdateEvaluatorAsync(string hubName) { try { bool shouldClose; Evaluator oldEvaluator; using (await this.sync.LockAsync(this.cts.Token)) { ImmutableDictionary <string, Evaluator> snapshot = this.Evaluators; RouterConfig config = await this.routeStore.GetRouterConfigAsync(hubName, this.cts.Token); // Close the current evaluator shouldClose = snapshot.TryGetValue(hubName, out oldEvaluator); var newEvaluator = new Evaluator(config); bool evaluatorIsSet = this.evaluators.CompareAndSet(snapshot, snapshot.SetItem(hubName, newEvaluator)); Debug.Assert(evaluatorIsSet); } if (shouldClose) { await oldEvaluator.CloseAsync(this.cts.Token); } } catch (Exception ex) when(!ex.IsFatal()) { Events.EvaluatorUpdateFailed(ex); } }
static async Task <RoutingEdgeHub> GetTestEdgeHub(IConnectionManager connectionManager = null) { // Arrange connectionManager = connectionManager ?? Mock.Of <IConnectionManager>(); var endpoint = new Mock <Endpoint>("myId"); var endpointExecutor = Mock.Of <IEndpointExecutor>(); Mock.Get(endpointExecutor).SetupGet(ee => ee.Endpoint).Returns(() => endpoint.Object); var endpointExecutorFactory = Mock.Of <IEndpointExecutorFactory>(); Mock.Get(endpointExecutorFactory).Setup(eef => eef.CreateAsync(It.IsAny <Endpoint>())).ReturnsAsync(endpointExecutor); // Create a route to map to the message var endpoints = new HashSet <Endpoint> { endpoint.Object }; var route = new Route("myRoute", "true", "myIotHub", TelemetryMessageSource.Instance, endpoints); // Create a router var routerConfig = new RouterConfig(new[] { route }); Router router = await Router.CreateAsync("myRouter", "myIotHub", routerConfig, endpointExecutorFactory); var edgeHub = new RoutingEdgeHub( router, Mock.Of <Core.IMessageConverter <Devices.Routing.Core.IMessage> >(), connectionManager, Mock.Of <ITwinManager>(), "ed1", Mock.Of <IInvokeMethodHandler>(), Mock.Of <ISubscriptionProcessor>()); return(edgeHub); }
public Deploy WithRouterConfig(RouterConfig routerConfig) { var copy = Copy(); copy.RouterConfig = routerConfig; return(copy); }
public async Task Test_NavigateBackWhileAction_Causes_Rotuer_To_Navigate_Backwards_While_The_Func_Is_True() { Resolver.Register(() => new TestViewModel(), typeof(TestViewModel)); var navigator = new Navigator(); Router = new Router(navigator); var initParams = new RouterConfig() { ViewModelMap = new Dictionary <Type, RouteActions>() { { typeof(TestViewModel), new RouteActions() { Actions = new[] { RouteActions.NavigateBackWhile(transition => transition.ViewModel is TestViewModel), RouteActions.Navigate() } } } } }; await Router.InitAsync(initParams); await Router.ShowAsync <TestViewModel, TestParams>(); await Router.ShowAsync <TestViewModel, TestParams>(); Assert.Collection(navigator.TransitionStack, t => t.ViewModel.Should().BeAssignableTo <TestViewModel>()); }
public async Task Test_Router_Presents_Transition_Resolved_From_OnTransition() { var viewModel = new TestViewModel(); var subject = new Subject <TransitionEvent>(); IPresenter presenter = Substitute.For <IPresenter>(); Locator.CurrentMutable.Register(() => presenter, typeof(TestPresenterType)); Locator.CurrentMutable.Register(() => viewModel, typeof(TestViewModel)); var initParams = new RouterConfig() { ViewModelMap = new Dictionary <Type, RouteActions>() { { typeof(TestViewModel), new RouteActions() { Actions = new IRouteAction[] { RouteActions.Navigate(), RouteActions.Present(typeof(TestPresenterType)) } } } } }; Navigator.OnTransition.Returns(subject); await Router.InitAsync(initParams); Router.ShowAsync <TestViewModel, TestParams>(); presenter.Received(1).PresentAsync(viewModel, null); }
public async Task Test_NavigateBackAction_Causes_Router_To_Navigate_Backwards() { Resolver.Register(() => new TestViewModel(), typeof(TestViewModel)); var initParams = new RouterConfig() { ViewModelMap = new Dictionary <Type, RouteActions>() { { typeof(TestViewModel), new RouteActions() { Actions = new IRouteAction[] { RouteActions.Navigate() } } } } }; await Router.InitAsync(initParams); await Router.ShowAsync <TestViewModel, TestParams>(); await Router.BackAsync(); Navigator.Received(1).PopAsync(); }
public async Task Test_ShowAsync_Creates_Presenter_If_Router_Actions_Specify_Present() { Func <TestPresenterType> presenterConstructor = Substitute.For <Func <TestPresenterType> >(); presenterConstructor().Returns(new TestPresenterType()); Locator.CurrentMutable.Register(() => new TestViewModel(), typeof(TestViewModel)); Locator.CurrentMutable.Register(presenterConstructor, typeof(TestPresenterType)); var initParams = new RouterConfig() { ViewModelMap = new Dictionary <Type, RouteActions>() { { typeof(TestViewModel), new RouteActions() { Actions = new IRouteAction[] { RouteActions.Present(typeof(TestPresenterType)) } } } } }; await Router.InitAsync(initParams); await Router.ShowAsync(typeof(TestViewModel), new TestParams()); presenterConstructor.Received(1)(); }
async Task <Evaluator> GetEvaluatorAsync(string hubName) { ImmutableDictionary <string, Evaluator> snapshot = this.Evaluators; Evaluator evaluator; if (!snapshot.TryGetValue(hubName, out evaluator)) { using (await this.sync.LockAsync(this.cts.Token)) { snapshot = this.Evaluators; if (!snapshot.TryGetValue(hubName, out evaluator)) { RouterConfig config = await this.routeStore.GetRouterConfigAsync(hubName, this.cts.Token); evaluator = new Evaluator(config, this.compiler); bool evaluatorIsSet = this.evaluators.CompareAndSet(snapshot, snapshot.Add(hubName, evaluator)); Debug.Assert(evaluatorIsSet); // Setup to be notified of changes to the hub for this evaluator INotifier notifier; if (!this.Notifiers.TryGetValue(hubName, out notifier)) { notifier = this.notifierFactory.Create(hubName); await notifier.SubscribeAsync(nameof(FilteringRoutingService), this.UpdateEvaluatorAsync, this.RemoveEvaluatorAsync, this.cts.Token); bool notifierIsSet = this.notifiers.CompareAndSet(this.Notifiers, this.Notifiers.Add(hubName, notifier)); Debug.Assert(notifierIsSet); } } } } return(evaluator); }
public async Task EdgeHubChecksMessageSize() { // Create a mock endpoint capable of returning a mock processor var processor = Mock.Of <IProcessor>(); var endpoint = new Mock <Endpoint>("myId"); endpoint.Setup(ep => ep.CreateProcessor()).Returns(processor); endpoint.SetupGet(ep => ep.Id).Returns("myId"); // Create a mock endpoint executor factory to create the endpoint executor to verify invocation var endpointExecutor = Mock.Of <IEndpointExecutor>(); Mock.Get(endpointExecutor).SetupGet(ee => ee.Endpoint).Returns(() => endpoint.Object); var endpointExecutorFactory = Mock.Of <IEndpointExecutorFactory>(); Mock.Get(endpointExecutorFactory).Setup(eef => eef.CreateAsync(It.IsAny <Endpoint>())).ReturnsAsync(endpointExecutor); // Create a route to map to the message var endpoints = new HashSet <Endpoint> { endpoint.Object }; var route = new Route("myRoute", "true", "myIotHub", TelemetryMessageSource.Instance, endpoints); // Create a router var routerConfig = new RouterConfig(new[] { route }); Router router = await Router.CreateAsync("myRouter", "myIotHub", routerConfig, endpointExecutorFactory); // Create mock for IConnectionManager var connectionManager = Mock.Of <IConnectionManager>(); // Mock of twin manager var twinManager = Mock.Of <ITwinManager>(); // Mock of identity var identity = new Mock <IIdentity>(); identity.SetupGet(id => id.Id).Returns("something"); var messageConverter = new RoutingMessageConverter(); Message badMessage = new Message.Builder(new byte[300 * 1024]).Build(); var routingEdgeHub = new RoutingEdgeHub(router, messageConverter, connectionManager, twinManager, "testEdgeDevice", Mock.Of <IInvokeMethodHandler>()); await Assert.ThrowsAsync <InvalidOperationException>(() => routingEdgeHub.ProcessDeviceMessage(identity.Object, badMessage)); string badString = System.Text.Encoding.UTF8.GetString(new byte[300 * 1024], 0, 300 * 1024); var badProperties = new Dictionary <string, string> { ["toolong"] = badString }; badMessage = new Message.Builder(new byte[1]).SetProperties(badProperties).Build(); await Assert.ThrowsAsync <InvalidOperationException>(() => routingEdgeHub.ProcessDeviceMessage(identity.Object, badMessage)); badMessage = new Message(new byte[1], new Dictionary <string, string>(), badProperties); await Assert.ThrowsAsync <InvalidOperationException>(() => routingEdgeHub.ProcessDeviceMessage(identity.Object, badMessage)); }
public async Task TestInitialConfigUpdate_WaitForInit() { // Arrange string id = "id"; string iotHub = "foo.azure-devices.net"; var routerConfig = new RouterConfig(Enumerable.Empty <Route>()); var messageStore = new Mock <IMessageStore>(); messageStore.Setup(m => m.SetTimeToLive(It.IsAny <TimeSpan>())); var storageSpaceChecker = new Mock <IStorageSpaceChecker>(); storageSpaceChecker.Setup(m => m.SetMaxSizeBytes(It.IsAny <Option <long> >())); TimeSpan updateFrequency = TimeSpan.FromSeconds(10); Endpoint GetEndpoint() => new ModuleEndpoint("id", Guid.NewGuid().ToString(), "in1", Mock.Of <IConnectionManager>(), Mock.Of <Core.IMessageConverter <IMessage> >()); var endpointFactory = new Mock <IEndpointFactory>(); endpointFactory.Setup(e => e.CreateSystemEndpoint($"$upstream")).Returns(GetEndpoint); var routeFactory = new EdgeRouteFactory(endpointFactory.Object); var endpointExecutorFactory = new Mock <IEndpointExecutorFactory>(); endpointExecutorFactory.Setup(e => e.CreateAsync(It.IsAny <Endpoint>(), It.IsAny <IList <uint> >(), It.IsAny <ICheckpointerFactory>())) .Returns <Endpoint, IList <uint>, ICheckpointerFactory>((endpoint, priorities, checkpointerFactory) => Task.FromResult(Mock.Of <IEndpointExecutor>(e => e.Endpoint == endpoint))); Router router = await Router.CreateAsync(id, iotHub, routerConfig, endpointExecutorFactory.Object); var routes1 = Routes.Take(2) .ToDictionary(r => r.Key, r => new RouteConfig(r.Key, r.Value, routeFactory.Create(r.Value))); var storeAndForwardConfiguration1 = new StoreAndForwardConfiguration(7200); var edgeHubConfig1 = new EdgeHubConfig("1.0", routes1, storeAndForwardConfiguration1, Option.None <BrokerConfig>(), Option.None <ManifestIntegrity>()); var configProvider = new Mock <IConfigSource>(); configProvider.SetupSequence(c => c.GetConfig()) .Returns(async() => { await Task.Delay(5000); return(Option.Some(edgeHubConfig1)); }); configProvider.Setup(c => c.GetCachedConfig()) .Returns(() => Task.FromResult(Option.None <EdgeHubConfig>())); // Act var configUpdater = new ConfigUpdater(router, messageStore.Object, updateFrequency, storageSpaceChecker.Object); await configUpdater.Init(configProvider.Object); // Assert Assert.Equal(2, router.Routes.Count); // After 6 seconds no updates await Task.Delay(TimeSpan.FromSeconds(6)); Assert.Equal(2, router.Routes.Count); }
internal HandlerEntry(string method, string path, Handler handler, RouterConfig config) { Method = method; Path = path; Handle = handler; Config = config; PathParser = new PathParser(path, config.IgnoreTrailingSlashes); }
public Deploy(string path, Config config, RouterConfig routerConfig, Scope scope, string dispatcher) { Path = path; Config = config; RouterConfig = routerConfig; Scope = scope ?? NoScopeGiven; Dispatcher = dispatcher ?? NoDispatcherGiven; }
protected void Application_Start(object sender, EventArgs e) { RouterConfig.AddConfigRouteAdmin(RouteTable.Routes); RouterConfig.AddConfigRouteCommon(RouteTable.Routes); RouterConfig.AddConfigRouteAjax(RouteTable.Routes); }
public Deploy(string path, Config config, RouterConfig routerConfig, Scope scope, string dispatcher) { Path = path; Config = config; RouterConfig = routerConfig; Scope = scope; Dispatcher = dispatcher; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouterConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
/// <summary> /// Initializes a new instance of the <see cref="Deploy"/> class. /// </summary> public Deploy() { _path = ""; _config = ConfigurationFactory.Empty; _routerConfig = NoRouter.Instance; _scope = NoScopeGiven; _dispatcher = NoDispatcherGiven; _mailbox = NoMailboxGiven; }
public async Task AddEdgeSystemPropertiesTest() { // Create a mock endpoint capable of returning a mock processor var endpoint = new Mock <Endpoint>("myId"); // Create a mock endpoint executor factory to create the endpoint executor to verify invocation var endpointExecutor = Mock.Of <IEndpointExecutor>(); Mock.Get(endpointExecutor).SetupGet(ee => ee.Endpoint).Returns(() => endpoint.Object); var endpointExecutorFactory = Mock.Of <IEndpointExecutorFactory>(); Mock.Get(endpointExecutorFactory).Setup(eef => eef.CreateAsync(It.IsAny <Endpoint>())).ReturnsAsync(endpointExecutor); // Create a route to map to the message var endpoints = new HashSet <Endpoint> { endpoint.Object }; var route = new Route("myRoute", "true", "myIotHub", TelemetryMessageSource.Instance, endpoints); // Create a router var routerConfig = new RouterConfig(new[] { route }); Router router = await Router.CreateAsync("myRouter", "myIotHub", routerConfig, endpointExecutorFactory); var messageConverter = Mock.Of <Core.IMessageConverter <IMessage> >(); // Create mock for IConnectionManager var connectionManager = Mock.Of <IConnectionManager>(); // Mock of twin manager var twinManager = Mock.Of <ITwinManager>(); string edgeDeviceId = "testEdgeDevice"; // Test Scenario var routingEdgeHub = new RoutingEdgeHub(router, messageConverter, connectionManager, twinManager, edgeDeviceId); Message clientMessage1 = new Message.Builder(new byte[0]).Build(); clientMessage1.SystemProperties[Core.SystemProperties.ConnectionDeviceId] = edgeDeviceId; routingEdgeHub.AddEdgeSystemProperties(clientMessage1); Assert.True(clientMessage1.SystemProperties.ContainsKey(Core.SystemProperties.EdgeHubOriginInterface)); Assert.True(clientMessage1.SystemProperties.ContainsKey(Core.SystemProperties.EdgeMessageId)); Assert.Equal(Core.Constants.InternalOriginInterface, clientMessage1.SystemProperties[Core.SystemProperties.EdgeHubOriginInterface]); Message clientMessage2 = new Message.Builder(new byte[0]).Build(); clientMessage2.SystemProperties[Core.SystemProperties.ConnectionDeviceId] = "downstreamDevice"; routingEdgeHub.AddEdgeSystemProperties(clientMessage2); Assert.True(clientMessage2.SystemProperties.ContainsKey(Core.SystemProperties.EdgeHubOriginInterface)); Assert.True(clientMessage2.SystemProperties.ContainsKey(Core.SystemProperties.EdgeMessageId)); Assert.Equal(Core.Constants.DownstreamOriginInterface, clientMessage2.SystemProperties[Core.SystemProperties.EdgeHubOriginInterface]); Message clientMessage3 = new Message.Builder(new byte[0]).Build(); routingEdgeHub.AddEdgeSystemProperties(clientMessage3); Assert.False(clientMessage3.SystemProperties.ContainsKey(Core.SystemProperties.EdgeHubOriginInterface)); Assert.True(clientMessage3.SystemProperties.ContainsKey(Core.SystemProperties.EdgeMessageId)); }
/// <summary> /// Initializes a new instance of the <see cref="Deploy"/> class. /// </summary> /// <param name="path">The path to deploy the actor.</param> /// <param name="config">The configuration used when deploying the actor.</param> /// <param name="routerConfig">The router used in this deployment.</param> /// <param name="scope">The scope to bind to this deployment.</param> /// <param name="dispatcher">The dispatcher used in this deployment.</param> public Deploy(string path, Config config, RouterConfig routerConfig, Scope scope, string dispatcher) : this() { _path = path; _config = config; _routerConfig = routerConfig; _scope = scope ?? NoScopeGiven; _dispatcher = dispatcher ?? NoDispatcherGiven; }
public Deploy(string path, Config config, RouterConfig routerConfig, Scope scope, string dispatcher, string mailbox) : this() { Path = path; Config = config; RouterConfig = routerConfig; Scope = scope ?? NoScopeGiven; Dispatcher = dispatcher ?? NoDispatcherGiven; Mailbox = mailbox ?? NoMailboxGiven; }
private IActorRef CreateActor(Type actorType, RouterConfig routeConfig, string actorName) { var handleActorProps = Context.System.DI().Props(actorType); handleActorProps = handleActorProps.WithRouter(routeConfig); var handleActor = Context.System.ActorOf(handleActorProps, actorName); return(handleActor); }
public async Task Test_StartAsync_Calls_InitAsync_On_IRouter() { var router = Substitute.For <IRouter>(); var routerParams = new RouterConfig(); Register(routerParams); Register(Substitute.For <IObjectStateStore>()); Register(router); await AppHost.StartAsync(); ((IActivatable)router).Received(1).InitAsync(routerParams); }
/// <summary> /// Creates a new <see cref="Akka.Actor.Deploy" /> from this deployment using another <see cref="Akka.Actor.Deploy" /> /// to backfill options that might be missing from this deployment. /// /// <note> /// This method is immutable and returns a new instance of <see cref="Akka.Actor.Deploy" />. /// </note> /// </summary> /// <param name="other">The <see cref="Akka.Actor.Deploy" /> used for fallback configuration.</param> /// <returns>A new <see cref="Akka.Actor.Deploy" /> using <paramref name="other" /> for fallback configuration.</returns> public Deploy WithFallback(Deploy other) { return(new Deploy ( Path, Config.Equals(other.Config) ? Config: Config.WithFallback(other.Config), RouterConfig.WithFallback(other.RouterConfig), Scope.WithFallback(other.Scope), Dispatcher == NoDispatcherGiven ? other.Dispatcher : Dispatcher, Mailbox == NoMailboxGiven ? other.Mailbox : Mailbox )); }
/// <summary> /// Creates a new <see cref="Akka.Actor.Deploy" /> with a given <see cref="Akka.Routing.RouterConfig" />. /// /// <note> /// This method is immutable and returns a new instance of <see cref="Akka.Actor.Deploy" />. /// </note> /// </summary> /// <param name="routerConfig">The <see cref="Akka.Routing.RouterConfig" /> used to configure the new <see cref="Akka.Actor.Deploy" />.</param> /// <returns>A new <see cref="Akka.Actor.Deploy" /> with the provided <paramref name="routerConfig" />.</returns> public Deploy WithRouterConfig(RouterConfig routerConfig) { return(new Deploy ( Path, Config, routerConfig, Scope, Dispatcher, Mailbox )); }
private void AssertRouting(string service, RouterConfig expected, string expectPath) { var deployment = ((ActorSystemImpl)Sys).Provider.Deployer.Lookup(service.Split('/').Drop(1)); Assert.Equal(expectPath, deployment.Path); Assert.Equal(expected.GetType(), deployment.RouterConfig.GetType()); Assert.Equal(Deploy.NoScopeGiven, deployment.Scope); if (expected is Pool pool) { Assert.Equal(pool.Resizer, ((Pool)deployment.RouterConfig).Resizer); } }
public Deploy WithFallback(Deploy other) { return(new Deploy { Path = Path, Config = Config.WithFallback(other.Config), RouterConfig = RouterConfig.WithFallback(other.RouterConfig), Scope = Scope.WithFallback(other.Scope), Dispatcher = Dispatcher == NoDispatcherGiven ? other.Dispatcher : Dispatcher, Mailbox = Mailbox == NoMailboxGiven ? other.Mailbox : Mailbox, }); }
public bool Equals(Deploy other) { if (other == null) { return(false); } return(((string.IsNullOrEmpty(Mailbox) && string.IsNullOrEmpty(other.Mailbox)) || string.Equals(Mailbox, other.Mailbox)) && string.Equals(Dispatcher, other.Dispatcher) && string.Equals(Path, other.Path) && RouterConfig.Equals(other.RouterConfig) && ((Config.IsNullOrEmpty() && other.Config.IsNullOrEmpty()) || Config.ToString().Equals(other.Config.ToString())) && (Scope == null && other.Scope == null || (Scope != null && Scope.Equals(other.Scope)))); }
public async Task UpdateDesiredPropertiesForwardsToTwinManager() { // Create a mock endpoint capable of returning a mock processor var processor = Mock.Of <IProcessor>(); var endpoint = new Mock <Endpoint>("myId"); endpoint.Setup(ep => ep.CreateProcessor()).Returns(processor); endpoint.SetupGet(ep => ep.Id).Returns("myId"); // Create a mock endpoint executor factory to create the endpoint executor to verify invocation var endpointExecutor = Mock.Of <IEndpointExecutor>(); Mock.Get(endpointExecutor).SetupGet(ee => ee.Endpoint).Returns(() => endpoint.Object); var endpointExecutorFactory = Mock.Of <IEndpointExecutorFactory>(); Mock.Get(endpointExecutorFactory).Setup(eef => eef.CreateAsync(It.IsAny <Endpoint>(), new List <uint>() { 0 })).ReturnsAsync(endpointExecutor); // Create a route to map to the message var route = new Route("myRoute", "true", "myIotHub", TelemetryMessageSource.Instance, endpoint.Object, 0, 3600); // Create a router var routerConfig = new RouterConfig(new[] { route }); Router router = await Router.CreateAsync("myRouter", "myIotHub", routerConfig, endpointExecutorFactory); var messageConverter = Mock.Of <Core.IMessageConverter <Devices.Routing.Core.IMessage> >(); var connectionManager = Mock.Of <IConnectionManager>(); var twinManager = new Mock <ITwinManager>(); var message = Mock.Of <IMessage>(); IMessage received = new EdgeMessage.Builder(new byte[0]).Build(); twinManager.Setup(t => t.UpdateDesiredPropertiesAsync(It.IsAny <string>(), It.IsAny <IMessage>())).Callback <string, IMessage>((s, m) => received = message).Returns(Task.CompletedTask); var routingEdgeHub = new RoutingEdgeHub( router, messageConverter, connectionManager, twinManager.Object, "testEdgeDevice", "$edgeHub", Mock.Of <IInvokeMethodHandler>(), Mock.Of <ISubscriptionProcessor>(), Mock.Of <IDeviceScopeIdentitiesCache>()); await routingEdgeHub.UpdateDesiredPropertiesAsync("*", message); twinManager.Verify(x => x.UpdateDesiredPropertiesAsync("*", message), Times.Once); Assert.Equal(message, received); }