コード例 #1
0
        public void Get_Active_Matching_Offers_For_User()
        {
            //Arrange
            var offerSaved = _offerService.CreateOffer(MongoDbTestUtil.CreateOffer("Little Jebbies 5 Cent Coffee"));

            _offerService.ActivateOffer(offerSaved.Id);

            var offerSaved2 = _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.GetActiveMatchesForUser(user.UserId);

            var offersFound = matchingOffers.FirstOrDefault().Value;

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

            var matchingOffer = offersFound.FirstOrDefault();

            Assert.IsTrue(matchingOffer.Name == "Little Jebbies 5 Cent Coffee");
            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);
        }