public void LogInfoTest() { var fsLogManagerMock = new Mock <IFsLogManager>(); var config = new Config.DecisionApiConfig() { LogManager = fsLogManagerMock.Object, }; var message = "test log Info"; var tag = "test"; Log.LogInfo(config, message, tag); fsLogManagerMock.Verify(x => x.Info(message, tag), Times.Once()); config.LogLevel = LogLevel.CRITICAL; Log.LogInfo(config, message, tag); fsLogManagerMock.Verify(x => x.Info(message, tag), Times.Once()); config.LogManager = null; Log.LogInfo(config, message, tag); fsLogManagerMock.Verify(x => x.Info(message, tag), Times.Once()); }
public void LogErrorFailedTest() { var fsLogManagerMock = new Mock <IFsLogManager>(); var config = new Config.DecisionApiConfig() { LogManager = fsLogManagerMock.Object, }; var message = "test log Error"; var tag = "test"; var error = new Exception("error"); fsLogManagerMock.Setup(x => x.Error(message, tag)).Throws(error); var stringWriter = new StringWriter(); Console.SetOut(stringWriter); Log.LogError(config, message, tag); fsLogManagerMock.Verify(x => x.Error(message, tag), Times.Once()); Assert.IsTrue(stringWriter.ToString().Contains(error.Message)); stringWriter.Dispose(); }
public void EventTest() { var config = new Config.DecisionApiConfig() { EnvId = "envID", ApiKey = "apiKey" }; var action = "click"; var label = "lable"; var value = 12f; var visitorId = "VisitorId"; var hitEvent = new Hit.Event(EventCategory.USER_ENGAGEMENT, action) { Label = label, Value = value, Config = config, VisitorId = visitorId, DS = Constants.SDK_APP }; var keys = Newtonsoft.Json.JsonConvert.SerializeObject(hitEvent.ToApiKeys()); var apiKeys = new Dictionary <string, object>() { [Constants.VISITOR_ID_API_ITEM] = visitorId, [Constants.DS_API_ITEM] = Constants.SDK_APP, [Constants.CUSTOMER_ENV_ID_API_ITEM] = config.EnvId, [Constants.T_API_ITEM] = $"{Hit.HitType.EVENT}", [Constants.CUSTOMER_UID] = null, [Constants.EVENT_CATEGORY_API_ITEM] = $"{EventCategory.USER_ENGAGEMENT}", [Constants.EVENT_ACTION_API_ITEM] = action, [Constants.EVENT_LABEL_API_ITEM] = label, [Constants.EVENT_VALUE_API_ITEM] = value }; var apiKeysJson = Newtonsoft.Json.JsonConvert.SerializeObject(apiKeys); Assert.AreEqual(EventCategory.USER_ENGAGEMENT, hitEvent.Category); Assert.AreEqual(action, hitEvent.Action); Assert.AreEqual(value, hitEvent.Value); Assert.AreEqual(label, hitEvent.Label); Assert.AreEqual(apiKeysJson, keys); Assert.IsTrue(hitEvent.IsReady()); Assert.AreEqual(hitEvent.GetErrorMessage(), Constants.HIT_EVENT_ERROR_MESSSAGE); hitEvent = new Hit.Event(EventCategory.USER_ENGAGEMENT, null); Assert.IsFalse(hitEvent.IsReady()); }
public void Start2Test() { var stringWriter = new StringWriter(); Console.SetOut(stringWriter); var envId = "envId"; var apiKey = "apiKey"; Fs.Start(envId, apiKey); Assert.IsNotNull(Fs.Config); Assert.IsInstanceOfType(Fs.Config, typeof(Config.DecisionApiConfig)); Assert.IsInstanceOfType(Fs.Config.LogManager, typeof(FsLogManager)); Assert.AreEqual(envId, Fs.Config.EnvId); Assert.AreEqual(apiKey, Fs.Config.ApiKey); Assert.AreEqual(FlagshipStatus.READY, Fs.Status); envId = "new envId"; apiKey = "new apiKey"; Fs.Start(envId, apiKey); Assert.IsNotNull(Fs.Config); Assert.IsInstanceOfType(Fs.Config, typeof(Config.DecisionApiConfig)); Assert.IsInstanceOfType(Fs.Config.LogManager, typeof(FsLogManager)); Assert.AreEqual(envId, Fs.Config.EnvId); Assert.AreEqual(apiKey, Fs.Config.ApiKey); var config = new Config.DecisionApiConfig(); Fs.Start(envId, apiKey, config); Assert.IsNotNull(Fs.Config); Assert.AreEqual(Fs.Config, config); Assert.IsInstanceOfType(Fs.Config.LogManager, typeof(FsLogManager)); Assert.AreEqual(envId, Fs.Config.EnvId); Assert.AreEqual(apiKey, Fs.Config.ApiKey); Assert.IsTrue(stringWriter.ToString().Contains(string.Format(Constants.SDK_STARTED_INFO, Constants.SDK_VERSION))); stringWriter.Dispose(); }
public void PageTest() { var config = new Config.DecisionApiConfig() { EnvId = "envID", ApiKey = "apiKey" }; var pageUrl = "http://localhost"; var visitorId = "VisitorId"; var page = new Hit.Page(pageUrl) { Config = config, VisitorId = visitorId, DS = Constants.SDK_APP }; Assert.AreEqual(page.DocumentLocation, pageUrl); Assert.AreEqual(page.Config, config); Assert.AreEqual(page.VisitorId, visitorId); var keys = Newtonsoft.Json.JsonConvert.SerializeObject(page.ToApiKeys()); var apiKeys = new Dictionary <string, object>() { [Constants.VISITOR_ID_API_ITEM] = visitorId, [Constants.DS_API_ITEM] = Constants.SDK_APP, [Constants.CUSTOMER_ENV_ID_API_ITEM] = config.EnvId, [Constants.T_API_ITEM] = $"{Hit.HitType.PAGEVIEW}", [Constants.CUSTOMER_UID] = null, [Constants.DL_API_ITEM] = pageUrl, }; var apiKeysJson = Newtonsoft.Json.JsonConvert.SerializeObject(apiKeys); Assert.AreEqual(apiKeysJson, keys); Assert.IsTrue(page.IsReady()); Assert.AreEqual(page.GetErrorMessage(), Constants.HIT_PAGE_ERROR_MESSAGE); page = new Hit.Page(null); Assert.IsFalse(page.IsReady()); }
public void ScreenTest() { var config = new Config.DecisionApiConfig() { EnvId = "envID", ApiKey = "apiKey" }; var viewName = "HomeView"; var visitorId = "VisitorId"; var anonymousId = "anonymousId"; var userIp = "127.0.0.1"; var screenResolution = "800X650"; var locale = "en"; var sessionNumber = "1"; var screen = new Hit.Screen(viewName) { Config = config, VisitorId = visitorId, DS = Constants.SDK_APP, AnonymousId = anonymousId, UserIp = userIp, ScreenResolution = screenResolution, Locale = locale, SessionNumber = sessionNumber }; Assert.AreEqual(screen.DocumentLocation, viewName); Assert.AreEqual(screen.Config, config); Assert.AreEqual(screen.VisitorId, visitorId); Assert.AreEqual(screen.AnonymousId, anonymousId); Assert.AreEqual(screen.UserIp, userIp); Assert.AreEqual(screen.ScreenResolution, screenResolution); Assert.AreEqual(screen.Locale, locale); Assert.AreEqual(screen.SessionNumber, sessionNumber); var keys = Newtonsoft.Json.JsonConvert.SerializeObject(screen.ToApiKeys()); var apiKeys = new Dictionary <string, object>() { [Constants.VISITOR_ID_API_ITEM] = anonymousId, [Constants.DS_API_ITEM] = Constants.SDK_APP, [Constants.CUSTOMER_ENV_ID_API_ITEM] = config.EnvId, [Constants.T_API_ITEM] = $"{Hit.HitType.SCREENVIEW}", [Constants.USER_IP_API_ITEM] = userIp, [Constants.SCREEN_RESOLUTION_API_ITEM] = screenResolution, [Constants.USER_LANGUAGE] = locale, [Constants.SESSION_NUMBER] = sessionNumber, [Constants.CUSTOMER_UID] = visitorId, [Constants.DL_API_ITEM] = viewName, }; var apiKeysJson = Newtonsoft.Json.JsonConvert.SerializeObject(apiKeys); Assert.AreEqual(apiKeysJson, keys); Assert.IsTrue(screen.IsReady()); Assert.AreEqual(screen.GetErrorMessage(), Constants.HIT_SCREEN_ERROR_MESSAGE); screen = new Hit.Screen(null) { Config = config, }; Assert.IsFalse(screen.IsReady()); keys = Newtonsoft.Json.JsonConvert.SerializeObject(screen.ToApiKeys()); apiKeys = new Dictionary <string, object>() { [Constants.VISITOR_ID_API_ITEM] = null, [Constants.DS_API_ITEM] = null, [Constants.CUSTOMER_ENV_ID_API_ITEM] = config.EnvId, [Constants.T_API_ITEM] = $"{Hit.HitType.SCREENVIEW}", [Constants.CUSTOMER_UID] = null, [Constants.DL_API_ITEM] = null, }; apiKeysJson = Newtonsoft.Json.JsonConvert.SerializeObject(apiKeys); Assert.AreEqual(apiKeysJson, keys); }
public void ItemTest() { var config = new Config.DecisionApiConfig() { EnvId = "envID", ApiKey = "apiKey" }; var transactionId = "transactionId"; var code = "itemCode"; var name = "itemName"; var price = 100f; var quantity = 5f; var category = "ItemCategory"; var visitorId = "VisitorId"; var item = new Hit.Item(transactionId, name, code) { Price = price, Quantity = quantity, Category = category, Config = config, VisitorId = visitorId, DS = Constants.SDK_APP }; Assert.AreEqual(transactionId, item.TransactionId); Assert.AreEqual(name, item.Name); Assert.AreEqual(code, item.Code); Assert.AreEqual(price, item.Price); Assert.AreEqual(quantity, item.Quantity); Assert.AreEqual(category, item.Category); var keys = Newtonsoft.Json.JsonConvert.SerializeObject(item.ToApiKeys()); var apiKeys = new Dictionary <string, object>() { [Constants.VISITOR_ID_API_ITEM] = visitorId, [Constants.DS_API_ITEM] = Constants.SDK_APP, [Constants.CUSTOMER_ENV_ID_API_ITEM] = config.EnvId, [Constants.T_API_ITEM] = $"{Hit.HitType.ITEM}", [Constants.CUSTOMER_UID] = null, [Constants.TID_API_ITEM] = transactionId, [Constants.IN_API_ITEM] = name, [Constants.ICN_API_ITEM] = code, [Constants.IP_API_ITEM] = price, [Constants.IQ_API_ITEM] = quantity, [Constants.IV_API_ITEM] = category, }; var apiKeysJson = Newtonsoft.Json.JsonConvert.SerializeObject(apiKeys); Assert.AreEqual(apiKeysJson, keys); Assert.IsTrue(item.IsReady()); Assert.AreEqual(item.GetErrorMessage(), Constants.HIT_ITEM_ERROR_MESSAGE); item = new Hit.Item(null, null, null); Assert.IsFalse(item.IsReady()); }
public void TransactionTest() { var config = new Config.DecisionApiConfig() { EnvId = "envID", ApiKey = "apiKey" }; var transactionId = "transactionId"; var affiliation = "affiliation"; var taxes = 100f; var currency = "ItemCategory"; var visitorId = "VisitorId"; var couponCode = "couponCode"; var itemCount = 5f; var shippingMethod = "shippingMethod"; var paymentMethod = "paymentMethod"; var totalRevenue = 450f; var shippingCosts = 10f; var transaction = new Hit.Transaction(transactionId, affiliation) { Taxes = taxes, Currency = currency, CouponCode = couponCode, ItemCount = itemCount, ShippingMethod = shippingMethod, PaymentMethod = paymentMethod, TotalRevenue = totalRevenue, ShippingCosts = shippingCosts, Config = config, VisitorId = visitorId, DS = Constants.SDK_APP }; Assert.AreEqual(transactionId, transaction.TransactionId); Assert.AreEqual(affiliation, transaction.Affiliation); Assert.AreEqual(taxes, transaction.Taxes); Assert.AreEqual(currency, transaction.Currency); Assert.AreEqual(couponCode, transaction.CouponCode); Assert.AreEqual(itemCount, transaction.ItemCount); Assert.AreEqual(shippingMethod, transaction.ShippingMethod); Assert.AreEqual(paymentMethod, transaction.PaymentMethod); Assert.AreEqual(totalRevenue, transaction.TotalRevenue); Assert.AreEqual(shippingCosts, transaction.ShippingCosts); var keys = Newtonsoft.Json.JsonConvert.SerializeObject(transaction.ToApiKeys()); var apiKeys = new Dictionary <string, object>() { [Constants.VISITOR_ID_API_ITEM] = visitorId, [Constants.DS_API_ITEM] = Constants.SDK_APP, [Constants.CUSTOMER_ENV_ID_API_ITEM] = config.EnvId, [Constants.T_API_ITEM] = $"{Hit.HitType.TRANSACTION}", [Constants.CUSTOMER_UID] = null, [Constants.TID_API_ITEM] = transactionId, [Constants.TA_API_ITEM] = affiliation, [Constants.TT_API_ITEM] = taxes, [Constants.TC_API_ITEM] = currency, [Constants.TCC_API_ITEM] = couponCode, [Constants.ICN_API_ITEM] = itemCount, [Constants.SM_API_ITEM] = shippingMethod, [Constants.PM_API_ITEM] = paymentMethod, [Constants.TR_API_ITEM] = totalRevenue, [Constants.TS_API_ITEM] = shippingCosts }; var apiKeysJson = Newtonsoft.Json.JsonConvert.SerializeObject(apiKeys); Assert.AreEqual(apiKeysJson, keys); Assert.IsTrue(transaction.IsReady()); Assert.AreEqual(transaction.GetErrorMessage(), Constants.HIT_TRANSACTION_ERROR_MESSAGE); transaction = new Hit.Transaction(null, null); Assert.IsFalse(transaction.IsReady()); }
public void BatchTest() { var config = new Config.DecisionApiConfig() { EnvId = "envID", ApiKey = "apiKey" }; var visitorId = "VisitorId"; var batch = new Batch() { Config = config, VisitorId = visitorId, DS = Constants.SDK_APP }; var hits = new List <HitAbstract>() { new Page("home") }; batch.Hits = hits; var keys = Newtonsoft.Json.JsonConvert.SerializeObject(batch.ToApiKeys()); Assert.AreEqual(batch.Hits, hits); var apiKeys = new Dictionary <string, object>() { [Constants.VISITOR_ID_API_ITEM] = visitorId, [Constants.DS_API_ITEM] = Constants.SDK_APP, [Constants.CUSTOMER_ENV_ID_API_ITEM] = config.EnvId, [Constants.T_API_ITEM] = $"{HitType.BATCH}", [Constants.CUSTOMER_UID] = null, ["h"] = new Collection <IDictionary <string, object> >() { new Dictionary <string, object>() { [Constants.T_API_ITEM] = $"{HitType.PAGEVIEW}", [Constants.DL_API_ITEM] = "home" } } }; var apiKeysJson = Newtonsoft.Json.JsonConvert.SerializeObject(apiKeys); Assert.AreEqual(apiKeysJson, keys); Assert.IsTrue(batch.IsReady()); Assert.AreEqual(batch.GetErrorMessage(), Batch.ERROR_MESSAGE); batch = new Batch(); Assert.IsFalse(batch.IsReady()); hits = new List <HitAbstract>(); batch.Hits = hits; Assert.IsFalse(batch.IsReady()); hits = new List <HitAbstract>() { new Page(null) }; batch.Hits = hits; Assert.IsFalse(batch.IsReady()); }