Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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;
            }
        }