Ejemplo n.º 1
0
        public void Detect_GivenAListOfTwoOrdersWithDifferentEmailsAndSameDealId_WillReturnEmptyList()
        {
            Order order1 = new Order { OrderId = 1, EmailAddress = "*****@*****.**", DealId = 1, CreditCardNo = string.Empty };
            Order order2 = new Order { OrderId = 2, EmailAddress = "*****@*****.**", DealId = 1, CreditCardNo = string.Empty };

            var detect = Solution.DetectFraudulentOrders(new List<Order> { order1, order2 });

            CollectionAssert.IsEmpty(detect);
        }
Ejemplo n.º 2
0
        public void Detect_GivenAListOfTwoOrdersWithSameAddressButDifferentCCCNoAndDifferentEmailAddresses_ReturnsBothIds()
        {
            Order order1 = new Order { OrderId = 1, StreetAddress = "asd", City = "Asd", State = "Asd", ZipCode = "asd", DealId = 1, CreditCardNo = "12345689010", EmailAddress = "*****@*****.**" };
            Order order2 = new Order { OrderId = 2, StreetAddress = "aSd", City = "asd", State = "asd", ZipCode = "asD", DealId = 1, CreditCardNo = "12345689011", EmailAddress = "*****@*****.**" };

            var detect = Solution.DetectFraudulentOrders(new List<Order> { order1, order2 });

            CollectionAssert.Contains(detect, 1);
            CollectionAssert.Contains(detect, 2);
        }
Ejemplo n.º 3
0
        public void Detect_GivenAListOfTwoOrdersWithEmailOnlyDifferentByCaseAndSameDealIdButDifferentCCCNo_WillReturnBothIds()
        {
            Order order1 = new Order { OrderId = 1, EmailAddress = "[email protected]", DealId = 1, CreditCardNo = "12345689010" };
            Order order2 = new Order { OrderId = 2, EmailAddress = "[email protected]", DealId = 1, CreditCardNo = "12345689011" };

            var detect = Solution.DetectFraudulentOrders(new List<Order> { order1, order2 });

            CollectionAssert.Contains(detect, 1);
            CollectionAssert.Contains(detect, 2);
        }
Ejemplo n.º 4
0
        public void Detect_GivenAListOfTwoOrdersWithEmailDifferentOnlyByPartAfterPlusButDifferentCCCNo_ReturnsBothIds()
        {
            Order order1 = new Order { OrderId = 1, EmailAddress = "*****@*****.**", DealId = 1, CreditCardNo = "12345689010" };
            Order order2 = new Order { OrderId = 2, EmailAddress = "*****@*****.**", DealId = 1, CreditCardNo = "12345689011" };

            var detect = Solution.DetectFraudulentOrders(new List<Order> { order1, order2 });

            CollectionAssert.Contains(detect, 1);
            CollectionAssert.Contains(detect, 2);
        }
Ejemplo n.º 5
0
        public void Detect_GivenAListOfTwoOrdersWithSameEmailAndSameDealIdButSameCCCNo_ReturnsEmptyList()
        {
            Order order1 = new Order { OrderId = 1, EmailAddress = "*****@*****.**", DealId = 1, CreditCardNo = "12345689011" };
            Order order2 = new Order { OrderId = 2, EmailAddress = "*****@*****.**", DealId = 1, CreditCardNo = "12345689011" };

            var detect = Solution.DetectFraudulentOrders(new List<Order> { order1, order2 });

            CollectionAssert.IsEmpty(detect);
        }
Ejemplo n.º 6
0
        public void Normalize_Always_ReplacesLongWordsWithTheirShortForms()
        {
            var order = new Order
                            {
                                StreetAddress = "Street Road",
                                State = "Illinois California New York",
                            };
            var orders = new List<Order> { order };

            Solution.Normalize(orders);

            order = orders[0];
            Assert.AreEqual("st. rd.", order.StreetAddress);
            Assert.AreEqual("il ca ny", order.State);
        }
Ejemplo n.º 7
0
        public void Detect_GivenAListOfTwoOrdersWithTheSameEmailAddressAndDealIdButDifferentCCCNo_WillReturnBothIdsInAscendingOrder()
        {
            Order order1 = new Order { OrderId = 1, EmailAddress = "[email protected]", DealId = 1, CreditCardNo = "12345689010" };
            Order order2 = new Order { OrderId = 2, EmailAddress = "[email protected]", DealId = 1, CreditCardNo = "12345689011" };

            var detect = Solution.DetectFraudulentOrders(new List<Order> { order1, order2 });

            Assert.AreEqual(1, detect[0]);
            Assert.AreEqual(2, detect[1]);
        }
Ejemplo n.º 8
0
        public void Normalize_Always_NormalizesEmailAddress()
        {
            var order = new Order
            {
                EmailAddress = "*****@*****.**"
            };
            var orders = new List<Order> { order };

            Solution.Normalize(orders);

            order = orders[0];
            Assert.AreEqual("*****@*****.**", order.EmailAddress);
        }
Ejemplo n.º 9
0
 private static void NormalizeOrder(Order order)
 {
     NormalizeAddress(order);
     order.EmailAddress = NormalizeEmailAddress(order);
 }
Ejemplo n.º 10
0
 private static string NormalizeEmailAddress(Order order)
 {
     var emailAddress = order.EmailAddress.ToLowerInvariant();
     var emailParts = emailAddress.Split('@');
     var userName = emailParts[0].Replace(".", string.Empty);
     userName = userName.Split('+')[0];
     var address = string.Join("@", userName, emailParts[1]);
     return address;
 }
Ejemplo n.º 11
0
        private static void NormalizeAddress(Order order)
        {
            order.StreetAddress = order.StreetAddress.ToLowerInvariant();
            order.City = order.City.ToLowerInvariant();
            order.State = order.State.ToLowerInvariant();
            order.ZipCode = order.ZipCode.ToLowerInvariant();

            foreach (var stateReplacer in stateReplacers)
            {
                order.State = order.State.Replace(stateReplacer.Key, stateReplacers[stateReplacer.Key]);
            }

            foreach (var addressReplacer in addressReplacers)
            {
                order.StreetAddress = order.StreetAddress.Replace(addressReplacer.Key, addressReplacers[addressReplacer.Key]);
            }
        }
Ejemplo n.º 12
0
 private static bool IsSameAddress(Order order1, Order order2)
 {
     return order1.StreetAddress == order2.StreetAddress
         && order1.City == order2.City
         && order1.State == order2.State
         && order1.ZipCode == order2.ZipCode;
 }
Ejemplo n.º 13
0
        private static bool AreFraudulent(Order order1, Order order2)
        {
            var areFraudulent = order1.DealId == order2.DealId;
            areFraudulent &= !(order1.CreditCardNo.Equals(order2.CreditCardNo, StringComparison.InvariantCulture));
            areFraudulent &= (order1.EmailAddress == order2.EmailAddress) || IsSameAddress(order1, order2);

            return areFraudulent;
        }