public void Search_Subscriber_Exists_Only_In_Provisioning_Using_TN_provisining_results_are_returned()
        {
            using (ShimsContext.Create())
            {
                //Arrange
                var myContext = new SIMPLTestContext();

                ShimCurrentUser.AsUserDto = new SIMPLTestContext().GetFakeUserDtoObject;
                var subscriberId = "TESTSUBID";
                //search criteria
                var subscriberSearchViewModel = new SubscriberSearchViewModel
                {
                    PhoneNumber = "999999999",
                    State = "CT",
                    ProvisionedSearch = true
                };

                //expected search results
                var expectedSearchResults = new[]
                {
                    new
                    {
                        ID = subscriberId,
                        ExistsInBilling = false,
                        ExistsInProvisioning = true,
                        Phone = "999-999-9999",
                        Name = "jesse",
                        LocationID = "9999999",
                        AddressLine1 = subscriberSearchViewModel.Address1,
                        AddressLine2 = subscriberSearchViewModel.Address2,
                        CityName = subscriberSearchViewModel.City,
                        StateName = (string)null,
                        ZipCode = subscriberSearchViewModel.Zip,
                        DataSource=1,
                        Environment = "",
                        Status = 0
                    }
                };

                var expectedResult = new
                {
                    status = "partialsuccessprovisioning",
                    isModal = false,
                    searchResults = expectedSearchResults,
                    provisioned = true

                }.ToJSON();

                var fakeSubscriberList = new SubscriberCollection()
                {
                    myContext.GetFakeRosettianSubscriber(subscriberId, "jesse", "", "9999999999", myContext.GetFakeRosettianCustomField(), myContext.GetFakeRosettianAccountObject())
                };

                //Search Subscriber from Triad
                ShimProvisioningServiceClient.AllInstances.SearchSubscribersSearchFieldsUser =
                    delegate
                    {
                        return fakeSubscriberList;
                    };

                //Search Subscriber from Dpi
                ShimBillingServiceClient.AllInstances.SearchSubscriberBillingSearchFieldsUser =
                    delegate
                    {
                        return new BillingSearchSubscriberResponse();
                    };

                var actionResult = SearchControllerForTests.SearchCompositeSubscribers(subscriberSearchViewModel) as JsonResult;

                Assert.IsNotNull(actionResult, "SearchSubscribers  returned null");

                var actualJsonResult = actionResult.Data.ToJSON().Replace(" ", "");

                Assert.AreEqual(expectedResult, actualJsonResult);

            }
        }
        public void Search_Subscriber_When_Billing_Throws_Exception()
        {
            using (ShimsContext.Create())
            {
                //Arrange
                var myContext = new SIMPLTestContext();

                var fakeUserDto = myContext.GetFakeUserDtoObject();
                ShimCurrentUser.AsUserDto = () => fakeUserDto;

                //search criteria
                var subscriberSearchViewModel = new SubscriberSearchViewModel
                {

                    SubscriberID = "370001704986"
                };

                var expectedSearchResults = new List<SubscriberSearchResult>();
                var record = new SubscriberSearchResult
                {
                    ID = "TESTSUBID",
                    ExistsInBilling = false,
                    ExistsInProvisioning = true,
                    Phone = "999-999-9999",
                    Name = "ProvisioningTestFirstNameLast",
                    LocationID = "9999999",
                    AddressLine1 = "123FakeSt.",
                    AddressLine2 = "Apt2",
                    CityName = "FakeCity",
                    StateName = "WA",
                    ZipCode = "99999",
                    DataSource = SubscriberEnums.SubscriberDataSource.Provisioning,
                    Environment = ""
                };
                expectedSearchResults.Add(record);

                var expectedResult = new
                {
                    status = "error",
                    isModal = false,
                    searchResults = new List<SubscriberSearchResult>(),
                    provisioned = false

                }.ToJSON();

                var fakeSubscriberList = new SubscriberCollection()
                {
                    myContext.GetFakeRosettianSubscriber("TESTSUBID", "ProvisioningTestFirstName", "Last", "9999999999", myContext.GetFakeRosettianCustomField(), myContext.GetFakeRosettianAccountObject(), myContext.GetFakeRosettianLocationObject())
                };

                ShimErrorLoggingService.AllInstances.LogErrorNoContextException = delegate { };
                //Search Subscriber from provisioning
                ShimProvisioningServiceClient.AllInstances.SearchSubscribersSearchFieldsUser =
                    delegate
                    {
                        return fakeSubscriberList;
                    };

                //Search Subscriber from billing
                ShimBillingServiceClient.AllInstances.SearchSubscriberBillingSearchFieldsUser =
                    delegate
                    {
                        throw new Exception();
                    };

                var searchController = DependencyResolver.Current.GetService<SearchController>();

                var actionResult = searchController.SearchCompositeSubscribers(subscriberSearchViewModel) as JsonResult;

                Assert.IsNotNull(actionResult, "SearchSubscribers  returned null");

                var actualJsonResult = actionResult.Data.ToJSON().Replace(" ", "");

                Assert.AreEqual(expectedResult, actualJsonResult);

            }
        }
        public void Search_Subscriber_Exists_Only_In_Provisioning_Using_Name_And_State_and_provisioning_results_are_returned()
        {
            using (ShimsContext.Create())
            {
                //Arrange
                var myContext = new SIMPLTestContext();

                ShimCurrentUser.AsUserDto = new SIMPLTestContext().GetFakeUserDtoObject;

                var subscriberid = "FakeSubscriberId";

                //search criteria
                var subscriberSearchViewModel = new SubscriberSearchViewModel
                {
                    Name = "Fake Name",
                    State = "WA",
                    ProvisionedSearch = true
                };

                //expected search results - we remove spaces so that we can properly assert on the json string
                var expectedSearchResults = new List<SubscriberSearchResult>()
                {
                    new SubscriberSearchResult
                    {
                        ID = subscriberid,
                        ExistsInBilling = false,
                        ExistsInProvisioning = true,
                        Phone = "",
                        Name = "FakeName",
                        LocationID = "9999999",
                        AddressLine1 = "123FakeSt.",
                        AddressLine2 = "Apt2",
                        StateName = "WA",
                        ZipCode = "99999",
                        CityName = "FakeCity",
                        DataSource = SubscriberEnums.SubscriberDataSource.Provisioning,
                        Environment = ""
                    }
                };

                var expectedResult = new
                {
                    status = "partialsuccessprovisioning",
                    isModal = false,
                    searchResults = expectedSearchResults,
                    provisioned = true

                }.ToJSON();

                var fakeSubscriberList = new SubscriberCollection()
                {
                    myContext.GetFakeRosettianSubscriber(subscriberid, "FakeName", "", "", myContext.GetFakeRosettianCustomField(), myContext.GetFakeRosettianAccountObject(), myContext.GetFakeRosettianLocationObject())
                };

                //Search Subscriber from Triad
                ShimProvisioningServiceClient.AllInstances.SearchSubscribersSearchFieldsUser =
                    delegate
                    {
                        return fakeSubscriberList;
                    };

                //Search Subscriber from Dpi
                ShimBillingServiceClient.AllInstances.SearchSubscriberBillingSearchFieldsUser =
                    delegate
                    {
                        return new BillingSearchSubscriberResponse();
                    };

                var searchController = DependencyResolver.Current.GetService<SearchController>();

                var actionResult = searchController.SearchCompositeSubscribers(subscriberSearchViewModel) as JsonResult;

                Assert.IsNotNull(actionResult, "SearchSubscribers  returned null");

                var actualJsonResult = actionResult.Data.ToJSON().Replace(" ", "");

                Assert.AreEqual(expectedResult, actualJsonResult);

            }
        }