Inheritance: EventHistory
        public void Validate()
        {
            // Make sure the handlers have been added
            if (!completed)
            {
                throw new Exception("EventFlowValidator must be completed before it can be validated.");
            }

            // Iterate over the two lists in sync to see if they are the same
            for (int i = 0; i < Math.Max(expectedEvents.Count, receivedEvents.Count); i++)
            {
                // Step 0) Make sure both events exist
                if (i >= expectedEvents.Count)
                {
                    throw new Exception($"Unexpected event received: [{receivedEvents[i].EventType}] {receivedEvents[i].EventObject}");
                }
                ExpectedEvent expected = expectedEvents[i];

                if (i >= receivedEvents.Count)
                {
                    throw new Exception($"Expected additional events: [{expectedEvents[i].EventType}] {expectedEvents[i].ParamType}");
                }
                ReceivedEvent received = receivedEvents[i];

                // Step 1) Make sure the event type matches
                Assert.Equal(expected.EventType, received.EventType);

                // Step 2) Make sure the param type matches
                Assert.Equal(expected.ParamType, received.EventObject.GetType());

                // Step 3) Run the validator on the param object
                Assert.NotNull(received.EventObject);
                expected.Validator?.DynamicInvoke(received.EventObject);
            }
        }
Esempio n. 2
0
        public IEnumerator TestFetchWithCompletion()
        {
            string        json = @"
{
    ""response"": {
        ""messages"": [
            {
                ""action"": {
                    ""campaign_id"": ""sample_campaign"",
                    ""shorten_id"": ""sample_shorten"",
                    ""content"": {
                        ""inlined_variables"": [
                            {""name"": ""strvar"", ""value"": ""foo""}
                        ]
                    },
                    ""plugin_type"": ""remote_config""
                },
                ""campaign"": {
                    ""_id"": ""sample_campaign"",
                    ""service_action_type"": ""remote_config""
                }
            }
        ]
    }
}";
            ExpectedEvent e    = new ExpectedEvent("_fetch_variables", json);

            ExpectedEvent[] events = new ExpectedEvent[] { e };
            PlayModeTestHelper.StartMockServer(events);

            bool done = false;

            Variables.FetchWithCompletion((result) => {
                Assert.True(result);
                Variable var = Variables.GetVariable("strvar");
                Assert.AreEqual("foo", var.GetString("bar"));
                done = true;
            });

            bool eventSent = false;

            while (!eventSent || !done)
            {
                eventSent = PlayModeTestHelper.IsEventSent("_message_ready");
                yield return(null);
            }
            Assert.True(eventSent);
            Assert.True(done);

            PlayModeTestHelper.StopMockServer();
        }
Esempio n. 3
0
        public void HandleRequest(HttpListenerContext context)
        {
            Debug.Log(context.Request.Url.LocalPath);
            if (context.Request.Url.LocalPath == "/v0/native/overlay")
            {
                context.Response.StatusCode = 200;
                context.Response.AddHeader("Content-Type", "text/html");
                context.Response.Close(System.Text.Encoding.UTF8.GetBytes(""), false);
                return;
            }
            StreamReader reader = new StreamReader(context.Request.InputStream);
            string       body   = reader.ReadToEnd();
            JObject      json   = JObject.Parse(body);
            JArray       events = json["events"] as JArray;

            foreach (JObject item in events.Children())
            {
                string eventName = item["event_name"].ToString();
                receivedEvents.Add(eventName);
            }
            if (expectedEvents.Length > 0)
            {
                ExpectedEvent expected = null;
                foreach (ExpectedEvent e in expectedEvents)
                {
                    if (receivedEvents.IndexOf(e.eventName) >= 0)
                    {
                        expected = e;
                        break;
                    }
                }
                if (expected != null)
                {
                    var responseJson = System.Text.Encoding.UTF8.GetBytes(expected.responseJson);
                    context.Response.StatusCode = 200;
                    context.Response.Close(responseJson, false);
                    return;
                }
            }

            var data = System.Text.Encoding.UTF8.GetBytes("");

            context.Response.StatusCode = 200;
            context.Response.Close(data, false);
        }
Esempio n. 4
0
        public void Validate()
        {
            // Make sure the handlers have been added
            if (!_completed)
            {
                throw new Exception("EventFlowValidator must be completed before it can be validated.");
            }

            // Iterate over the two lists in sync to see if they are the same
            for (int i = 0; i < Math.Max(ExpectedEvents.Count, ReceivedEvents.Count); i++)
            {
                // Step 0) Make sure both events exist
                if (i >= ExpectedEvents.Count)
                {
                    throw new Exception($"Unexpected event received: [{ReceivedEvents[i].EventType}] {ReceivedEvents[i].EventObject}");
                }
                ExpectedEvent expected = ExpectedEvents[i];

                if (i >= ReceivedEvents.Count)
                {
                    throw new Exception($"Expected additional events: [{ExpectedEvents[i].EventType}] {ExpectedEvents[i].ParamType}");
                }
                ReceivedEvent received = ReceivedEvents[i];

                // Step 1) Make sure the event type matches
                Assert.True(expected.EventType.Equals(received.EventType),
                            string.Format("Expected EventType {0} but got {1}. Received object is {2}", expected.EventType, received.EventType, received.EventObject.ToString()));

                // Step 2) Make sure the param type matches
                Assert.True(expected.ParamType == received.EventObject.GetType()
                            , $"expected and received event types differ for event Number: {i+1}. Expected EventType: {expected.ParamType}  & Received EventType: {received.EventObject.GetType()}\r\n"
                            + $"\there is the full list of expected and received events::"
                            + $"\r\n\t\t expected event types:{string.Join("\r\n\t\t", ExpectedEvents.ConvertAll(evt=>evt.ParamType))}"
                            + $"\r\n\t\t received event types:{string.Join("\r\n\t\t", ReceivedEvents.ConvertAll(evt=>evt.EventObject.GetType()))}"
                            );

                // Step 3) Run the validator on the param object
                Assert.NotNull(received.EventObject);
                expected.Validator?.DynamicInvoke(received.EventObject);
            }

            // Iterate over updates events if any to ensure that they are conforming
        }
