public async Task DeviceCameOnline_BannedById()
        {
            var circuitManager    = new Mock <ICircuitManager>();
            var circuitConnection = new Mock <ICircuitConnection>();

            circuitManager.Setup(x => x.Connections).Returns(new[] { circuitConnection.Object });
            circuitConnection.Setup(x => x.User).Returns(_testData.Admin1);
            var appConfig            = new Mock <IApplicationConfig>();
            var viewerHub            = new Mock <IHubContext <ViewerHub> >();
            var expiringTokenService = new Mock <IExpiringTokenService>();

            appConfig.Setup(x => x.BannedDevices).Returns(new string[] { _testData.Device1.ID });

            var hub = new AgentHub(DataService, appConfig.Object, viewerHub.Object, circuitManager.Object, expiringTokenService.Object);

            var hubClients = new Mock <IHubCallerClients>();
            var caller     = new Mock <IClientProxy>();

            hubClients.Setup(x => x.Caller).Returns(caller.Object);
            hub.Clients = hubClients.Object;

            Assert.IsFalse(await hub.DeviceCameOnline(_testData.Device1));
            hubClients.Verify(x => x.Caller, Times.Once);
            caller.Verify(x => x.SendCoreAsync("UninstallAgent", It.IsAny <object[]>(), It.IsAny <CancellationToken>()), Times.Once);
        }
Beispiel #2
0
        public async Task DeviceCameOnline_BannedById()
        {
            var appConfig = new Mock<IApplicationConfig>();
            var browserHub = new Mock<IHubContext<BrowserHub>>();
            var viewerHub = new Mock<IHubContext<ViewerHub>>();

            appConfig.Setup(x => x.BannedDevices).Returns(new string[] { TestData.Device1.ID });

            var hub = new AgentHub(DataService, appConfig.Object, browserHub.Object, viewerHub.Object);

            var hubClients = new Mock<IHubCallerClients>();
            var caller = new Mock<IClientProxy>();
            hubClients.Setup(x => x.Caller).Returns(caller.Object);
            hub.Clients = hubClients.Object;

            Assert.IsFalse(await hub.DeviceCameOnline(TestData.Device1));
            hubClients.Verify(x => x.Caller, Times.Once);
            caller.Verify(x => x.SendCoreAsync("UninstallAgent", It.IsAny<object[]>(), It.IsAny<CancellationToken>()), Times.Once);
        }
        public async Task DeviceCameOnline_NotBanned()
        {
            var appConfig = new Mock <IApplicationConfig>();

            var circuitManager    = new Mock <ICircuitManager>();
            var circuitConnection = new Mock <ICircuitConnection>();

            circuitManager.Setup(x => x.Connections).Returns(new[] { circuitConnection.Object });
            circuitConnection.Setup(x => x.User).Returns(_testData.Admin1);
            var browserHubClients    = new Mock <IHubClients>();
            var expiringTokenService = new Mock <IExpiringTokenService>();

            var viewerHub = new Mock <IHubContext <ViewerHub> >();

            appConfig.Setup(x => x.BannedDevices).Returns(Array.Empty <string>());

            var hub = new AgentHub(DataService, appConfig.Object, viewerHub.Object, circuitManager.Object, expiringTokenService.Object)
            {
                Context = new CallerContext()
            };


            var agentHubClients   = new Mock <IHubCallerClients>();
            var agentHubCaller    = new Mock <IClientProxy>();
            var agentClientsProxy = new Mock <IClientProxy>();

            agentHubClients.Setup(x => x.Caller).Returns(agentHubCaller.Object);
            agentHubClients.Setup(x => x.Clients(It.IsAny <IReadOnlyList <string> >())).Returns(agentClientsProxy.Object);
            hub.Clients = agentHubClients.Object;

            var result = await hub.DeviceCameOnline(_testData.Device1);

            Assert.IsTrue(result);

            agentHubClients.Verify(x => x.Caller, Times.Never);
            agentHubCaller.Verify(x => x.SendCoreAsync("UninstallAgent", It.IsAny <object[]>(), It.IsAny <CancellationToken>()), Times.Never);

            circuitConnection.Verify(x => x.InvokeCircuitEvent(
                                         CircuitEventName.DeviceUpdate,
                                         It.Is <Device>(x => x.ID == _testData.Device1.ID)),
                                     Times.Once);
        }
Beispiel #4
0
        public async Task DeviceCameOnline_NotBanned()
        {
            var appConfig = new Mock <IApplicationConfig>();

            var browserHub          = new Mock <IHubContext <BrowserHub> >();
            var browserHubClients   = new Mock <IHubClients>();
            var browserClientsProxy = new Mock <IClientProxy>();

            browserHubClients.Setup(x => x.Clients(It.IsAny <IReadOnlyList <string> >())).Returns(browserClientsProxy.Object);
            browserHub.Setup(x => x.Clients).Returns(browserHubClients.Object);

            var viewerHub = new Mock <IHubContext <ViewerHub> >();

            appConfig.Setup(x => x.BannedDevices).Returns(new string[0]);

            var hub = new AgentHub(DataService, appConfig.Object, browserHub.Object, viewerHub.Object);

            hub.Context = new CallerContext();
            //hub.Context.Items.Add("Device", TestData.Device1);

            var agentHubClients   = new Mock <IHubCallerClients>();
            var agentHubCaller    = new Mock <IClientProxy>();
            var agentClientsProxy = new Mock <IClientProxy>();

            agentHubClients.Setup(x => x.Caller).Returns(agentHubCaller.Object);
            agentHubClients.Setup(x => x.Clients(It.IsAny <IReadOnlyList <string> >())).Returns(agentClientsProxy.Object);
            hub.Clients = agentHubClients.Object;

            Assert.IsTrue(await hub.DeviceCameOnline(TestData.Device1));
            agentHubClients.Verify(x => x.Caller, Times.Never);
            agentHubCaller.Verify(x => x.SendCoreAsync("UninstallAgent", It.IsAny <object[]>(), It.IsAny <CancellationToken>()), Times.Never);

            browserClientsProxy.Verify(x => x.SendCoreAsync("DeviceCameOnline",
                                                            It.Is <object[]>(x => x[0] == TestData.Device1),
                                                            It.IsAny <CancellationToken>()),
                                       Times.Once);
        }