Esempio n. 1
0
        public void Add_Offer_To_Index_FindPhrase_FinallyRemove()
        {
            Offer offer = MongoDbTestUtil.CreateOffer(null, null, 10, Offer.StatusType.Active);

            SearchService.AddUpdateLuceneIndex(offer);

            //matches the phrase searched for
            List <Offer> results = SearchService.Search("get some").ToList();

            Assert.AreEqual(1, results.Count);
            Assert.IsNotNull(results[0]);
            Assert.AreEqual(results[0].Name, "Duck n Coffee discount");

            //no match for this phrase
            results = SearchService.Search("get more").ToList();
            Assert.AreEqual(0, results.Count);

            //matches on gojuice, but not get more
            results = SearchService.Search("get more, gojuice").ToList();
            Assert.AreEqual(1, results.Count);


            SearchService.ClearLuceneOfferRecord(offer.Id);
            //record is deleted
            results = SearchService.Search("get some").ToList();

            Assert.AreEqual(0, results.Count);
        }
 public void SetUp()
 {
     _offerRepo = new Mock <IOfferRepository>(MockBehavior.Strict);
     _offers    = new List <Offer>();
     _offers.Add(MongoDbTestUtil.CreateOffer(null, null, 10, Offer.StatusType.Active));
     _offerRepo.Setup(x => x.Offers).Returns(_offers.AsQueryable);
     _offerService = new OfferService(_offerRepo.Object);
 }
Esempio n. 3
0
        public void Get_All_Offers_For_User()
        {
            //Arrange
            var offerSaved = _offerService.CreateOffer(MongoDbTestUtil.CreateOffer("Jebbies Discount"));

            _offerService.ActivateOffer(offerSaved.Id);

            var offerSaved2 = _offerService.CreateOffer(MongoDbTestUtil.CreateOffer());

            var offerSaved3 = _offerService.CreateOffer(MongoDbTestUtil.CreateOffer());

            User user1 = MongoDbTestUtil.CreateUserCustomer();

            bool exists = _userRepo.DoesAccountExist(user1.Email, user1.Password);

            if (exists)
            {
                _userRepo.DeleteUser(user1.Email, user1.Password);
            }

            var user = _userService.CreateUser(user1);

            var profileId = _userService.GetProfileID(user.UserId);

            var savedProfile = _userService.SaveProfile(MongoDbTestUtil.CreateProfileWithPreferences(user.UserId, profileId));

            //Act
            var matchingOffers = _match.GetMatchesForUser(user.UserId);

            var offersFound = matchingOffers.FirstOrDefault().Value;

            //Assert
            Assert.IsTrue(offersFound.Count == 3);

            var matchingOffer = offersFound.FirstOrDefault();

            Assert.IsTrue(matchingOffer.Name == "Jebbies Discount");
            Assert.IsTrue(matchingOffer.Category == "discounts");

            _userRepo.DeleteProfile(savedProfile.Id);
            var profileDeleted = _userRepo.Profiles.FirstOrDefault(x => x.Id == savedProfile.Id);

            Assert.IsTrue(profileDeleted == null);

            _userRepo.DeleteUser(user1.Email, user1.Password);

            var userGet = _userRepo.GetUser(user.Id);

            Assert.IsNull(userGet);

            //Delete offers
            _offerRepo.DeleteOffer(offerSaved.Id);
            _offerRepo.DeleteOffer(offerSaved2.Id);
            _offerRepo.DeleteOffer(offerSaved3.Id);
        }
