Exemplo n.º 1
0
        public void TestRecorder()
        {
            var recorder = new MockRecorder();
            var obj1 = recorder.AddActor(2, f =>
            {
                f.AddInt16(1, 10);
                f.AddInt32(2, -10);
                f.AddFloat(3, 5.7f);
            });

            var var1 = obj1.GetVariable<short>(1);
            var var2 = obj1.GetVariable<int>(2);
            var var3 = obj1.GetVariable<float>(3);

            var obj2 = recorder.GetActor(1);
            Assert.AreEqual(obj1.Id, obj2.Id);
            Assert.AreEqual(obj1.StartTime, obj2.StartTime);
            Assert.AreEqual(obj1.EndTime, obj2.EndTime);

            var var4 = obj2.GetVariable<short>(var1.Id);
            var var5 = obj2.GetVariable<int>(var2.Id);
            var var6 = obj2.GetVariable<float>(var3.Id);
            Assert.Throws<ArgumentException>(() => var4.GetValue(1));
            Assert.AreEqual(10, var4.GetValue(2));

            recorder.AddLine(var4, 2, 100, (short)30);
            recorder.AddStep(var5, 2, 110, 10);
            recorder.AddLine(var6, 2, 90, 9.3f);

            var data = recorder.Record(100);
            Assert.AreEqual(0, data.StartTime);
            Assert.AreEqual(100, data.EndTime);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a mock object.
        /// </summary>
        /// <typeparam name="TMock">The type of object to mock.</typeparam>
        /// <returns></returns>
        /// <remarks>
        /// This is where you'd use Reflection.Emit to generate a mock implementation
        /// </remarks>
        public TMock CreateMock <TMock>()
        {
            IMockRecorder recorder = new MockRecorder <TMock>();

            _mockRecorders.Add(recorder);

            return(MockObjectFactory.CreateMock <TMock>(recorder));
        }
Exemplo n.º 3
0
        public void TestReplayer()
        {
            var recorder = new MockRecorder();
            var replayer = new MockReplayer();

            #region Time: 0-100ms

            var obj1 = recorder.AddActor(0, f =>
            {
                f.AddInt16(1, 10);
                f.AddInt32(2, -10);
                f.AddFloat(3, 5.7f);
            });

            var var1 = obj1.GetVariable<short>(1);
            var var2 = obj1.GetVariable<int>(2);
            var var3 = obj1.GetVariable<float>(3);

            recorder.AddLine(var1, 0, 100, (short)30);
            recorder.AddStep(var2, 0, 110, 10);
            recorder.AddLine(var3, 0, 90, 9.3f);

            var data = recorder.Record(100);
            Assert.AreEqual(0, data.StartTime);
            Assert.AreEqual(100, data.EndTime);

            replayer.Replay(data.StartTime, data.EndTime, data);

            var mObj1 = replayer.GetActor(1);
            Assert.AreEqual(obj1.StartTime, mObj1.StartTime);
            Assert.AreEqual(obj1.EndTime, mObj1.EndTime);

            var mVar1 = mObj1.GetVariable<short>(1);
            Assert.AreEqual(10, mVar1.GetValue(0));
            Assert.AreEqual(20, mVar1.GetValue(50));
            Assert.AreEqual(30, mVar1.GetValue(100));

            var mVar2 = mObj1.GetVariable<int>(2);
            Assert.AreEqual(-10, mVar2.GetValue(50));

            var mVar3 = mObj1.GetVariable<float>(3);
            Assert.AreEqual(7.7f, mVar3.GetValue(50));
            Assert.AreEqual(9.3f, mVar3.GetValue(95));

            #endregion

            #region Time: 100-200ms

            recorder.AddLine(var1, 110, 150, (short)40);

            #endregion
        }
Exemplo n.º 4
0
        public void TestReplayer()
        {
            var recorder = new MockRecorder();
            var replayer = new MockReplayer();

            #region Time: 0-100ms

            var obj1 = recorder.AddActor(0, f =>
            {
                f.AddInt16(1, 10);
                f.AddInt32(2, -10);
                f.AddFloat(3, 5.7f);
            });

            var var1 = obj1.GetVariable <short>(1);
            var var2 = obj1.GetVariable <int>(2);
            var var3 = obj1.GetVariable <float>(3);

            recorder.AddLine(var1, 0, 100, (short)30);
            recorder.AddStep(var2, 0, 110, 10);
            recorder.AddLine(var3, 0, 90, 9.3f);

            var data = recorder.Record(100);
            Assert.AreEqual(0, data.StartTime);
            Assert.AreEqual(100, data.EndTime);

            replayer.Replay(data.StartTime, data.EndTime, data);

            var mObj1 = replayer.GetActor(1);
            Assert.AreEqual(obj1.StartTime, mObj1.StartTime);
            Assert.AreEqual(obj1.EndTime, mObj1.EndTime);

            var mVar1 = mObj1.GetVariable <short>(1);
            Assert.AreEqual(10, mVar1.GetValue(0));
            Assert.AreEqual(20, mVar1.GetValue(50));
            Assert.AreEqual(30, mVar1.GetValue(100));

            var mVar2 = mObj1.GetVariable <int>(2);
            Assert.AreEqual(-10, mVar2.GetValue(50));

            var mVar3 = mObj1.GetVariable <float>(3);
            Assert.AreEqual(7.7f, mVar3.GetValue(50));
            Assert.AreEqual(9.3f, mVar3.GetValue(95));

            #endregion

            #region Time: 100-200ms

            recorder.AddLine(var1, 110, 150, (short)40);

            #endregion
        }
        public void TestMockConsistency()
        {
            var random   = new Random();
            var recorder = new MockRecorder();
            var replayer = new MockReplayer();

            for (var time = 0; time < TotalRunTime; time += RecordInterval)
            {
                var data = RandomRecord(random, recorder, time);

                replayer.Replay(time, time + RecordInterval, data);

                for (var frameTime = time; frameTime < time + RecordInterval; frameTime += ReplayInterval)
                {
                    var recorderFrame = GetFrameData(recorder.Scene, frameTime);
                    var replayerFrame = GetFrameData(replayer.Scene, frameTime);

                    CompareFrameData(recorderFrame, replayerFrame);
                }
            }
        }
Exemplo n.º 6
0
        public void TestRecorder()
        {
            var recorder = new MockRecorder();
            var obj1     = recorder.AddActor(2, f =>
            {
                f.AddInt16(1, 10);
                f.AddInt32(2, -10);
                f.AddFloat(3, 5.7f);
            });

            var var1 = obj1.GetVariable <short>(1);
            var var2 = obj1.GetVariable <int>(2);
            var var3 = obj1.GetVariable <float>(3);

            var obj2 = recorder.GetActor(1);

            Assert.AreEqual(obj1.Id, obj2.Id);
            Assert.AreEqual(obj1.StartTime, obj2.StartTime);
            Assert.AreEqual(obj1.EndTime, obj2.EndTime);

            var var4 = obj2.GetVariable <short>(var1.Id);
            var var5 = obj2.GetVariable <int>(var2.Id);
            var var6 = obj2.GetVariable <float>(var3.Id);

            Assert.Throws <ArgumentException>(() => var4.GetValue(1));
            Assert.AreEqual(10, var4.GetValue(2));

            recorder.AddLine(var4, 2, 100, (short)30);
            recorder.AddStep(var5, 2, 110, 10);
            recorder.AddLine(var6, 2, 90, 9.3f);

            var data = recorder.Record(100);

            Assert.AreEqual(0, data.StartTime);
            Assert.AreEqual(100, data.EndTime);
        }