コード例 #1
0
        /// <summary>
        /// Check if an user is existing with some rule.
        /// </summary>
        /// <param name="newUser"></param>
        /// <returns></returns>
        public static bool IsExisting(User newUser)
        {
            // new instant of user matcher
            IUserMatcher userMatcher = new UserMatcher();

            // add all rules for user matcher
            userMatcher.AddRule(new DistanceMatcher());
            userMatcher.AddRule(new NameAddressMatcher());
            userMatcher.AddRule(new ReferralCodeMatcher());

            if (existingUserList.Find(user => userMatcher.IsMatch(newUser, user)) != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        public void IsMatch_MatchAddress_ReturnTrue()
        {
            var     addressMatcher = new UserMatcher();
            Address address1       = new Address()
            {
                Suburb        = "Level 3",
                StreetAddress = "51_Pitt Street",
                State         = "Sydney NSW-2000",
                Latitude      = 1100,
                Longitude     = 2000,
            };
            User newUser = new User()
            {
                Address      = address1,
                Name         = "Luong",
                ReferralCode = "ABC123"
            };

            Address address2 = new Address()
            {
                Suburb        = "Level 3",
                StreetAddress = "51_Pitt Street",
                State         = "Sydney NSW-2000",
                Latitude      = 110,
                Longitude     = 200,
            };
            User existingUser = new User()
            {
                Address      = address2,
                Name         = "Luong 2",
                ReferralCode = "ABC123"
            };

            var isMatch = addressMatcher.IsMatch(newUser, existingUser);

            Assert.True(isMatch);
        }