예제 #1
0
        //[TestMethod()] --> Can not test this, because there is no proper way to inject Mock-Session-Object
        public void ShutdownMachineTest()
        {
            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);

            machineProxy.Shutdown(ShutdownType.ACPI);

            _mockedComMachine.Verify(x => x.LockMachine(It.IsAny <Session>(), It.IsAny <LockType>()));
        }
예제 #2
0
        public void PropertyDelegationTest()
        {
            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);

            Assert.AreEqual("testMachine", machineProxy.getName());
            Assert.AreEqual("testDescription", machineProxy.getDescription());
            Assert.AreEqual("idOfTestMachine", machineProxy.getId());
        }
예제 #3
0
        public void EstimateTimeProgressCompletedTest()
        {
            Mock <IProgress> progressMock = new Mock <IProgress>();
            int completed = 0;

            progressMock.SetupGet(x => x.Completed).Returns(() => completed).Callback(() => completed = 1);
            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny <Session>(), It.IsAny <string>(), It.IsAny <string>())).Returns(progressMock.Object);

            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            ProgressToken   t            = machineProxy.Start();
            TimeSpan        test         = t.EstimateRemainingTime();

            Assert.AreEqual(TimeSpan.Zero, test);
        }
예제 #4
0
        public void EstimateTimeProgressPercentReachedTest()
        {
            Mock <IProgress> progressMock = new Mock <IProgress>();
            int percent = 0;

            progressMock.SetupGet(x => x.Percent).Returns(() => (uint)percent).Callback(() => percent++);
            progressMock.SetupGet(x => x.TimeRemaining).Returns(10);
            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny <Session>(), It.IsAny <string>(), It.IsAny <string>())).Returns(progressMock.Object);

            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            ProgressToken   t            = machineProxy.Start();
            TimeSpan        test         = t.EstimateRemainingTime();

            Assert.AreEqual(10, test.TotalSeconds);
        }
예제 #5
0
        public void EstimateTimeNegativeTimeTest()
        {
            Mock <IProgress> progressMock = new Mock <IProgress>();

            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny <Session>(), It.IsAny <string>(), It.IsAny <string>())).Returns(progressMock.Object);
            progressMock.Setup(x => x.TimeRemaining).Returns(-100);
            progressMock.SetupGet(x => x.Percent).Returns(40);

            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            ProgressToken   t            = machineProxy.Start();

            TimeSpan test = t.EstimateRemainingTime();

            Assert.IsTrue(test.CompareTo(TimeSpan.Zero) > 0, "Negative TimeSpan returned");
        }
예제 #6
0
        public void EstimateTimeProgressTimeoutTest()
        {
            Mock <IProgress> progressMock = new Mock <IProgress>();

            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny <Session>(), It.IsAny <string>(), It.IsAny <string>())).Returns(progressMock.Object);

            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            ProgressToken   t            = machineProxy.Start();

            try {
                TimeSpan test = t.EstimateRemainingTime();
                Assert.Fail("Timeout exception did not occur!");
            }
            catch (TimeoutException) {
            }
        }
예제 #7
0
        public void StartMachineCancelTest()
        {
            Mock <IProgress> progressMock = new Mock <IProgress>();

            progressMock.SetupGet(x => x.Cancelable).Returns(1);
            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny <Session>(), It.IsAny <string>(), It.IsAny <string>())).Returns(progressMock.Object);


            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            ProgressToken   t            = machineProxy.Start();

            Assert.IsInstanceOfType(t, typeof(ComMachineProxy.IProgressProgressToken));

            t.Cancel();
            progressMock.Verify(x => x.Cancel());
        }
        public void MachineStateMappingTest() {
            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            
            Assert.AreEqual(VBoxWrapper.MachineState.Off, machineProxy.getState());
            
            _mockedComMachine.SetupGet(x => x.State).Returns(VirtualBox.MachineState.MachineState_Running);
            Assert.AreEqual(VBoxWrapper.MachineState.Running, machineProxy.getState());

            _mockedComMachine.SetupGet(x => x.State).Returns(VirtualBox.MachineState.MachineState_Paused);
            Assert.AreEqual(VBoxWrapper.MachineState.Running, machineProxy.getState());

            _mockedComMachine.SetupGet(x => x.State).Returns(VirtualBox.MachineState.MachineState_Saved);
            Assert.AreEqual(VBoxWrapper.MachineState.SessionSaved, machineProxy.getState());

            _mockedComMachine.SetupGet(x => x.State).Returns(VirtualBox.MachineState.MachineState_Saving);
            Assert.AreEqual(VBoxWrapper.MachineState.InTransition, machineProxy.getState());
        }
예제 #9
0
        public void MachineStateMappingTest()
        {
            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);

            Assert.AreEqual(VBoxWrapper.MachineState.Off, machineProxy.getState());

            _mockedComMachine.SetupGet(x => x.State).Returns(VirtualBox.MachineState.MachineState_Running);
            Assert.AreEqual(VBoxWrapper.MachineState.Running, machineProxy.getState());

            _mockedComMachine.SetupGet(x => x.State).Returns(VirtualBox.MachineState.MachineState_Paused);
            Assert.AreEqual(VBoxWrapper.MachineState.Running, machineProxy.getState());

            _mockedComMachine.SetupGet(x => x.State).Returns(VirtualBox.MachineState.MachineState_Saved);
            Assert.AreEqual(VBoxWrapper.MachineState.SessionSaved, machineProxy.getState());

            _mockedComMachine.SetupGet(x => x.State).Returns(VirtualBox.MachineState.MachineState_Saving);
            Assert.AreEqual(VBoxWrapper.MachineState.InTransition, machineProxy.getState());
        }
        public virtual IEnumerable<IVirtualMachineProxy> buildMachineProxyList() {
            dynamic machines = _virtualBox.Machines;

            foreach (var machine in machines) {
                ComMachineProxy cmp = null;
                try {
                    cmp = new ComMachineProxy(machine);
                }
                catch (Exception anyEx) {
                    _log.TraceEvent(TraceEventType.Error, (int)Logging.ComInterfaceErrorIds.ComProxyInstantiationFailed, "Could not instantiate MachineProxy via COM-Interface", anyEx.ToString());
                    _log.TraceData(TraceEventType.Error, (int)Logging.ComInterfaceErrorIds.ComProxyInstantiationFailed, anyEx);
                }

                if (cmp != null) {
                    yield return cmp;
                }
            }
        }
