public void FindCached_CachedOutdated_CachesResult()
        {
            IntPtr baseAddress = Process.GetCurrentProcess().MainModule.BaseAddress;
            IntPtr expected = baseAddress + 0x1337;
            TestPatternElement element = new TestPatternElement
            {
                Cached = new CachedElement { Value = 4, Build = "0.0.0" }
            };
            Mock<IBotProcessContext> contextMock = new Mock<IBotProcessContext>();
            contextMock.TargetProcessIsCurrent();
            Mock<Pattern> patternMock = new Mock<Pattern>(new byte[0], (bool[])null, false);
            patternMock.Setup(x => x.Find(contextMock.Object, null)).Returns(expected);
            element.Pattern = patternMock.Object;

            element.FindCached(contextMock.Object);
            IntPtr actual = baseAddress + element.Cached.Value;

            Assert.AreEqual(expected, actual);
        }
        public void FindCached_CachedUpToDate_ReturnsSameValueAsNotCached()
        {
            var info = Process.GetCurrentProcess().MainModule.FileVersionInfo;
            IntPtr expected = Process.GetCurrentProcess().MainModule.BaseAddress + 0x1337;
            TestPatternElement element = new TestPatternElement();

            Mock<IBotProcessContext> contextMock = new Mock<IBotProcessContext>();
            contextMock.TargetProcessIsCurrent();
            Mock<Pattern> patternMock = new Mock<Pattern>(new byte[0], (bool[])null, false);
            patternMock.Setup(x => x.Find(contextMock.Object, null)).Returns(expected);
            element.Pattern = patternMock.Object;

            IntPtr actual1 = element.FindCached(contextMock.Object);
            IntPtr actual2 = element.FindCached(contextMock.Object);

            Assert.AreEqual(expected, actual1);
            Assert.AreEqual(expected, actual2);
            patternMock.Verify(x => x.Find(contextMock.Object, null), Times.Once());
        }
        public void FindCached_NotCached_ForwardsToPattern()
        {
            IntPtr expected = new IntPtr(0x1337);
            TestPatternElement element = new TestPatternElement();
            Mock<IBotProcessContext> contextMock = new Mock<IBotProcessContext>();
            contextMock.TargetProcessIsCurrent();
            Mock<Pattern> patternMock = new Mock<Pattern>(new byte[0], (bool[])null, false);
            patternMock.Setup(x => x.Find(contextMock.Object, null)).Returns(expected);
            element.Pattern = patternMock.Object;

            IntPtr actual = element.FindCached(contextMock.Object);

            Assert.AreEqual(expected, actual);
            patternMock.Verify(x => x.Find(contextMock.Object, null));
        }
        public void FindCached_CachedUpToDate_ReturnsCachedValue()
        {
            var info = Process.GetCurrentProcess().MainModule.FileVersionInfo;
            int expected = 0x1337;
            TestPatternElement element = new TestPatternElement
            {
                Cached = new CachedElement { Value = expected, Build = info.FileVersion }
            };
            Mock<IBotProcessContext> contextMock = new Mock<IBotProcessContext>();
            contextMock.TargetProcessIsCurrent();
            Mock<Pattern> patternMock = new Mock<Pattern>(new byte[0], (bool[])null, false);
            element.Pattern = patternMock.Object;

            element.FindCached(contextMock.Object);
            int actual = element.Cached.Value;

            Assert.AreEqual(expected, actual);
            patternMock.Verify(x => x.Find(contextMock.Object, null), Times.Never());
        }