﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ctrip.SOA.Comm;
using Arch.SOA.BLL.Check;
using Moq;
using Moq.Protected;

namespace Arch.SOA.QETest
{
    [TestClass()]
    public class IPAddressCheckTest
    {
        //[TestMethod]
        //public void ValidIPTest()
        //{
        //    IPAddressCheck IPCheck = new IPAddressCheck();
        //    RequestHead head = new RequestHead();
        //    head.RequestType = "SOA.Example.GetCityRequest";
        //    bool expected = true;
        //    bool actual = IPCheck.IsValid(head);
        //    Assert.AreEqual(expected, actual);
        //}

        [TestMethod]
        public void NotExistedIPTest()
        {
            IPAddressCheck IPCheck = new IPAddressCheck();
            RequestHead head = new RequestHead();
            Ctrip.SOA.Comm.Utility.ClientIPFactory.Getter = new Ctrip.SOA.Comm.Utility.MockIPGetter("173.16.145.26");
            head.RequestType = "SOA.Example.GetCityRequest".ToLower();
            bool expected = false;
            bool actual = IPCheck.IsValid(head);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void InValidIPTest()
        {
            IPAddressCheck IPCheck = new IPAddressCheck();
            RequestHead head = new RequestHead();
            Ctrip.SOA.Comm.Utility.ClientIPFactory.Getter = new Ctrip.SOA.Comm.Utility.MockIPGetter("147.16.13.21");
            head.RequestType = "SOA.Example.GetCityRequest".ToLower();
            bool expected = false;
            bool actual = IPCheck.IsValid(head);
            Assert.AreEqual(expected, actual);
        }


        [TestMethod]
        public void SepcialIPTest()
        {
            IPAddressCheck IPCheck = new IPAddressCheck();
            RequestHead head = new RequestHead();
            Ctrip.SOA.Comm.Utility.ClientIPFactory.Getter = new Ctrip.SOA.Comm.Utility.MockIPGetter("0");
            head.RequestType = "SOA.Example.GetCityRequest".ToLower();
            bool expected = true;
            bool actual = IPCheck.IsValid(head);
            Assert.AreEqual(expected, actual);
        }


        [TestMethod]
        public void SepcialIPTest2()
        {
            IPAddressCheck IPCheck = new IPAddressCheck();
            RequestHead head = new RequestHead();
            Ctrip.SOA.Comm.Utility.ClientIPFactory.Getter = new Ctrip.SOA.Comm.Utility.MockIPGetter("192.168.83.*");
            head.RequestType = "SOA.Example.GetCityRequest".ToLower();
            bool expected = true;
            bool actual = IPCheck.IsValid(head);
            Assert.AreEqual(expected, actual);
        }

    }
}
