public void GetProductTypeNotFoundTest() { MProductType prdReturned = null; MockedNoSqlContext ctx = new MockedNoSqlContext(); ctx.SetReturnObjectByKey(prdReturned); FactoryBusinessOperation.SetNoSqlContext(ctx); var opt = (IBusinessOperationGetInfo <MProductType>)FactoryBusinessOperation.CreateBusinessOperationObject("GetProductTypeInfo"); MProductType pd = new MProductType(); pd.Code = "MockedCode"; var result = opt.Apply(pd); Assert.AreEqual(null, result, "Product type not found should return null!!!"); }
protected override int Execute() { ILogger logger = GetLogger(); CTable t = XmlToCTable(); INoSqlContext ctx = GetNoSqlContextWithAuthen("firebase"); FactoryBusinessOperation.SetNoSqlContext(ctx); SaveProductType opr = (SaveProductType)FactoryBusinessOperation.CreateBusinessOperationObject("SaveProductType"); try { ArrayList types = t.GetChildArray("ProductTypes"); foreach (CTable pt in types) { MProductType mpt = new MProductType(); mpt.Code = pt.GetFieldValue("Code"); ArrayList descs = pt.GetChildArray("Descriptions"); foreach (CTable desc in descs) { MGenericDescription mdc = new MGenericDescription(); mdc.Language = desc.GetFieldValue("Language"); mdc.Name = desc.GetFieldValue("Name"); mdc.ShortDescription = desc.GetFieldValue("ShortDescription"); mdc.LongDescription1 = desc.GetFieldValue("LongDescription"); mpt.Descriptions.Add(mdc.Language, mdc); LogUtils.LogInformation(logger, "Adding product type : [{0}] [{1}]", mpt.Code, mdc.Name); } opr.Apply(mpt); } } catch (Exception e) { Console.WriteLine("Error : {0}", e.Message); } return(0); }
public void SaveProductTypeByAddingTheNewOneTest() { MProductType prdReturned = null; MockedNoSqlContext ctx = new MockedNoSqlContext(); ctx.SetReturnObjectByKey(prdReturned); FactoryBusinessOperation.SetNoSqlContext(ctx); var opt = (IBusinessOperationGetInfo <MProductType>)FactoryBusinessOperation.CreateBusinessOperationObject("SaveProductType"); MProductType pd = new MProductType(); pd.Code = "MockedCode"; var result = opt.Apply(pd); Assert.AreEqual(null, result, "Expected null to return !!!"); }
public void GetProductTypeFoundTest(string code) { MProductType prdReturned = new MProductType(); prdReturned.Code = code; MockedNoSqlContext ctx = new MockedNoSqlContext(); ctx.SetReturnObjectByKey(prdReturned); FactoryBusinessOperation.SetNoSqlContext(ctx); var opt = (IBusinessOperationGetInfo <MProductType>)FactoryBusinessOperation.CreateBusinessOperationObject("GetProductTypeInfo"); MProductType pd = new MProductType(); pd.Code = "MockedCode"; var result = opt.Apply(pd); Assert.AreEqual(code, result.Code, "Return product type code should be [{0}]!!!", code); }
public void GenericGetProductTypeListTest(string code) { MockedNoSqlContext ctx = new MockedNoSqlContext(); FactoryBusinessOperation.SetNoSqlContext(ctx); var opt = (IBusinessOperationQuery <MProductType>)FactoryBusinessOperation.CreateBusinessOperationObject("GetProductTypeList"); MProductType pd = new MProductType(); pd.Code = code; try { opt.Apply(pd, null); } catch (Exception) { Assert.Fail("Exception should not be thrown here!!!"); } }
public void GetProductTypeWithEmptyTest(string code) { MockedNoSqlContext ctx = new MockedNoSqlContext(); FactoryBusinessOperation.SetNoSqlContext(ctx); var opt = (IBusinessOperationGetInfo <MProductType>)FactoryBusinessOperation.CreateBusinessOperationObject("GetProductTypeInfo"); MProductType pd = new MProductType(); pd.Code = code; try { opt.Apply(pd); Assert.Fail("Exception should be thrown"); } catch (Exception) { //Do nothing } }
private IEnumerable <MProductType> getDummyContents() { var pro1 = new MProductType(); pro1.Code = "001"; pro1.Descriptions["EN"] = new MGenericDescription(); pro1.Descriptions["EN"].Name = "A"; var pro2 = new MProductType(); pro2.Code = "002"; pro2.Descriptions["EN"] = new MGenericDescription(); pro2.Descriptions["EN"].Name = "B"; var list = new List <MProductType>(); list.Add(pro1); list.Add(pro2); IEnumerable <MProductType> dummy = (IEnumerable <MProductType>)list; return(dummy); }
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"; }