Beispiel #1
0
        public void CurrentStateWhenRunsThroughExpectedStates()
        {
            var exploitFinished = false;
            var exploit         = new Mock <IExploit>();

            exploit.Setup(x => x.Exploit()).Callback(() =>
            {
                while (!exploitFinished)
                {
                    Thread.Sleep(10);
                }
            });
            exploit.Setup(x => x.Successful).Returns(true);
            exploit.Setup(x => x.SecretValue).Returns("Secret12345");

            var sut = new ExploitRunner(1, exploit.Object);

            Assert.Equal(ExploitStatus.NotStarted, sut.CurrentState.Exploited);
            sut.Start();
            Assert.Equal(ExploitStatus.Running, sut.CurrentState.Exploited);

            // Allow time for the exploit to complete
            exploitFinished = true;
            Thread.Sleep(20);
            Assert.Equal(ExploitStatus.Successful, sut.CurrentState.Exploited);
        }
Beispiel #2
0
        public void CurrentStateBeforeStartIsNotStarted()
        {
            var exploit = new Mock <IExploit>();

            var sut = new ExploitRunner(1, exploit.Object);

            var result = sut.CurrentState;

            Assert.Equal(ExploitStatus.NotStarted, result.Exploited);
        }
Beispiel #3
0
        public void CurrentStateWhenHasFailure()
        {
            var exploit = new Mock <IExploit>();

            exploit.Setup(x => x.Exploit()).Callback(() =>
            {
                throw new ArgumentException("Broken!!!");
            });

            var sut = new ExploitRunner(1, exploit.Object);

            sut.Start();

            Thread.Sleep(20);
            Assert.Equal(ExploitStatus.Failed, sut.CurrentState.Exploited);
        }
Beispiel #4
0
        public void CurrentStateWhenExploitFails()
        {
            var exploit = new Mock <IExploit>();

            exploit.Setup(x => x.Successful).Returns(false);

            var sut = new ExploitRunner(1, exploit.Object);

            sut.Start();

            Thread.Sleep(20);
            var result = sut.CurrentState;

            Assert.Equal(ExploitStatus.Failed, result.Exploited);
            Assert.Null(result.Value);
        }
Beispiel #5
0
        public void CurrentStateWhenExploitIsSuccessful()
        {
            var exploit = new Mock <IExploit>();

            exploit.Setup(x => x.Successful).Returns(true);
            exploit.Setup(x => x.SecretValue).Returns("Secret12345");

            var sut = new ExploitRunner(1, exploit.Object);

            sut.Start();

            Thread.Sleep(20);
            var result = sut.CurrentState;

            Assert.Equal(ExploitStatus.Successful, result.Exploited);
            Assert.Equal("Secret12345", result.Value);
        }