public void Create() { var commandHub = new Mock <ISendCommandsToRemoteEndpoints>(); var id = new DatasetId(); var endpoint = EndpointIdExtensions.CreateEndpointIdForCurrentProcess(); var networkId = NetworkIdentifier.ForLocalMachine(); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var notifications = new Mock <IDatasetApplicationNotifications>(); var notificationHub = new Mock <INotifyOfRemoteEndpointEvents>(); { notificationHub.Setup(n => n.HasNotificationsFor(It.IsAny <EndpointId>())) .Returns(true); notificationHub.Setup(n => n.NotificationsFor <IDatasetApplicationNotifications>(It.IsAny <EndpointId>())) .Callback <EndpointId>(e => Assert.AreSame(endpoint, e)) .Returns(notifications.Object); } var info = new DatasetOnlineInformation( id, endpoint, networkId, commandHub.Object, notificationHub.Object, systemDiagnostics); Assert.AreSame(id, info.Id); Assert.AreSame(endpoint, info.Endpoint); Assert.AreSame(networkId, info.RunsOn); }
public void AvailableCommands() { var id = new DatasetId(); var endpoint = EndpointIdExtensions.CreateEndpointIdForCurrentProcess(); var networkId = NetworkIdentifier.ForLocalMachine(); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var commandList = new Dictionary <Type, ICommandSet> { { typeof(IMockCommandSetWithTaskReturn), new Mock <IMockCommandSetWithTaskReturn>().Object }, { typeof(IMockCommandSetWithTypedTaskReturn), new Mock <IMockCommandSetWithTaskReturn>().Object }, { typeof(IMockCommandSetForInternalUse), new Mock <IMockCommandSetWithTaskReturn>().Object }, }; var commandHub = new Mock <ISendCommandsToRemoteEndpoints>(); { commandHub.Setup(h => h.AvailableCommandsFor(It.IsAny <EndpointId>())) .Returns(commandList.Keys); commandHub.Setup(h => h.CommandsFor(It.IsAny <EndpointId>(), It.IsAny <Type>())) .Returns <EndpointId, Type>((e, t) => commandList[t]); } var notifications = new Mock <IDatasetApplicationNotifications>(); var notificationHub = new Mock <INotifyOfRemoteEndpointEvents>(); { notificationHub.Setup(n => n.HasNotificationsFor(It.IsAny <EndpointId>())) .Returns(true); notificationHub.Setup(n => n.NotificationsFor <IDatasetApplicationNotifications>(It.IsAny <EndpointId>())) .Callback <EndpointId>(e => Assert.AreSame(endpoint, e)) .Returns(notifications.Object); } var info = new DatasetOnlineInformation( id, endpoint, networkId, commandHub.Object, notificationHub.Object, systemDiagnostics); var commands = info.AvailableCommands(); Assert.AreEqual(2, commands.Count()); }
public void Close() { var id = new DatasetId(); var endpoint = EndpointIdExtensions.CreateEndpointIdForCurrentProcess(); var networkId = NetworkIdentifier.ForLocalMachine(); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var datasetCommands = new Mock <IDatasetApplicationCommands>(); { datasetCommands.Setup(d => d.Close()) .Returns( Task.Factory.StartNew( () => { }, new CancellationToken(), TaskCreationOptions.None, new CurrentThreadTaskScheduler())) .Verifiable(); } var commandHub = new Mock <ISendCommandsToRemoteEndpoints>(); { commandHub.Setup(h => h.HasCommandFor(It.IsAny <EndpointId>(), It.IsAny <Type>())) .Returns(true); commandHub.Setup(h => h.CommandsFor <IDatasetApplicationCommands>(It.IsAny <EndpointId>())) .Returns(datasetCommands.Object); } var notifications = new Mock <IDatasetApplicationNotifications>(); var notificationHub = new Mock <INotifyOfRemoteEndpointEvents>(); { notificationHub.Setup(n => n.HasNotificationsFor(It.IsAny <EndpointId>())) .Returns(true); notificationHub.Setup(n => n.NotificationsFor <IDatasetApplicationNotifications>(It.IsAny <EndpointId>())) .Callback <EndpointId>(e => Assert.AreSame(endpoint, e)) .Returns(notifications.Object); } var info = new DatasetOnlineInformation( id, endpoint, networkId, commandHub.Object, notificationHub.Object, systemDiagnostics); info.Close(); datasetCommands.Verify(d => d.Close(), Times.Once()); }
public void Command() { var id = new DatasetId(); var endpoint = EndpointIdExtensions.CreateEndpointIdForCurrentProcess(); var networkId = NetworkIdentifier.ForLocalMachine(); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var commandList = new SortedList <Type, ICommandSet> { { typeof(IMockCommandSetWithTaskReturn), new Mock <IMockCommandSetWithTaskReturn>().Object }, }; var commandHub = new Mock <ISendCommandsToRemoteEndpoints>(); { commandHub.Setup(h => h.CommandsFor <IMockCommandSetWithTaskReturn>(It.IsAny <EndpointId>())) .Returns((IMockCommandSetWithTaskReturn)commandList.Values[0]); } var notifications = new Mock <IDatasetApplicationNotifications>(); var notificationHub = new Mock <INotifyOfRemoteEndpointEvents>(); { notificationHub.Setup(n => n.HasNotificationsFor(It.IsAny <EndpointId>())) .Returns(true); notificationHub.Setup(n => n.NotificationsFor <IDatasetApplicationNotifications>(It.IsAny <EndpointId>())) .Callback <EndpointId>(e => Assert.AreSame(endpoint, e)) .Returns(notifications.Object); } var info = new DatasetOnlineInformation( id, endpoint, networkId, commandHub.Object, notificationHub.Object, systemDiagnostics); var commands = info.Command <IMockCommandSetWithTaskReturn>(); Assert.AreSame(commandList.Values[0], commands); }
private static DistributionPlan CreateNewDistributionPlan( DatasetActivationProposal proposal, IDatasetOfflineInformation offlineInfo, SystemDiagnostics systemDiagnostics) { var plan = new DistributionPlan( (p, t, r) => Task <DatasetOnlineInformation> .Factory.StartNew( () => new DatasetOnlineInformation( new DatasetId(), new EndpointId("id"), new NetworkIdentifier("machine"), new Mock <ISendCommandsToRemoteEndpoints>().Object, new Mock <INotifyOfRemoteEndpointEvents>().Object, systemDiagnostics), t), offlineInfo, NetworkIdentifier.ForLocalMachine(), proposal); return(plan); }