public TestResourceNamer(string name, string methodName) : base(name)
        {
            var namesField = typeof(HttpMockServer).GetField("names", BindingFlags.NonPublic | BindingFlags.Static);

            assetNames    = ((AssetNames)namesField.GetValue(null));
            this.testName = methodName;
        }
예제 #2
0
 public void Initialize(
     AssetNames hitMap,
     int desiredSpeed,
     CollisionHandler onCollide,
     PushedAwayHandler onPush
     )
 {
     HitMap            = hitMap;
     DesiredSpeed_HACK = desiredSpeed;
     OnCollision       = onCollide;
     OnPush            = onPush;
 }
        private static AnimationTemplate LoadTemplate(AnimationNames name, string file)
        {
            var text  = File.ReadAllText(file);
            var parts = text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length < 2)
            {
                throw new InvalidOperationException("Couldn't load animation, insufficient parts");
            }

            if (!int.TryParse(parts[0], out var steps))
            {
                throw new InvalidOperationException($"Couldn't parse step for animation, expected integer, found: {parts[0]}");
            }
            if (steps < 0)
            {
                throw new InvalidOperationException("Steps for animation is < 0");
            }

            var frames  = new AssetNames[4];
            var frameIx = 0;

            for (var i = 1; i < parts.Length; i++)
            {
                var frame = parts[i];
                if (!Enum.TryParse <AssetNames>(frame, ignoreCase: true, out var parsedFrame))
                {
                    throw new InvalidOperationException($"Couldn't parse animation frame, found: {frame}");
                }

                if (frameIx == frames.Length)
                {
                    Array.Resize(ref frames, frames.Length * 2);
                }

                frames[frameIx] = parsedFrame;
                frameIx++;
            }

            Array.Resize(ref frames, frameIx);

            return(new AnimationTemplate(name, frames, steps));
        }
예제 #4
0
        static HttpMockServer()
        {
            names = new AssetNames();
            sessionRecords = new List<RecordEntry>();
            instanceCount = 0;
            Mode = GetCurrentMode();

            if (Mode == HttpRecorderMode.Playback)
            {
                if (Directory.Exists(recordsDir))
                {
                    foreach (string recordsFile in Directory.GetFiles(recordsDir))
                    {
                        sessionRecords.AddRange(Utilities.DeserializeJson<List<RecordEntry>>(recordsFile));
                    }
                }

                Dictionary<string, string[]> savedNames = Utilities.DeserializeJson<Dictionary<string, string[]>>(namesPath)
                    ?? new Dictionary<string, string[]>();
                savedNames.ForEach(r => names.Enqueue(r.Key, r.Value));
            }
        }