Esempio n. 4
0
        public void Add_Offer_To_Index_FindByDescription_FinallyRemove()
        {
            Offer offer = MongoDbTestUtil.CreateOffer(null, null, 10, Offer.StatusType.Active);

            SearchService.AddUpdateLuceneIndex(offer);

            List <Offer> results = SearchService.Search("20%").ToList();

            Assert.AreEqual(1, results.Count);
            Assert.IsNotNull(results[0]);
            Assert.AreEqual(results[0].Name, "Duck n Coffee discount");

            SearchService.ClearLuceneOfferRecord(offer.Id);

            results = SearchService.Search("20%").ToList();

            Assert.AreEqual(0, results.Count);
        }
        public void Can_Change_Offer_Status()
        {
            var offer      = MongoDbTestUtil.CreateOffer(null, _createdBy);
            var offerSaved = _offerRepo.SaveOffer(offer);

            Assert.IsTrue(offerSaved.Status == Offer.StatusType.Pending);

            _offerRepo.InactivateOffer(offerSaved.Id);
            var offerInactive = _offerRepo.Offers.FirstOrDefault(x => x.Id == offerSaved.Id);

            Assert.IsTrue(offerInactive.Status == Offer.StatusType.Inactive);

            _offerRepo.ActivateOffer(offerSaved.Id);
            var offerActivated = _offerRepo.Offers.FirstOrDefault(x => x.Id == offerSaved.Id);

            Assert.IsTrue(offerActivated.Status == Offer.StatusType.Active);

            _offerRepo.DeleteOffer(offerSaved.Id);
        }
        public void Can_Expire_An_Offer()
        {
            //Arrange
            var offer = MongoDbTestUtil.CreateOffer(null, _createdBy);

            var offerSaved        = _offerRepo.SaveOffer(offer);
            var firstTimeToExpire = _offerRepo.SaveOffer(offer).Expires;

            //Act
            _offerRepo.ExpireOffer(offerSaved.Id);

            var secondTimeToExpire = _offerRepo.Offers.FirstOrDefault(x => x.Id == offerSaved.Id).Expires;

            var compare = DateTime.Compare((DateTime)firstTimeToExpire, (DateTime)secondTimeToExpire);

            _offerRepo.DeleteOffer(offerSaved.Id);

            //Assert
            Assert.IsTrue(compare == 1);
        }
        public void Can_Create_And_Delete_Offer()
        {
            //Arrange
            var offer = MongoDbTestUtil.CreateOffer(null, _createdBy);

            //Act
            var offerSaved = _offerRepo.SaveOffer(offer);

            //Assert
            Assert.IsNotNull(offerSaved.Id);
            Assert.AreEqual(offer.Category, offerSaved.Category);

            //Act
            _offerRepo.DeleteOffer(offerSaved.Id);

            var offerDeleted = _offerRepo.Offers.FirstOrDefault(x => x.Id == offerSaved.Id);

            //Assert
            Assert.IsTrue(offerDeleted == null);
        }
        public void Can_Create_And_Delete_Campaign()
        {
            //Arrange
            var offerActive  = MongoDbTestUtil.CreateOffer(null, _createdBy, 10, Offer.StatusType.Active);
            var offerExpired = MongoDbTestUtil.CreateOffer(null, _createdBy, -10, Offer.StatusType.Active);
            var offerPending = MongoDbTestUtil.CreateOffer(null, _createdBy);

            var campaign = new Campaign
            {
                CurrentOffers = new List <Offer>()
                {
                    offerActive
                },
                ExpiredOffers = new List <Offer>()
                {
                    offerExpired
                },
                PendingOffers = new List <Offer>()
                {
                    offerPending
                },
                Id        = ObjectId.GenerateNewId().ToString(),
                ProfileId = ObjectId.GenerateNewId().ToString()
            };

            //Act
            var c = _offerRepo.SaveCampaign(campaign);

            testIds.Add(campaign.Id);

            //Assert
            Assert.IsNotNull(c.Id);
            Assert.AreEqual(campaign.Id, c.Id);

            _offerRepo.DeleteCampaign(campaign.Id);

            var campaignDeleted = _offerRepo.Campaigns.FirstOrDefault(x => x.Id == campaign.Id);

            Assert.IsTrue(campaignDeleted == null);
        }