public void TestInitException() { EcommerceTransaction et = null; try { et = new EcommerceTransaction().Build(); } catch (Exception e) { Assert.AreEqual("OrderId cannot be null or empty.", e.Message); } Assert.IsNull(et); try { et = new EcommerceTransaction().SetOrderId("orderId").Build(); } catch (Exception e) { Assert.AreEqual("Items cannot be null.", e.Message); } Assert.IsNull(et); try { et = new EcommerceTransaction().SetOrderId("orderId").SetItems(GetItem()).Build(); } catch (Exception e) { Assert.AreEqual("TotalValue cannot be null.", e.Message); } Assert.IsNull(et); }
public void TestInitFull() { EcommerceTransaction et = new EcommerceTransaction() .SetOrderId("orderId") .SetTotalValue(10.22) .SetAffiliation("affiliation") .SetTaxValue(2.5) .SetShipping(6.3) .SetCity("London") .SetState("Shoreditch") .SetCountry("United Kingdom") .SetCurrency("GBP") .SetItems(GetItem()) .Build(); Assert.NotNull(et); Dictionary <string, object> payload = et.GetPayload().GetDictionary(); Assert.AreEqual(12, payload.Count); Assert.AreEqual("tr", payload [Constants.EVENT]); Assert.AreEqual("orderId", payload [Constants.TR_ID]); Assert.AreEqual("10.22", payload [Constants.TR_TOTAL]); Assert.AreEqual("affiliation", payload [Constants.TR_AFFILIATION]); Assert.AreEqual("2.50", payload [Constants.TR_TAX]); Assert.AreEqual("6.30", payload [Constants.TR_SHIPPING]); Assert.AreEqual("London", payload [Constants.TR_CITY]); Assert.AreEqual("Shoreditch", payload [Constants.TR_STATE]); Assert.AreEqual("United Kingdom", payload [Constants.TR_COUNTRY]); Assert.AreEqual("GBP", payload [Constants.TR_CURRENCY]); }
public void testInitEcommerceTransaction() { var et = new EcommerceTransaction() .SetOrderId("orderId") .SetTotalValue(20.1) .SetAffiliation("affiliation") .SetTaxValue(1.56) .SetShipping(10.5) .SetCity("city") .SetState("state") .SetCountry("country") .SetCurrency("AUD") .SetItems(new List <EcommerceTransactionItem>()) .SetTrueTimestamp(123456789123) .Build(); Assert.IsNotNull(et); Assert.AreEqual(Constants.EVENT_ECOMM, et.GetPayload().Payload[Constants.EVENT]); Assert.AreEqual("orderId", et.GetPayload().Payload[Constants.TR_ID]); Assert.AreEqual("20.10", et.GetPayload().Payload[Constants.TR_TOTAL]); Assert.AreEqual("affiliation", et.GetPayload().Payload[Constants.TR_AFFILIATION]); Assert.AreEqual("1.56", et.GetPayload().Payload[Constants.TR_TAX]); Assert.AreEqual("10.50", et.GetPayload().Payload[Constants.TR_SHIPPING]); Assert.AreEqual("city", et.GetPayload().Payload[Constants.TR_CITY]); Assert.AreEqual("state", et.GetPayload().Payload[Constants.TR_STATE]); Assert.AreEqual("country", et.GetPayload().Payload[Constants.TR_COUNTRY]); Assert.AreEqual("AUD", et.GetPayload().Payload[Constants.TR_CURRENCY]); Assert.IsNotNull(et.GetContexts()); Assert.IsTrue(et.GetPayload().Payload.ContainsKey(Constants.EID)); Assert.IsTrue(et.GetPayload().Payload.ContainsKey(Constants.TIMESTAMP)); Assert.IsTrue(et.GetPayload().Payload.ContainsKey(Constants.TRUE_TIMESTAMP)); }
public void TestInitMinimal() { EcommerceTransaction et = new EcommerceTransaction().SetOrderId("orderId").SetItems(GetItem()).SetTotalValue(10.20).Build(); Assert.NotNull(et); Dictionary <string, object> payload = et.GetPayload().GetDictionary(); Assert.AreEqual(5, payload.Count); Assert.AreEqual("tr", payload [Constants.EVENT]); Assert.AreEqual("orderId", payload [Constants.TR_ID]); Assert.AreEqual("10.20", payload [Constants.TR_TOTAL]); }
/// <summary> /// Figures out what kind of event is being tracked and /// then processes it accordingly. /// </summary> /// <param name="newEvent"></param> private void ProcessEvent(IEvent newEvent) { List <IContext> contexts = newEvent.GetContexts(); string eventId = newEvent.GetEventId(); Type eType = newEvent.GetType(); if (eType == typeof(PageView) || eType == typeof(Structured)) { CompleteAndTrackPayload((Payload)newEvent.GetPayload(), contexts, eventId); } else if (eType == typeof(EcommerceTransaction)) { CompleteAndTrackPayload((Payload)newEvent.GetPayload(), contexts, eventId); EcommerceTransaction ecommerceTransaction = (EcommerceTransaction)newEvent; foreach (EcommerceTransactionItem item in ecommerceTransaction.GetItems()) { item.SetItemId(ecommerceTransaction.GetOrderId()); item.SetCurrency(ecommerceTransaction.GetCurrency()); item.SetDeviceCreatedTimestamp(ecommerceTransaction.GetDeviceCreatedTimestamp()); item.SetTrueTimestamp(ecommerceTransaction.GetTrueTimestamp()); CompleteAndTrackPayload((Payload)item.GetPayload(), item.GetContexts(), item.GetEventId()); } } else if (eType == typeof(SelfDescribing)) { SelfDescribing selfDescribing = (SelfDescribing)newEvent; selfDescribing.SetBase64Encode(_encodeBase64); CompleteAndTrackPayload((Payload)selfDescribing.GetPayload(), contexts, eventId); } else if (eType == typeof(ScreenView) || eType == typeof(Timing)) { ProcessEvent(new SelfDescribing() .SetEventData((SelfDescribingJson)newEvent.GetPayload()) .SetCustomContext(newEvent.GetContexts()) .SetDeviceCreatedTimestamp(newEvent.GetDeviceCreatedTimestamp()) .SetTrueTimestamp(newEvent.GetTrueTimestamp()) .SetEventId(newEvent.GetEventId()) .Build()); } }
/// <summary> /// Processes the event. /// </summary> /// <param name="newEvent">New event.</param> private void ProcessEvent(IEvent newEvent) { List <IContext> contexts = newEvent.GetContexts(); string eventId = newEvent.GetEventId(); Type eType = newEvent.GetType(); if (eType == typeof(PageView) || eType == typeof(Structured)) { AddTrackerPayload((TrackerPayload)newEvent.GetPayload(), contexts, eventId); } else if (eType == typeof(EcommerceTransaction)) { AddTrackerPayload((TrackerPayload)newEvent.GetPayload(), contexts, eventId); EcommerceTransaction ecommerceTransaction = (EcommerceTransaction)newEvent; foreach (EcommerceTransactionItem item in ecommerceTransaction.GetItems()) { item.SetItemId(ecommerceTransaction.GetOrderId()); item.SetCurrency(ecommerceTransaction.GetCurrency()); item.SetTimestamp(ecommerceTransaction.GetTimestamp()); AddTrackerPayload((TrackerPayload)item.GetPayload(), item.GetContexts(), item.GetEventId()); } } else if (eType == typeof(Unstructured)) { Unstructured unstruct = (Unstructured)newEvent; unstruct.SetBase64Encode(this.base64Encoded); AddTrackerPayload((TrackerPayload)unstruct.GetPayload(), contexts, eventId); } else if (eType == typeof(Timing) || eType == typeof(ScreenView)) { this.ProcessEvent(new Unstructured() .SetEventData((SelfDescribingJson)newEvent.GetPayload()) .SetCustomContext(newEvent.GetContexts()) .SetTimestamp(newEvent.GetTimestamp()) .SetEventId(newEvent.GetEventId()) .Build()); } }