public void AddCouponToDBTest_ShouldAndSaveCouponInDB_by_AddCouponToDBFunctino_And_FetchThisCouponByGetCouponByIdFunctino() { //Arrange CouponType tempCoupon = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "52810aca3720e808eccf5149" } }; //Act //save tempCoupon in DB string savedCouponId = serviceLayer.AddCouponToDB(tempCoupon); //fetch coupon fromDB CouponType fetchedCoupon = serviceLayer.GetCouponById(savedCouponId); serviceLayer.DeleteCoupon(savedCouponId); //Assert Assert.IsNotNull(fetchedCoupon); Assert.AreEqual(tempCoupon.Id, fetchedCoupon.Id); Assert.AreEqual(tempCoupon.Description, fetchedCoupon.Description); Assert.AreEqual(tempCoupon.ValidFrom, fetchedCoupon.ValidFrom); Assert.AreEqual(tempCoupon.ValidUntil.Millisecond, fetchedCoupon.ValidUntil.Millisecond); }
public ActionResult FirstCouponsCreate() { log.InfoFormat("[CouponController.FirstCouponsCreate]"); try { CouponType coupon1 = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen.", RestaurantsIDs = new List<string>() { "52810aca3720e808eccf5149" }, LocationsList = new List<Location>() { new Location(32.051, 34.755) }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31) }; CouponType coupon2 = new CouponType() { Description = "מנה ראשונה במתנה בהזמנת עיקרית במסעדת BG99.", RestaurantsIDs = new List<string>() { "51c5a3cf3720e80f808f5d3c" }, LocationsList = new List<Location>() { new Location(32.016652, 34.738724) }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31) }; CouponType coupon3 = new CouponType() { Description = "אכול כפי יכולתך רק ב89 שקל במסעדת קולומבוס.", RestaurantsIDs = new List<string>() { "528ccb2c3720e8104497f5b3" }, LocationsList = new List<Location>() { new Location(32.161, 34.81) }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31) }; CouponType coupon4 = new CouponType() { Description = "1+1 על כל בירה מהחבית במסעדת Red Burger Bar, כל יום עד שעה 19:00.", RestaurantsIDs = new List<string>() { "5293649b3720e807887f939e" }, LocationsList = new List<Location>() { new Location(32.33, 34.85) }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31) }; CouponType coupon5 = new CouponType() { Description = "1+1 על סטייק אנטריקוט, בהזמנה מנה עיקרית ושתייה, במסעדת Red Burger Bar.", RestaurantsIDs = new List<string>() { "5293649b3720e807887f939e" }, LocationsList = new List<Location>() { new Location(32.33, 34.85) }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31) }; CouponType coupon6 = new CouponType() { Description = "מנת ילד חינם בהזמנה מנה עיקרית למבוגר במסעדת Palamida, ביום שישי 12:00-16:00", RestaurantsIDs = new List<string>() { "513cf83c3720e80c38aa46fd" }, LocationsList = new List<Location>() { new Location(32.084638, 34.803035) }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31) }; CouponType coupon7 = new CouponType() { Description = "ארוחה זוגית ב- 200 שח הארוחה כוללת: - 2 כוסות יין הבית - 2 מרק + לחם הבית - מיקס פירות ים, במסעדת Palamida.", RestaurantsIDs = new List<string>() { "513cf83c3720e80c38aa46fd" }, LocationsList = new List<Location>() { new Location(32.084638, 34.803035) }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31) }; //m_serviceLayer.AddCouponToDB(coupon4); //m_serviceLayer.AddCouponToDB(coupon6); //m_serviceLayer.AddCouponToDB(coupon1); //m_serviceLayer.AddCouponToDB(coupon2); //m_serviceLayer.AddCouponToDB(coupon3); //m_serviceLayer.AddCouponToDB(coupon5); //m_serviceLayer.AddCouponToDB(coupon7); return RedirectToAction("Index"); } catch(Exception e) { log.ErrorFormat("[CouponController.FirstCouponsCreate] Exception={0}", e.ToString()); return RedirectToAction("Index"); } }
public void AddListOfCouponToDB_ShouldCreateNewListCouponAndSaveInDB() { //Arrange using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<CouponType> basicData = new MongoEntityRepositoryBase<CouponType>(restaurantsDb.DB); CouponType tempCoupon1 = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "11111" } }; CouponType tempCoupon2 = new CouponType() { Description = "מנה ראשונה במתנה בהזמנת עיקרית במסעדת BG99. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "22222" } }; CouponType tempCoupon3 = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדתאכול כפי יכולתך רק ב89 שקל במסעדת קולומבוס", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "33333" } }; //Act //save tempCoupon in DB basicData.Add(tempCoupon1); basicData.Add(tempCoupon2); basicData.Add(tempCoupon3); //fetch coupon fromDB string savedCouponId1 = tempCoupon1.Id.ToString(); string savedCouponId2 = tempCoupon2.Id.ToString(); string savedCouponId3 = tempCoupon3.Id.ToString(); CouponType fetchedCoupon1 = basicData.GetSingle(ObjectId.Parse(savedCouponId1)); CouponType fetchedCoupon2 = basicData.GetSingle(ObjectId.Parse(savedCouponId2)); CouponType fetchedCoupon3 = basicData.GetSingle(ObjectId.Parse(savedCouponId3)); serviceLayer.DeleteCoupon(savedCouponId1); serviceLayer.DeleteCoupon(savedCouponId2); serviceLayer.DeleteCoupon(savedCouponId3); //Assert Assert.IsNotNull(fetchedCoupon1); Assert.AreEqual(tempCoupon1.Id, fetchedCoupon1.Id); Assert.AreEqual(tempCoupon1.Description, fetchedCoupon1.Description); Assert.AreEqual(tempCoupon1.ValidFrom, fetchedCoupon1.ValidFrom); Assert.AreEqual(tempCoupon1.ValidUntil.Millisecond, fetchedCoupon1.ValidUntil.Millisecond); Assert.IsNotNull(fetchedCoupon2); Assert.AreEqual(tempCoupon2.Id, fetchedCoupon2.Id); Assert.AreEqual(tempCoupon2.Description, fetchedCoupon2.Description); Assert.AreEqual(tempCoupon2.ValidFrom, fetchedCoupon2.ValidFrom); Assert.AreEqual(tempCoupon2.ValidUntil.Millisecond, fetchedCoupon2.ValidUntil.Millisecond); Assert.IsNotNull(fetchedCoupon3); Assert.AreEqual(tempCoupon3.Id, fetchedCoupon3.Id); Assert.AreEqual(tempCoupon3.Description, fetchedCoupon3.Description); Assert.AreEqual(tempCoupon3.ValidFrom, fetchedCoupon3.ValidFrom); Assert.AreEqual(tempCoupon3.ValidUntil.Millisecond, fetchedCoupon3.ValidUntil.Millisecond); } }
public void ToCouponTypeModelTest_ShouldConverCouponTypeToCouponTypeModel() { //Arrange DateTime time = DateTime.UtcNow; CouponType coupon = new CouponType() { Id = ObjectId.Parse("51aae3bf3720e811c09fb107"), Description = "test coupon nomber 1", RestaurantsIDs = new List<string>() { "51b02f863720e81d6cf62a3b", "51cbee273720e80ea00922ae" }, ValidFrom = new DateTime(0), ValidUntil = time }; //Act CouponTypeModel tempCoupon = coupon.ToCouponTypeModel(); //Assert Assert.AreEqual(tempCoupon.Id, coupon.Id.ToString()); Assert.AreEqual(tempCoupon.Description, coupon.Description); Assert.AreEqual(tempCoupon.ValidFrom, coupon.ValidFrom); Assert.AreEqual(tempCoupon.ValidUntil, time); Assert.AreEqual(tempCoupon.RestaurantID, coupon.RestaurantsIDs[0]); Assert.IsTrue(tempCoupon.LogoUrl.IndexOf("/Restaurant/GetImage/") >= 0); }
public void TestSortCouponsListByDistance_ShouldCalculateDistanceAttributeForeachCouponTypeModel_AndSortListByDistanceValue() { CouponType tempCoupon1 = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "11111" }, LocationsList = new List<Location>() { new Location(0.1, 0.1) } }; CouponType tempCoupon2 = new CouponType() { Description = "מנה ראשונה במתנה בהזמנת עיקרית במסעדת BG99. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "22222" }, LocationsList = new List<Location>() { new Location(0.5, 0.5) } }; CouponType tempCoupon3 = new CouponType() { Description = "אכול כפי יכולתך רק ב89 שקל במסעדת קולומבוס", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "33333" }, LocationsList = new List<Location>() { new Location(0.3, 0.3) } }; CouponType tempCoupon4 = new CouponType() { Description = "1+1 על כל בירה מהחבית במסעדת Red Burger Bar, כל יום עד שעה 19:00.", RestaurantsIDs = new List<string>() { "44444" }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31), LocationsList = new List<Location>() { new Location(1, 1) } }; CouponType tempCoupon5 = new CouponType() { Description = "1+1 על סטייק אנטריקוט, בהזמנה מנה עיקרית ושתייה, במסעדת Red Burger Bar.", RestaurantsIDs = new List<string>() { "55555" }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31), LocationsList = new List<Location>() { new Location(32.067141, 34.804314) } }; CouponType tempCoupon6 = new CouponType() { Description = "מנת ילד חינם בהזמנה מנה עיקרית למבוגר במסעדת Palamida, ביום שישי 12:00-16:00", RestaurantsIDs = new List<string>() { "66666" }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31), LocationsList = new List<Location>() { new Location(0.6, 0.6) } }; CouponType tempCoupon7 = new CouponType() { Description = "ארוחה זוגית ב- 200 שח הארוחה כוללת: - 2 כוסות יין הבית - 2 מרק + לחם הבית - מיקס פירות ים, במסעדת Palamida.", RestaurantsIDs = new List<string>() { "77777" }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31), LocationsList = new List<Location>() { new Location(0.2, 0.2) } }; List<CouponType> couponList = new List<CouponType>(){ tempCoupon1, tempCoupon2, tempCoupon3, tempCoupon4, tempCoupon5, tempCoupon6, tempCoupon7 }; List<CouponTypeModel> couponModelList = couponList.ToCouponTypeModelList(); //Act LocationModel location = new LocationModel(0, 0); foreach (var item in couponModelList) { item.CalcDistance(location); } var list = couponModelList.OrderBy(c=> c.Distance).ToList(); //Assert Assert.IsNotNull(couponModelList); Assert.AreEqual(list[0].RestaurantID, "11111"); Assert.AreEqual(list[1].RestaurantID, "77777"); Assert.AreEqual(list[2].RestaurantID, "33333"); Assert.AreEqual(list[3].RestaurantID, "22222"); Assert.AreEqual(list[4].RestaurantID, "66666"); Assert.AreEqual(list[5].RestaurantID, "44444"); Assert.AreEqual(list[6].RestaurantID, "55555"); }
public void GetCouponForMedal_Should_ResiveUserDataAndDecideWhichCouponToReturn() { CouponType tempCoupon1 = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "11111" } }; CouponType tempCoupon2 = new CouponType() { Description = "מנה ראשונה במתנה בהזמנת עיקרית במסעדת BG99. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "22222" } }; CouponType tempCoupon3 = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדתאכול כפי יכולתך רק ב89 שקל במסעדת קולומבוס", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "33333" } }; string savedCouponId1 = serviceLayer.AddCouponToDB(tempCoupon1); string savedCouponId2 = serviceLayer.AddCouponToDB(tempCoupon2); string savedCouponId3 = serviceLayer.AddCouponToDB(tempCoupon3); SpontaneousUserModel userModel = new SpontaneousUserModel() { UserMedalsList = new List<UserMedal>() }; //userModel.UserMedalsList.Add(new WelcomeUserMedal() { Coupon = tempCoupon1 }); userModel.UserMedalsList.Add(new RestaurantAdviserMedal() { Coupon = tempCoupon2 }); userModel.UserMedalsList.Add(new WelcomeUserMedal()); userModel.UserMedalsList.Add(new RestaurantAdviserMedal()); //Act CouponType coupon = serviceLayer.GetCoupon(userModel, new PageViewActivity("test")); serviceLayer.DeleteCoupon(savedCouponId1); serviceLayer.DeleteCoupon(savedCouponId2); serviceLayer.DeleteCoupon(savedCouponId3); //Assert Assert.IsNotNull(coupon); //Assert.AreNotEqual(coupon.Id, tempCoupon1.Id); Assert.AreNotEqual(coupon.Id, tempCoupon2.Id); }
public void GetCouponForMedal_Should_ResiveUserDataAndFindNearestCouponAccordinlyToActivityLocation() { CouponType tempCoupon1 = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "11111" }, LocationsList = new List<Location>() { new Location(1,1) } }; CouponType tempCoupon2 = new CouponType() { Description = "מנה ראשונה במתנה בהזמנת עיקרית במסעדת BG99. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "22222" }, LocationsList = new List<Location>() { new Location(0,0) } }; CouponType tempCoupon3 = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדתאכול כפי יכולתך רק ב89 שקל במסעדת קולומבוס", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "33333" }, LocationsList = new List<Location>() { new Location(1,1) } }; CouponType tempCoupon4 = new CouponType() { Description = "1+1 על כל בירה מהחבית במסעדת Red Burger Bar, כל יום עד שעה 19:00.", RestaurantsIDs = new List<string>() { "44444" }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31), LocationsList = new List<Location>() { new Location(1,1) } }; CouponType tempCoupon5 = new CouponType() { Description = "1+1 על סטייק אנטריקוט, בהזמנה מנה עיקרית ושתייה, במסעדת Red Burger Bar.", RestaurantsIDs = new List<string>() { "55555" }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31), LocationsList = new List<Location>() { new Location(32.067141, 34.804314) } }; CouponType tempCoupon6 = new CouponType() { Description = "מנת ילד חינם בהזמנה מנה עיקרית למבוגר במסעדת Palamida, ביום שישי 12:00-16:00", RestaurantsIDs = new List<string>() { "66666" }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31), LocationsList = new List<Location>() { new Location(0, 1) } }; CouponType tempCoupon7 = new CouponType() { Description = "ארוחה זוגית ב- 200 שח הארוחה כוללת: - 2 כוסות יין הבית - 2 מרק + לחם הבית - מיקס פירות ים, במסעדת Palamida.", RestaurantsIDs = new List<string>() { "77777" }, ValidFrom = DateTime.UtcNow, ValidUntil = new DateTime(2014, 1, 31), LocationsList = new List<Location>() { new Location(1, 1) } }; string savedCouponId1 = serviceLayer.AddCouponToDB(tempCoupon1); string savedCouponId2 = serviceLayer.AddCouponToDB(tempCoupon2); string savedCouponId3 = serviceLayer.AddCouponToDB(tempCoupon3); string savedCouponId4 = serviceLayer.AddCouponToDB(tempCoupon4); string savedCouponId5 = serviceLayer.AddCouponToDB(tempCoupon5); string savedCouponId6 = serviceLayer.AddCouponToDB(tempCoupon6); string savedCouponId7 = serviceLayer.AddCouponToDB(tempCoupon7); UserActivity activity1 = new PageViewActivity("test") { ActivityLocation = new Location(1, 1) }; UserActivity activity2 = new PageViewActivity("test") { ActivityLocation = new Location(32.067141, 34.804314) }; SpontaneousUserModel userModel = new SpontaneousUserModel() { UserMedalsList = new List<UserMedal>() }; userModel.UserMedalsList.Add(new WelcomeUserMedal() { Coupon = tempCoupon1 }); userModel.UserMedalsList.Add(new RestaurantAdviserMedal() { Coupon = tempCoupon2 }); userModel.UserMedalsList.Add(new WelcomeUserMedal() { Coupon = tempCoupon3 }); userModel.UserMedalsList.Add(new RestaurantAdviserMedal() { Coupon = tempCoupon4 }); //Act CouponType coupon1 = serviceLayer.GetCoupon(userModel, activity1); CouponType coupon2 = serviceLayer.GetCoupon(userModel, activity2); // clean DB from temp coupons serviceLayer.DeleteCoupon(savedCouponId1); serviceLayer.DeleteCoupon(savedCouponId2); serviceLayer.DeleteCoupon(savedCouponId3); serviceLayer.DeleteCoupon(savedCouponId4); serviceLayer.DeleteCoupon(savedCouponId5); serviceLayer.DeleteCoupon(savedCouponId6); serviceLayer.DeleteCoupon(savedCouponId7); //Assert Assert.IsNotNull(coupon1); //Assert.AreNotEqual(coupon.Id, tempCoupon1.Id); Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId1); Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId2); Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId3); Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId4); Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId5); Assert.AreNotEqual(coupon1.Id.ToString(), savedCouponId6); Assert.AreEqual(coupon1.Id.ToString(), savedCouponId7); Assert.AreEqual(coupon1.Description, tempCoupon7.Description); }
public void AddNewCoupon_ShouldCreateNewCouponAndSaveInDB() { //Arrange using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<CouponType> basicData = new MongoEntityRepositoryBase<CouponType>(restaurantsDb.DB); CouponType tempCoupon = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "52810aca3720e808eccf5149" } }; //Act //save tempCoupon in DB basicData.Add(tempCoupon); //restor coupon fromDB string savedCouponId = tempCoupon.Id.ToString(); CouponType fetchedCoupon = basicData.GetSingle(ObjectId.Parse(savedCouponId)); serviceLayer.DeleteCoupon(savedCouponId); //Assert Assert.IsNotNull(fetchedCoupon); Assert.AreEqual(tempCoupon.Id, fetchedCoupon.Id); Assert.AreEqual(tempCoupon.Description, fetchedCoupon.Description); Assert.AreEqual(tempCoupon.ValidFrom, fetchedCoupon.ValidFrom); Assert.AreEqual(tempCoupon.ValidUntil.Millisecond, fetchedCoupon.ValidUntil.Millisecond); } }
public void GetAllCouponsTest_ShouldSaveCouponsInDB_and_return_notEmptyListWhichIncludesSavedCoupons() { CouponType tempCoupon1 = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדת Nelly's Kitchen. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "11111" } }; CouponType tempCoupon2 = new CouponType() { Description = "מנה ראשונה במתנה בהזמנת עיקרית במסעדת BG99. למימוש יש להראות את המסך במסעדה. לפרטי המסעדה לחץ על המדליה", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "22222" } }; CouponType tempCoupon3 = new CouponType() { Description = "קפה + מאפה ב15% הנחה במסעדתאכול כפי יכולתך רק ב89 שקל במסעדת קולומבוס", ValidFrom = new DateTime(0), ValidUntil = DateTime.UtcNow.AddHours(1), RestaurantsIDs = new List<string>() { "33333" } }; //Act //save tempCoupon in DB string savedCouponId1 = serviceLayer.AddCouponToDB(tempCoupon1); string savedCouponId2 = serviceLayer.AddCouponToDB(tempCoupon2); string savedCouponId3 = serviceLayer.AddCouponToDB(tempCoupon3); //fetch coupon fromDB List<CouponType> couponsList = serviceLayer.GetAllCoupons(); int couponCount = 0; if (couponsList.Exists(x => x.Id.ToString() == savedCouponId1)) couponCount++; if (couponsList.Exists(x => x.Id.ToString() == savedCouponId2)) couponCount++; if (couponsList.Exists(x => x.Id.ToString() == savedCouponId3)) couponCount++; serviceLayer.DeleteCoupon(savedCouponId1); serviceLayer.DeleteCoupon(savedCouponId2); serviceLayer.DeleteCoupon(savedCouponId3); //Assert Assert.IsNotNull(couponsList); Assert.AreEqual(couponCount, couponCount); }
public void UpdateCoupon(CouponType coupon) { log.DebugFormat("[UpdateCoupon(CouponType)] couponId={0}.", coupon.Id.ToString()); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<CouponType> basicData = new MongoEntityRepositoryBase<CouponType>(restaurantsDb.DB); basicData.Update(coupon); } }
public static CouponType ToCouponType(this CouponTypeModel coupon) { try { IServicesLayer m_serviceLayer = new ServiceLayerImpl(); CouponType returnValue = new CouponType() { Description = coupon.Description, ValidFrom = coupon.ValidFrom, ValidUntil = coupon.ValidUntil, RestaurantsIDs = new List<string>() { coupon.RestaurantID }, LocationsList = new List<Location>() { coupon.Location.toLoaction() } }; returnValue.Id = (coupon.Id != null && coupon.Id != "") ? ObjectId.Parse(coupon.Id) : returnValue.Id; log.InfoFormat("[ToCouponType] coupon.Description={0}.", coupon.ToString()); return returnValue; } catch (Exception e) { log.ErrorFormat("[ToCouponType] Exception={0}.", e.ToString()); return null; } }
public string AddCouponToDB(CouponType coupon) { using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<CouponType> basicData = new MongoEntityRepositoryBase<CouponType>(restaurantsDb.DB); basicData.Add(coupon); log.InfoFormat("[AddCouponToDB] coupon description={0}.", coupon.Description); return coupon.Id.ToString(); } }
public string AddCouponToDB(CouponType coupon) { throw new NotImplementedException(); }
public void UpdateCoupon(CouponType coupon) { throw new NotImplementedException(); }
public void ToUserMedalModelTest_ShouldConvertUserMedalObjectToViewModel_ifCouponExistShouldConvertCouponTypeToCouponTypeModel() { //Arrange DateTime time = DateTime.UtcNow; CouponType coupon = new CouponType() { Id = new ObjectId("51aae3bf3720e811c09fb107"), Description = "test coupon nomber 1", RestaurantsIDs = new List<string>() { "51b02f863720e81d6cf62a3b", "51cbee273720e80ea00922ae" }, ValidFrom = new DateTime(0), ValidUntil = time }; UserMedal medal1 = new WelcomeUserMedal(); medal1.Coupon = coupon; UserMedal medal2 = new RestaurantAdviserMedal(); //Act UserMedalModel medalModel1 = medal1.ToUserMedalModel(); UserMedalModel medalModel2 = medal2.ToUserMedalModel(); //Assert Assert.AreEqual(medalModel1.MedalName, "ברוכים הבאים"); Assert.AreEqual(medalModel2.MedalName, "מבקר מסעדות"); Assert.AreEqual(medalModel1.CreatedAt, medal1.CreatedAt); Assert.AreEqual(medalModel1.Coupon.Id, medal1.Coupon.Id.ToString()); Assert.IsNull(medalModel2.Coupon); }
public void GetMedalsTest_Should_ReturnListOfUserMedal_ifMedalWithNullCouponMustCreatNewCoupon() { //Arrange SpontaneousUserModel userModel = new SpontaneousUserModel() { UserActivityList = new List<UserActivity>(), UserMedalsList = new List<UserMedal>() }; DateTime time = DateTime.UtcNow; CouponType coupon = new CouponType() { Id = new ObjectId("51aae3bf3720e811c09fb107"), Description = "test coupon nomber 1", RestaurantsIDs = new List<string>() { "51b02f863720e81d6cf62a3b", "51cbee273720e80ea00922ae" }, ValidFrom = new DateTime(0), ValidUntil = time }; UserMedal medal1 = new WelcomeUserMedal(); UserMedal medal2 = new RestaurantAdviserMedal(); UserMedal medal3 = new RestaurantAdviserMedal(); medal3.Coupon = coupon; UserMedal medal4 = new FlowCompleteMedal(); UserMedal medal5 = new AddRestaurantMedal(); userModel.UserMedalsList.Add(medal1); userModel.UserMedalsList.Add(medal2); userModel.UserMedalsList.Add(medal3); userModel.UserMedalsList.Add(medal4); userModel.UserMedalsList.Add(medal5); //Act List<UserMedal> list = serviceLayer.GetMedals(); //Assert Assert.IsFalse(list.Exists(m => m.Coupon == null)); }