예제 #11
0
        public void StartMachineTest()
        {
            Mock <IProgress> progressMock = new Mock <IProgress>();
            int i = 0;

            progressMock.SetupGet(x => x.Completed).Returns(i).Callback(() => i = 1); //return 0 once, then 1

            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny <Session>(), It.IsAny <string>(), It.IsAny <string>())).Returns(progressMock.Object);


            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);

            ProgressToken t = machineProxy.Start();

            Assert.IsInstanceOfType(t, typeof(ComMachineProxy.IProgressProgressToken));

            t.Wait();
            progressMock.Verify(x => x.WaitForCompletion(It.IsAny <int>()));
        }
        public void StartMachineTest() {
            Mock<IProgress> progressMock = new Mock<IProgress>();
            int i = 0;
            progressMock.SetupGet(x => x.Completed).Returns(i).Callback(() => i = 1); //return 0 once, then 1
            
            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny<Session>(), It.IsAny<string>(), It.IsAny<string>())).Returns(progressMock.Object);

            
            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);

            ProgressToken t = machineProxy.Start();

            Assert.IsInstanceOfType(t, typeof(ComMachineProxy.IProgressProgressToken));

            t.Wait();
            progressMock.Verify(x => x.WaitForCompletion(It.IsAny<int>()));
        }
        public void EstimateTimeProgressCompletedTest() {
            Mock<IProgress> progressMock = new Mock<IProgress>();
            int completed = 0;
            progressMock.SetupGet(x => x.Completed).Returns(() => completed).Callback(() => completed = 1);
            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny<Session>(), It.IsAny<string>(), It.IsAny<string>())).Returns(progressMock.Object);

            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            ProgressToken t = machineProxy.Start();
            TimeSpan test = t.EstimateRemainingTime();

            Assert.AreEqual(TimeSpan.Zero, test);
        }
        //[TestMethod()] --> Can not test this, because there is no proper way to inject Mock-Session-Object
        public void ShutdownMachineTest() {
            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            
            machineProxy.Shutdown(ShutdownType.ACPI);

            _mockedComMachine.Verify(x => x.LockMachine(It.IsAny<Session>(), It.IsAny<LockType>()));
        }
        public void EstimateTimeProgressPercentReachedTest() {
            Mock<IProgress> progressMock = new Mock<IProgress>();
            int percent = 0;
            progressMock.SetupGet(x => x.Percent).Returns(() => (uint)percent).Callback(() => percent++);
            progressMock.SetupGet(x => x.TimeRemaining).Returns(10);
            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny<Session>(), It.IsAny<string>(), It.IsAny<string>())).Returns(progressMock.Object);

            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            ProgressToken t = machineProxy.Start();
            TimeSpan test = t.EstimateRemainingTime();

            Assert.AreEqual(10, test.TotalSeconds);
        }
        public void EstimateTimeProgressTimeoutTest() {
            Mock<IProgress> progressMock = new Mock<IProgress>();
            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny<Session>(), It.IsAny<string>(), It.IsAny<string>())).Returns(progressMock.Object);

            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            ProgressToken t = machineProxy.Start();

            try {
                TimeSpan test = t.EstimateRemainingTime();
                Assert.Fail("Timeout exception did not occur!");
            }
            catch (TimeoutException) {
                
            }
        }
        public void EstimateTimeNegativeTimeTest() {
            Mock<IProgress> progressMock = new Mock<IProgress>();
            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny<Session>(), It.IsAny<string>(), It.IsAny<string>())).Returns(progressMock.Object);
            progressMock.Setup(x => x.TimeRemaining).Returns(-100);
            progressMock.SetupGet(x => x.Percent).Returns(40);

            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            ProgressToken t = machineProxy.Start();

            TimeSpan test = t.EstimateRemainingTime();

            Assert.IsTrue(test.CompareTo(TimeSpan.Zero) > 0, "Negative TimeSpan returned");
        }
 public void PropertyDelegationTest() {
     ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
     Assert.AreEqual("testMachine", machineProxy.getName());
     Assert.AreEqual("testDescription", machineProxy.getDescription());
     Assert.AreEqual("idOfTestMachine", machineProxy.getId());
 }
        public void StartMachineCancelTest() {
            Mock<IProgress> progressMock = new Mock<IProgress>();
            progressMock.SetupGet(x => x.Cancelable).Returns(1);
            _mockedComMachine.Setup(x => x.LaunchVMProcess(It.IsAny<Session>(), It.IsAny<string>(), It.IsAny<string>())).Returns(progressMock.Object);


            ComMachineProxy machineProxy = new ComMachineProxy(_mockedComMachine.Object);
            ProgressToken t = machineProxy.Start();

            Assert.IsInstanceOfType(t, typeof(ComMachineProxy.IProgressProgressToken));

            t.Cancel();
            progressMock.Verify(x => x.Cancel());
        }