Example #1
0
        public void Match()
        {
            //Arrange
            IOfferRepository offerRepository = new MongoOfferRepo();

            var user = _repo.SaveUser(MongoDbTestUtil.CreateUserCustomer());

            var profile = MongoDbTestUtil.CreateProfileWithPreferences(user.Id);

            //Act
            var p = _repo.SaveProfile(profile);

            //Assert
            Assert.IsNotNull(p.Id);
            Assert.AreEqual(p.UserId, profile.UserId);
            Assert.AreEqual(p.Preferences, profile.Preferences);

            _repo.DeleteProfile(p.Id);
            var profileDeleted = _repo.Profiles.FirstOrDefault(x => x.Id == p.Id);

            Assert.IsTrue(profileDeleted == null);

            _repo.DeleteUser(user.Id);

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

            Assert.IsNull(userGet);
        }
Example #2
0
        public void Get_UserById_AndEmail_And_Delete()
        {
            //Arrange
            User user1  = MongoDbTestUtil.CreateUserCustomer();
            bool exists = _repo.DoesAccountExist(user1.Email, user1.Password);

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

            var user = _repo.SaveUser(user1);

            //Act
            var userGet          = _repo.GetUser(user.Id);
            var userGetFromEmail = _repo.GetUserByEmail(user.Email, user.Password);

            //Assert
            Assert.AreEqual(user1.Id, userGet.Id);
            Assert.AreEqual(user1.Id, userGetFromEmail.Id);

            _repo.DeleteUser(user.Id);

            userGet = _repo.GetUser(user.Id);
            Assert.IsNull(userGet);
        }
Example #3
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);
        }
Example #4
0
        public void Matching_On_Different_Category_But_Same_Keywords_Returns_No_Results()
        {
            var offer = new Offer
            {
                Id          = ObjectId.GenerateNewId().ToString(),
                ProfileId   = ObjectId.GenerateNewId().ToString(),
                Category    = "Books",
                CreatedBy   = ObjectId.GenerateNewId().ToString(),
                Description = null,
                Expires     = DateTime.Now.AddDays(40),
                Keywords    = new List <string>
                {
                    "cookies"
                },
                Name        = "Dumbbell Sale",
                Status      = Offer.StatusType.Pending,
                IsRecurring = false
            };

            var offerSaved = _offerService.CreateOffer(offer);

            _offerService.ActivateOffer(offerSaved.Id);

            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, "Food", new List <string> {
                "cookies"
            }));

            //Act
            var matchingOffers = _match.GetActiveMatchesForUser(user.UserId).FirstOrDefault().Value.Count;

            Assert.IsTrue(matchingOffers == 0);

            _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);
        }
 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);
 }
Example #6
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);
        }
Example #7
0
        public void Create_Duplicate_User_Throws_Exception()
        {
            var user1 = _repo.CreateUser(MongoDbTestUtil.CreateUserCustomer());

            try
            {
                _repo.CreateUser(MongoDbTestUtil.CreateUserCustomer());
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.Message == "User already exists!");
                _repo.DeleteUser(user1.Id);
                throw;
            }
        }
Example #8
0
        public void Can_Create_And_Delete_Profile()
        {
            //Arrange
            var profile = MongoDbTestUtil.CreateProfileWithoutPreferences();

            //Act
            var p = _repo.SaveProfile(profile);

            //Assert
            Assert.IsNotNull(p.Id);
            Assert.AreEqual(p.UserId, profile.UserId);

            _repo.DeleteProfile(p.Id);
            var profileDeleted = _repo.Profiles.FirstOrDefault(x => x.Id == p.Id);

            Assert.IsTrue(profileDeleted == null);
        }
Example #9
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);
        }
Example #11
0
        public void Add_Offer_To_Index_FindByStemmingAndRemove()
        {
            //searching for "drinking" will return anything matching "drink"
            Offer offer = MongoDbTestUtil.CreateStemmingOffer(null, null, 10, Offer.StatusType.Active);

            SearchService.AddUpdateLuceneIndex(offer);

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

            Assert.AreEqual(1, results.Count);
            Assert.IsNotNull(results[0]);
            Assert.AreEqual(results[0].Name, "Early Bird Drink Special");

            SearchService.ClearLuceneOfferRecord(offer.Id);

            results = SearchService.Search("drinking").ToList();

            Assert.AreEqual(0, results.Count);
        }
        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);
        }