Esempio n. 5
0
  public IEnumerator TestSelfDisablingBehaviour() {
    int f = Time.frameCount;
    Evt eventsOfInterest = Evt.AllEvents & ~(Evt.AllPhysics | Evt.OnGUI);
    ExpectedEvent[] expectedResult = new ExpectedEvent[] {
      new ExpectedEvent(Evt.Awake, f),
      new ExpectedEvent(Evt.SetEnabled, f),
      new ExpectedEvent(Evt.OnDisable, false, true, f)
    };

    GameObject tmp = new GameObject("Self-Affecting Lifecycle", new Type[] { typeof(SelfDisableBehaviour) });
    ArrayList eventHistory = ((SelfDisableBehaviour)tmp.GetComponent(typeof(SelfDisableBehaviour))).eventHistory;
    yield return 0;
    yield return 0;

    Destroy(tmp);
    yield return 0;

    AssertEvents(eventsOfInterest, expectedResult, eventHistory);
  }
Esempio n. 6
0
  public IEnumerator TestSimpleLifecycleStuff() {
    int f = Time.frameCount;
    Evt eventsOfInterest = Evt.AllEvents & ~(Evt.AllPhysics | Evt.OnGUI);
    ExpectedEvent[] expectedResult = new ExpectedEvent[] {
      new ExpectedEvent(Evt.Awake, f),
      new ExpectedEvent(Evt.OnEnable, f),
      new ExpectedEvent(Evt.Start, f),
      new ExpectedEvent(Evt.LateUpdate, f),

      new ExpectedEvent(Evt.Update, f+1),
      new OnDisableFromDestroy(false, f+1),
    };

    GameObject tmp = new GameObject("Simple Lifecycle", new Type[] { typeof(LifecycleBehaviour) });
    ArrayList eventHistory = ((LifecycleBehaviour)tmp.GetComponent(typeof(LifecycleBehaviour))).eventHistory;
    yield return 0;

    Destroy(tmp);
    yield return 0;

    AssertEvents(eventsOfInterest, expectedResult, eventHistory);
  }
Esempio n. 7
0
 public void AssertEvents(Evt mask, ExpectedEvent[] expected, ArrayList actual, string msg)
 {
     AssertTrue(ExpectedEvent.Assert(mask, expected, actual), msg);
 }
Esempio n. 8
0
 private void CheckExpectedEvent(ExpectedEvent actual, ExpectedEvent next)
 {
     Assert.That(actual, Is.EqualTo(expectedEvent));
     expectedEvent = next;
 }
 private void CheckExpectedEventForAsync(ExpectedEvent actual, ExpectedEvent next)
 {
     Assert.That(actual, Is.EqualTo(expectedEventAsync));
     expectedEventAsync = next;
 }
Esempio n. 10
0
    public static bool Assert(Evt mask, ExpectedEvent[] expected, ArrayList actual)
    {
        float lastTime = 0f;

        // TODO: Report meaningful and specific errors.
        int i = 0, j = 0, k = 0, upperBounds = 0;
        upperBounds = Mathf.Max(actual.Count, expected.Length);
        for(i = 0; i < upperBounds; i++) {
        //Debug.Log("i=" + i + ", j=" + j + ", k=" + k + ", expected.Length=" + expected.Length + ", actual.Count=" + actual.Count);
          if(k >= actual.Count) return false;
          EventHistory a = actual[k] as EventHistory;
          if(a == null) throw new System.Exception("Got something other than EventHistory!  Got: " + actual[i]);
          if((a.name & mask) != 0) {
        if(j >= expected.Length) return false;
        if(!expected[j].CheckAgainst(lastTime, a)) return false;
        lastTime = a.realtimeSinceStartup;
        j++;
          }
          k++;
        }

        return true;
    }
Esempio n. 11
0
 public void AssertEvents(Evt mask, ExpectedEvent[] expected, ArrayList actual)
 {
     AssertEvents(mask, expected, actual, "Event history did not match expected result.  Got:\n" + EventHistory.ToString(mask, actual) + "\n\nExpected:\n" + EventHistory.ToString(expected));
 }
Esempio n. 12
0
 public void AssertEvents(Evt mask, ExpectedEvent[] expected, ArrayList actual, string msg)
 {
     AssertTrue(ExpectedEvent.Assert(mask, expected, actual), msg);
 }