public void UpdateExisting() { MockedNoSqlContext ctx = new MockedNoSqlContext(); FactoryBusinessOperation.SetNoSqlContext(ctx); MMetric existing = new MMetric(); existing.Key = "PageViews"; existing.Value = 5; ctx.SetReturnObjectByKey <MMetric>(existing); var opt = (IBusinessOperationManipulate <MMetric>)FactoryBusinessOperation.CreateBusinessOperationObject("IncreaseAndRetrieveMetric"); MMetric dat = new MMetric(); dat.Key = "PageViews"; dat.Value = 5; try { int result = opt.Apply(dat); Assert.AreEqual(10, result); } catch (Exception) { Assert.Fail("Exception should not be thrown here!!!"); } }
private IEnumerable <MMetricWrapper> getDummyMetricWrapper() { var metric1 = new MMetric(); metric1.Key = "PageViews"; metric1.Value = 50; var metric2 = new MMetric(); metric2.Key = "TotalProducts"; metric2.Value = 100; var metricWrapper1 = new MMetricWrapper(); metricWrapper1.Value = metric1; var metricWrapper2 = new MMetricWrapper(); metricWrapper2.Value = metric2; var list = new List <MMetricWrapper>(); list.Add(metricWrapper1); list.Add(metricWrapper2); IEnumerable <MMetricWrapper> dummy = (IEnumerable <MMetricWrapper>)list; return(dummy); }
private dynamic GetViews() { var metricOpr = GetMetricIncreaseOperation(); MMetric dat = new MMetric(); dat.Key = "views"; dat.Value = 1; int views = metricOpr.Apply(dat); return(String.Format("{0:n0}", views)); }
private int UpdateTotalShipped(int value) { var matrixOpr = GetMatrixIncreaseOperation(); MMetric dat = new MMetric(); dat.Key = "shipped"; dat.Value = value; int shipped = matrixOpr.Apply(dat); return(shipped); }
public virtual string GetOrderShipped() { var cache = GetMetricsCache(); int shipped = 0; try { MMetric metric = (MMetric)cache.GetValue("shipped"); shipped = metric.Value; } catch { // Use initial value zero if unable to retrieve the shipped value. } return(String.Format("{0:n0}", shipped)); }
public void Setup() { var httpContext = new DefaultHttpContext(); var controllerContext = new ControllerContext() { HttpContext = httpContext, }; mockController = new Mock <HomeController>() { CallBase = true }; iCacheMock = new Mock <ICacheContext>(); mockController.Setup(foo => foo.GetContentCache()).Returns(iCacheMock.Object); mockController.Setup(foo => foo.GetProductTypeCache()).Returns(iCacheMock.Object); mockController.Setup(foo => foo.GetProductsCache()).Returns(iCacheMock.Object); mockController.Setup(foo => foo.GetMetricsCache()).Returns(iCacheMock.Object); var iBusinessOpr = new Mock <IBusinessOperationManipulate <MMetric> >(); mockController.Setup(foo => foo.GetMetricIncreaseOperation()).Returns(iBusinessOpr.Object); MContent newArrivals = new MContent(); newArrivals.Values = new Dictionary <string, string>(); newArrivals.Values.Add("n1", "ITEM-003"); newArrivals.Values.Add("n2", "ITEM-004"); newArrivals.Values.Add("n3", "ITEM-005"); iCacheMock.Setup(foo => foo.GetValue("code/New_Arrival_Products")).Returns(newArrivals); Dictionary <string, BaseModel> cacheData = new Dictionary <string, BaseModel>(); MProductType product1 = new MProductType(); product1.Code = "ITEM-001"; cacheData.Add("ITEM-001", product1); iCacheMock.Setup(foo => foo.GetValues()).Returns(cacheData); controller = mockController.Object; controller.ControllerContext = controllerContext; MContent establishedDate = new MContent(); establishedDate.Values = new Dictionary <string, string>(); establishedDate.Values.Add("EN", "2019-01-01"); MContent bestSellers = new MContent(); bestSellers.Values = new Dictionary <string, string>(); bestSellers.Values.Add("b1", "ITEM-001"); bestSellers.Values.Add("b2", "ITEM-002"); iCacheMock.Setup(foo => foo.GetValue("code/Best_Seller_Products")).Returns(bestSellers); MMetric shipped = new MMetric(); shipped.Value = 2000; iCacheMock.Setup(foo => foo.GetValue("shipped")).Returns(shipped); var contentCache = new Dictionary <string, BaseModel>(); contentCache["cfg/Established_Date"] = establishedDate; cacheData.Add("cfg/Established_Date", establishedDate); contentCache["code/Best_Seller_Products"] = bestSellers; controller.ViewBag.Contents = contentCache; controller.ViewBag.Lang = "EN"; }