public void Index_User_Is_Shown_Index2_View_With_A_Single_ONT_And_A_Single_RG()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                ShimRosettianClient.AllInstances.LoadLocationStringUserDto = delegate { return new LocationDto(); };
                ShimRosettianClient.AllInstances.GetServicesUserDto = delegate { return new ServiceCollectionDto(); };
                const string subscriberID = "999999999999";
                const string subscriberContactPhone = "9999999999";
                const string firstName = "Test";
                const string lastName = "Account";
                const string deviceID = "11111111";
                var myContext = new SIMPLTestContext();

                // Build Fake UserDto
                var fakeUserDto = myContext.GetFakeUserDtoObject();

                // Fake call to CurrentUser.AsUserDto()
                ShimCurrentUser.AsUserDto = () => fakeUserDto;
                ShimCurrentUser.GetInstance = () => new ShimCurrentUser
                {
                    UniqueIdGet = () => "abc123",
                };

                ShimCurrentUser.AllInstances.RolesGet = delegate { return new List<int> { 1 }; };

                // Shim Permissions.UserHasGrant
                ShimPermissions.UserHasGrantGrant = delegate { return true; };

                // Shim feature flag
                ShimFeatureFlags.IsEnabledString = delegate { return true; };

                // Build Fake AccountDto
                var fakeAccountDto = myContext.GetFakeAccountDtoObject();

                // Build Fake CustomFieldDto
                var fakeCustomFieldDto = myContext.GetFakeCustomFieldDto();

                // Build Fake SubscriberDto
                var fakeSubscriberDto = myContext.GetFakeSubscriberDto(subscriberID, firstName, lastName, subscriberContactPhone, fakeCustomFieldDto, fakeAccountDto);

                // Build Fake PhoneNumberAsIdDto (internally builds the Fake TelephoneNumberDto)
                var fakePhoneNumberAsIdDto = myContext.GetFakePhoneNumberAsIdDto(subscriberContactPhone);

                // Build Fake BillingAccountIdDto
                var fakeBillingAccountIdDto = myContext.GetFakeBillingAccountIdDto(subscriberID, fakePhoneNumberAsIdDto);

                // Build Fake CustomerAccountIdDto
                var fakeCustomerAccountIdDto = myContext.GetFakeCustomerAccountIdDto(subscriberID, fakePhoneNumberAsIdDto);

                // Build Fake CustomerAccountDto (internaly builds the Fake IndividualNameDto,
                // the Fake IndividualDto, and the Fake CustomerDto)
                var fakeCustomerAccountDto = myContext.GetFakeCustomerAccountDto(firstName, lastName, subscriberID, fakeBillingAccountIdDto, fakeCustomerAccountIdDto);

                // A single ONT
                var fakeEquipmentTypeDtoONT = new EquipmentTypeDto
                {
                    ONTModel = new ONTModelDto(),
                    Category = EquipmentCategoryDto.ONTDataPort
                };

                var myEquipmentDto1 = new EquipmentDto()
                {
                    Type = fakeEquipmentTypeDtoONT
                };

                // A single ONT
                var fakeEquipmentTypeDtoRG = new EquipmentTypeDto
                {
                    ONTModel = new ONTModelDto(),
                    Category = EquipmentCategoryDto.RGDataPort
                };

                var myEquipmentDto2 = new EquipmentDto()
                {
                    Type = fakeEquipmentTypeDtoRG
                };

                // A single Video Device
                var fakeEquipmentTypeDtoVideoDevice = new EquipmentTypeDto
                {
                    ONTModel = null
                };

                var myEquipmentDto3 = new EquipmentDto()
                {
                    Type = fakeEquipmentTypeDtoVideoDevice
                };

                fakeSubscriberDto.Accounts[0].Equipment = new EquipmentCollectionDto();
                fakeSubscriberDto.Accounts[0].Equipment.Add(myEquipmentDto1);
                fakeSubscriberDto.Accounts[0].Equipment.Add(myEquipmentDto2);
                fakeSubscriberDto.Accounts[0].Equipment.Add(myEquipmentDto3);

                // Build Fake CompositeSubscriber
                var fakeCompositeSubscriber = new CompositeSubscriber()
                {
                    SubscriberTriad = fakeSubscriberDto,
                    SubscriberDpi = fakeCustomerAccountDto
                };

                // Fake the BusinessFacade.LoadCompositeSubscriber call
                ShimBusinessFacade.AllInstances.LoadCompositeSubscriberStringStringUserDto =
                    delegate { return fakeCompositeSubscriber; };

                // Build Fake fakeEquipmentDto
                var fakeEquipmentDto = new List<EquipmentDto>();
                fakeEquipmentDto.Add(myEquipmentDto1);
                fakeEquipmentDto.Add(myEquipmentDto2);
                fakeEquipmentDto.Add(myEquipmentDto3);

                // Fake the RosettianClient.SearchEquipment call
                ShimRosettianClient.AllInstances.SearchEquipmentSearchFieldsDtoUserDto =
                    (myRosettianClient, mySubscriberID, myUserObject) => fakeEquipmentDto;

                // A single ONT
                var fakeONT = new ONT
                {
                    Type = fakeEquipmentTypeDtoONT
                };

                // A single RG
                var fakeRG = new ONT
                {
                    Type = fakeEquipmentTypeDtoRG
                };

                var fakeONTAndRGList = new List<ONT>();
                fakeONTAndRGList.Add(fakeONT);
                fakeONTAndRGList.Add(fakeRG);

                var fakeONTList = new List<ONT>();
                fakeONTList.Add(fakeONT);

                var fakeRGList = new List<ONT>();
                fakeRGList.Add(fakeRG);

                // Fake the EquipmentExtension.ToONTList call
                SIMPL.Areas.Common.Extensions.Fakes.ShimEquipmentExtension.ToONTListIEnumerableOfEquipmentDto =
                    (myEquipmentList) =>
                    {
                        if (myEquipmentList != null)
                        {
                            var items = myEquipmentList.ToList();

                            if (items.Any())
                            {
                                if (items.Count == 2)
                                {
                                    return fakeONTAndRGList;
                                }
                                if (items[0].Type.Category == EquipmentCategoryDto.ONTDataPort)
                                {
                                    return fakeONTList;
                                }
                                if (items[0].Type.Category == EquipmentCategoryDto.RGDataPort)
                                {
                                    return fakeRGList;
                                }
                            }
                        }

                        return new List<ONT>();
                    };

                // A single Video Device
                var fakeVideoDevice = new SerializableVideoDevice();
                var fakeVideoDeviceList = new List<SerializableVideoDevice>();
                fakeVideoDeviceList.Add(fakeVideoDevice);

                // Fake the EquipmentExtension.ToVideoDeviceList call
                ShimEquipmentExtension.ToVideoDeviceListIEnumerableOfEquipmentDto =
                    (myVideoDeviceList) => fakeVideoDeviceList;

                var currentSubscriber = new ShimCurrentSubscriber
                {
                    SubIdGet = () => "SubId",
                    ProvisionedServicesListGet = () => new List<ServiceDto>()
                };
                ShimCurrentSubscriber.GetInstance = () => currentSubscriber;

                // Fake the CurrentSubscriber.SetInstance call
                ShimCurrentSubscriber.SetInstanceCompositeSubscriberSubscriberModel = (myCompositeSubscriber, mySubscriberModel) => { };

                // Fake the CurrentSubscriber.DataProductType call
                ShimCurrentSubscriber.AllInstances.DataProductTypeGet = (myResult) => SubscriberEnums.DataProductType.Ftth;

                // Fake the CurrentSubscriber.VideoProductType call
                ShimCurrentSubscriber.AllInstances.VideoProductTypeGet = (myResult) => SubscriberEnums.VideoProductType.FiberRf;

                // Fake the CurrentSubscriber.DataProductType call
                ShimCurrentSubscriber.AllInstances.VoiceProductTypeGet = (myResult) => SubscriberEnums.VoiceProductType.FiberPots;

                // Fake the CurrentSubscriber.DataProductType call
                ShimCurrentSubscriber.AllInstances.StateGet = (myResult) => "CT";

                ShimCurrentUser.RetrieveUserRolesString = (myUniqueId) => new List<int>() { 1 };

                //Fake DB call to get Headends
                var headends = new List<HeadEnd>()
                {
                    new HeadEnd()
                    {
                        EntityKey = new EntityKey(),
                        headend_code = "1",
                        headend_loc = "1",
                        headend_name = "1",
                        headend_nbr = 1,
                        location_id = "1",
                        location_nbr = 1
                    }
                };

                ShimDBCache.HeadEndCodesGet = delegate { return headends; };

                //Fake Line Results DB Call.
                var testResultsDbSet = new ShimDbSet<test_results>();

                testResultsDbSet.Bind(new List<test_results>().AsQueryable());

                ShimLineTestEntities.AllInstances.test_resultsGet = delegate { return testResultsDbSet; };

                // 1st Act
                var result = SubscriberControllerForTests.Index(subscriberID, deviceID) as ViewResult;

                // 1st set of Asserts
                Assert.IsNotNull(result, "SubscriberController Index method returned null");
                Assert.IsNotNull(result.ViewName, "result.ViewName method is null");
                const string expectedViewName = "Index2";
                Assert.IsTrue(expectedViewName == result.ViewName, "Expected: " + expectedViewName + ", Actual: " + result.ViewName);
                Assert.IsTrue(result.ViewName.Equals(expectedViewName));
                Assert.IsTrue(result.Model is SubscriberModel, "Not SubscriberModel");

                // 2nd Act
                var testSubscriberModel = result.Model as SubscriberModel;

                // 2nd set of Asserts
                var successCode = "200";
                Assert.AreEqual(successCode, testSubscriberModel.ActionResponse.Code, "Test threw an exception {0}{0}{1}", Environment.NewLine, testSubscriberModel.ActionResponse.Message);

                var jss = new JavaScriptSerializer();
                var expectedModel = fakeCompositeSubscriber.MapToSubscriberModel();
                expectedModel.SubEquipmentModel = new SubscriberEquipmentModel
                {
                    ONTList = fakeONTAndRGList,
                    ONTOnlyList = fakeONTList,
                    RGOnlyList = fakeRGList,
                    VideoDeviceList = fakeVideoDeviceList,
                    AccessDeviceList = fakeONTAndRGList,
                    LoadedSubID = subscriberID,
                    LoadedLocID = expectedModel.SubLocationModel.LocationID,
                    WanIpAddress = string.Empty,
                    MaxStb = string.Empty
                };
                expectedModel.SubLocationModel.LoadedDeviceID = deviceID;
                Assert.AreEqual(jss.Serialize(expectedModel.ActionResponse), jss.Serialize(testSubscriberModel.ActionResponse), "SubscriberModel");
                Assert.AreEqual(jss.Serialize(expectedModel.SubDetailsModel), jss.Serialize(testSubscriberModel.SubDetailsModel), "SubscriberDetailsModel");
                Assert.AreEqual(jss.Serialize(expectedModel.SubLocationModel), jss.Serialize(testSubscriberModel.SubLocationModel), "SubscriberLocationModel");

                // Since deviceID is not null, check to verify that LoadedDeviceID has the expected value
                Assert.AreEqual(deviceID, expectedModel.SubLocationModel.LoadedDeviceID, "LoadedDeviceID should not be string.Empty is deviceID is {0}", deviceID);
                Assert.AreEqual(jss.Serialize(expectedModel.SubServicesModel), jss.Serialize(testSubscriberModel.SubServicesModel), "SubscriberServicesModel");
                Assert.AreEqual(jss.Serialize(expectedModel.SubEquipmentModel.ONTList), jss.Serialize(testSubscriberModel.SubEquipmentModel.ONTList), "SubscriberEquipmentModel ONTList");
                Assert.AreEqual(jss.Serialize(expectedModel.SubEquipmentModel.ONTOnlyList), jss.Serialize(testSubscriberModel.SubEquipmentModel.ONTOnlyList), "SubscriberEquipmentModel ONTOnlyList");
                Assert.AreEqual(jss.Serialize(expectedModel.SubEquipmentModel.RGOnlyList), jss.Serialize(testSubscriberModel.SubEquipmentModel.RGOnlyList), "SubscriberEquipmentModel RGOnlyList");
                Assert.AreEqual(jss.Serialize(expectedModel.SubEquipmentModel.VideoDeviceList), jss.Serialize(testSubscriberModel.SubEquipmentModel.VideoDeviceList), "SubscriberEquipmentModel VideoDeviceList");
                Assert.AreEqual(jss.Serialize(expectedModel.SubEquipmentModel), jss.Serialize(testSubscriberModel.SubEquipmentModel), "SubscriberEquipmentModel entire object");
            }
        }
        public void Index_SubscriberDetails_AccountType()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                const string subscriberId = "1234567890";
                const string subscriberContactPhone = "4250010001";
                const string firstName = "JAMES";
                const string lastName = "SMITH";
                const AccountTypeDto accountType = AccountTypeDto.Business;
                var myContext = new SIMPLTestContext();

                // Build Fake UserDto
                var fakeUserDto = myContext.GetFakeUserDtoObject();

                // Fake call to CurrentUser.AsUserDto()
                ShimCurrentUser.AsUserDto = () => fakeUserDto;
                ShimCurrentUser.GetInstance = () => new ShimCurrentUser
                {
                    UniqueIdGet = () => "abc123"
                };

                // Build Fake AccountDto
                var fakeAccountDto = myContext.GetFakeAccountDtoObject();
                fakeAccountDto.AccountType = accountType;

                // Build Fake CustomFieldDto
                var fakeCustomFieldDto = myContext.GetFakeCustomFieldDto();

                // Build Fake SubscriberDto
                var fakeSubscriberDto = myContext.GetFakeSubscriberDto(subscriberId, firstName, lastName, subscriberContactPhone, fakeCustomFieldDto, fakeAccountDto);

                // Build Fake PhoneNumberAsIdDto (internally builds the Fake TelephoneNumberDto)
                var fakePhoneNumberAsIdDto = myContext.GetFakePhoneNumberAsIdDto(subscriberContactPhone);

                // Build Fake BillingAccountIdDto
                var fakeBillingAccountIdDto = myContext.GetFakeBillingAccountIdDto(subscriberId, fakePhoneNumberAsIdDto);

                // Build Fake CustomerAccountIdDto
                var fakeCustomerAccountIdDto = myContext.GetFakeCustomerAccountIdDto(subscriberId, fakePhoneNumberAsIdDto);

                // Build Fake CustomerAccountDto (internaly builds the Fake IndividualNameDto,
                // the Fake IndividualDto, and the Fake CustomerDto)
                var fakeCustomerAccountDto = myContext.GetFakeCustomerAccountDto(firstName, lastName, subscriberId, fakeBillingAccountIdDto, fakeCustomerAccountIdDto);

                // Build Fake CompositeSubscriber
                var fakeCompositeSubscriber = new CompositeSubscriber()
                {
                    SubscriberTriad = fakeSubscriberDto,
                    SubscriberDpi = fakeCustomerAccountDto
                };

                // Fake the BusinessFacade.LoadCompositeSubscriber call
                ShimBusinessFacade.AllInstances.LoadCompositeSubscriberStringStringUserDto =
                    delegate { return fakeCompositeSubscriber; };
                //TODO: Figure out why it is failing without below
                ShimRosettianClient.AllInstances.SearchEquipmentSearchFieldsDtoUserDto = delegate
                {
                    return new List<EquipmentDto>();
                };
                ShimRosettianClient.AllInstances.LoadLocationStringUserDto = delegate
                {
                    return new LocationDto();
                };

                ShimRosettianClient.AllInstances.SearchEquipmentSearchFieldsDtoUserDto = delegate
                {
                    return new List<EquipmentDto>();
                };
                ShimRosettianClient.AllInstances.LoadLocationStringUserDto = delegate
                {
                    return new LocationDto();
                };

                var currentSubscriber = new ShimCurrentSubscriber
                {
                    SubIdGet = () => subscriberId,
                    ProvisionedServicesListGet = () => new List<ServiceDto>()
                };
                ShimCurrentSubscriber.GetInstance = () => currentSubscriber;

                // Fake the CurrentSubscriber.SetInstance call
                ShimCurrentSubscriber.SetInstanceCompositeSubscriberSubscriberModel = (myCompositeSubscriber, mySubscriberModel) => { };

                // Call Index
                var result = SubscriberControllerForTests.Index(subscriberId, string.Empty) as ViewResult;

                // Validate view
                Assert.IsNotNull(result);
                Assert.AreEqual("Index2", result.ViewName, "ViewName does not match!");

                // Validate subscriber details account type
                var testSubscriberModel = result.Model as SubscriberModel ?? new SubscriberModel();

                var successCode = "200";
                Assert.AreEqual(successCode, testSubscriberModel.ActionResponse.Code, "Test threw an exception {0}{0}{1}", Environment.NewLine, testSubscriberModel.ActionResponse.Message);

                var actualSubDetailsModel = testSubscriberModel.SubDetailsModel;
                Assert.IsNotNull(actualSubDetailsModel, "SubscriberDetailsModel is null");
                Assert.AreEqual(subscriberId, actualSubDetailsModel.USI, "USI does not match");
                Assert.AreEqual(accountType, actualSubDetailsModel.AccountType, "AccountType does not match");
            }
        }
        public void LoadEditSubContent()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                const string subscriberId = "1234567890";
                const string subscriberContactPhone = "4250010001";
                const string firstName = "JAMES";
                const string lastName = "SMITH";
                const AccountTypeDto accountType = AccountTypeDto.Business;
                var myContext = new SIMPLTestContext();

                // Build Fake UserDto
                var fakeUserDto = myContext.GetFakeUserDtoObject();

                // Fake call to CurrentUser.AsUserDto()
                ShimCurrentUser.AsUserDto = () => fakeUserDto;
                ShimCurrentUser.GetInstance = () => new ShimCurrentUser
                {
                    UniqueIdGet = () => "abc123"
                };

                // Build Fake AccountDto
                var fakeAccountDto = myContext.GetFakeAccountDtoObject();
                fakeAccountDto.AccountType = accountType;

                // Build Fake CustomFieldDto
                var fakeCustomFieldDto = myContext.GetFakeCustomFieldDto();

                // Build Fake SubscriberDto
                var fakeSubscriberDto = myContext.GetFakeSubscriberDto(subscriberId, firstName, lastName, subscriberContactPhone, fakeCustomFieldDto, fakeAccountDto);

                // Build Fake PhoneNumberAsIdDto (internally builds the Fake TelephoneNumberDto)
                var fakePhoneNumberAsIdDto = myContext.GetFakePhoneNumberAsIdDto(subscriberContactPhone);

                // Build Fake BillingAccountIdDto
                var fakeBillingAccountIdDto = myContext.GetFakeBillingAccountIdDto(subscriberId, fakePhoneNumberAsIdDto);

                // Build Fake CustomerAccountIdDto
                var fakeCustomerAccountIdDto = myContext.GetFakeCustomerAccountIdDto(subscriberId, fakePhoneNumberAsIdDto);

                // Build Fake CustomerAccountDto (internaly builds the Fake IndividualNameDto,
                // the Fake IndividualDto, and the Fake CustomerDto)
                var fakeCustomerAccountDto = myContext.GetFakeCustomerAccountDto(firstName, lastName, subscriberId, fakeBillingAccountIdDto, fakeCustomerAccountIdDto);

                // Build Fake CompositeSubscriber
                var fakeCompositeSubscriber = new CompositeSubscriber()
                {
                    SubscriberTriad = fakeSubscriberDto,
                    SubscriberDpi = fakeCustomerAccountDto
                };

                // Fake the BusinessFacade.LoadCompositeSubscriber call
                ShimBusinessFacade.AllInstances.LoadCompositeSubscriberStringStringUserDto =
                    delegate { return fakeCompositeSubscriber; };

                var currentSubscriber = new ShimCurrentSubscriber
                {
                    SubIdGet = () => "SubId",
                    ProvisionedServicesListGet = () => new List<ServiceDto>()
                };
                ShimCurrentSubscriber.GetInstance = () => currentSubscriber;

                // Fake the CurrentSubscriber.SetInstance call
                ShimCurrentSubscriber.SetInstanceCompositeSubscriberSubscriberModel = (myCompositeSubscriber, mySubscriberModel) => { };

                // Fake the CurrentSubscriber.DataProductType call
                ShimCurrentSubscriber.AllInstances.StateGet = (myResult) => "CT";

                ShimCurrentUser.RetrieveUserRolesString = (myUniqueId) => new List<int>() { 1 };

                // Expected subscriber details model
                var expectedSubDetailsModel =
                    (fakeCompositeSubscriber.MapToSubscriberModel() ?? new SubscriberModel()).SubDetailsModel;
                Assert.IsNotNull(expectedSubDetailsModel, "Expected SubscriberDetailsModel is null");
                Assert.AreEqual(subscriberId, expectedSubDetailsModel.USI, "Expected USI does not match");
                Assert.AreEqual(accountType, expectedSubDetailsModel.AccountType, "Expected AccountType does not match");

                // Call LoadEditSubContent Action Method
                var result = SubscriberControllerForTests.LoadEditSubContent(expectedSubDetailsModel) as PartialViewResult;

                // Validate Action Method result
                Assert.IsNotNull(result, "LoadEditSubContent returned partial view is null");
                Assert.AreEqual("EditSub_Partial", result.ViewName, "LoadEditSubContent ViewName does not match!");

                // Validate returned subscriber details model
                var actualSubDetailsModel = result.Model as SubscriberDetailsModel;
                Assert.IsNotNull(actualSubDetailsModel, "Actual SubscriberDetailsModel is null");
                var jss = new JavaScriptSerializer();
                Assert.AreEqual(jss.Serialize(expectedSubDetailsModel), jss.Serialize(actualSubDetailsModel),
                    "SubscriberDetailsModel does not match");
            }
        }
        public void LoadEditSubContent_AccountTypeShowsUnknownInSubDetails_AccountTypeSelectListExcludesUnknown()
        {
            using (ShimsContext.Create())
            {
                // subscriber data
                const string subscriberId = "1234567890";
                const string subscriberContactPhone = "4250010001";
                const string firstName = "JAMES";
                const string lastName = "SMITH";
                const AccountTypeDto accountType = AccountTypeDto.Unknown;
                var myContext = new SIMPLTestContext();

                // fake userdto
                var fakeUserDto = myContext.GetFakeUserDtoObject();

                // set current instance
                ShimCurrentUser.AsUserDto = () => fakeUserDto;
                ShimCurrentUser.GetInstance = () => new ShimCurrentUser
                {
                    UniqueIdGet = () => "abc123"
                };

                // fake account
                var fakeAccountDto = myContext.GetFakeAccountDtoObject();
                fakeAccountDto.AccountType = accountType;

                // fake custome field
                var fakeCustomFieldDto = myContext.GetFakeCustomFieldDto();

                // fake subscriber
                var fakeSubscriberDto = myContext.GetFakeSubscriberDto(subscriberId, firstName, lastName, subscriberContactPhone, fakeCustomFieldDto, fakeAccountDto);

                // fake PhoneNumberAsIdDto (internally builds the Fake TelephoneNumberDto)
                var fakePhoneNumberAsIdDto = myContext.GetFakePhoneNumberAsIdDto(subscriberContactPhone);

                // fake BillingAccountIdDto
                var fakeBillingAccountIdDto = myContext.GetFakeBillingAccountIdDto(subscriberId, fakePhoneNumberAsIdDto);

                // fake CustomerAccountIdDto
                var fakeCustomerAccountIdDto = myContext.GetFakeCustomerAccountIdDto(subscriberId, fakePhoneNumberAsIdDto);

                // Build Fake CustomerAccountDto (internaly builds the Fake IndividualNameDto,
                // the Fake IndividualDto, and the Fake CustomerDto)
                var fakeCustomerAccountDto = myContext.GetFakeCustomerAccountDto(firstName, lastName, subscriberId, fakeBillingAccountIdDto, fakeCustomerAccountIdDto);

                // Build Fake CompositeSubscriber
                var fakeCompositeSubscriber = new CompositeSubscriber()
                {
                    SubscriberTriad = fakeSubscriberDto,
                    SubscriberDpi = fakeCustomerAccountDto
                };

                // Fake the BusinessFacade.LoadCompositeSubscriber call
                ShimBusinessFacade.AllInstances.LoadCompositeSubscriberStringStringUserDto =
                    delegate { return fakeCompositeSubscriber; };

                ShimCurrentSubscriber.GetInstance = () => new ShimCurrentSubscriber
                {
                    SubIdGet = () => "SubId",
                    ProvisionedServicesListGet = () => new List<ServiceDto>()
                };

                // Fake the CurrentSubscriber.SetInstance call
                ShimCurrentSubscriber.SetInstanceCompositeSubscriberSubscriberModel = (myCompositeSubscriber, mySubscriberModel) => { };

                // Fake the CurrentSubscriber.DataProductType call
                ShimCurrentSubscriber.AllInstances.StateGet = (myResult) => "CT";

                ShimCurrentUser.RetrieveUserRolesString = (myUniqueId) => new List<int>() { 1 };

                // expected subscriber details model
                var expectedSubDetailsModel =
                    (fakeCompositeSubscriber.MapToSubscriberModel() ?? new SubscriberModel()).SubDetailsModel;
                Assert.IsNotNull(expectedSubDetailsModel, "Expected SubscriberDetailsModel is null");
                Assert.AreEqual(subscriberId, expectedSubDetailsModel.USI, "Expected USI does not match");
                Assert.AreEqual(accountType, expectedSubDetailsModel.AccountType, "Expected AccountType does not match");

                // call LoadEditSubContent Action Method
                var result = SubscriberControllerForTests.LoadEditSubContent(expectedSubDetailsModel) as PartialViewResult;

                // validate view
                Assert.IsNotNull(result, "LoadEditSubContent returned partial view is null");
                Assert.AreEqual("EditSub_Partial", result.ViewName, "LoadEditSubContent ViewName does not match!");

                // validate returned subscriber details model
                var actualSubDetailsModel = result.Model as SubscriberDetailsModel;
                Assert.IsNotNull(actualSubDetailsModel, "Actual SubscriberDetailsModel is null");
                var jss = new JavaScriptSerializer();
                Assert.AreEqual(jss.Serialize(expectedSubDetailsModel), jss.Serialize(actualSubDetailsModel),
                    "SubscriberDetailsModel does not match");

                // validate the account type is still unknown
                Assert.AreEqual(AccountTypeDto.Unknown, actualSubDetailsModel.AccountType, "AccountType should be Unknown");

                // validate the account type select list used for "Edit" contains no unknown even the account type shows unknown in sub details
                Assert.IsTrue(
                    actualSubDetailsModel.AccountTypeSelectList.All(x => x.Value != AccountTypeDto.Unknown.ToString()),
                        "AccountType dropdownlist should not contain a list item of Unknown");
            }
        }
        public void Index_When_DeviceID_IsNull_User_Is_Shown_Index2_View()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                ShimRosettianClient.AllInstances.LoadLocationStringUserDto = delegate { return new LocationDto(); };
                ShimRosettianClient.AllInstances.GetServicesUserDto = delegate { return new ServiceCollectionDto(); };
                const string subscriberID = "999999999999";
                const string subscriberContactPhone = "9999999999";
                const string firstName = "Test";
                const string lastName = "Account";
                const string deviceID = null;
                var myContext = new SIMPLTestContext();

                // Build Fake UserDto
                var fakeUserDto = myContext.GetFakeUserDtoObject();

                // Fake call to CurrentUser.AsUserDto()
                ShimCurrentUser.AsUserDto = () => fakeUserDto;
                ShimCurrentUser.GetInstance = () => new ShimCurrentUser
                {
                    UniqueIdGet = () => "abc123"
                };

                ShimCurrentUser.AllInstances.RolesGet = delegate { return new List<int> {1}; };

                // Shim Permissions.UserHasGrant
                ShimPermissions.UserHasGrantGrant = delegate { return true; };

                // Shim feature flag
                ShimFeatureFlags.IsEnabledString = delegate { return true; };

                // Build Fake AccountDto
                var fakeAccountDto = myContext.GetFakeAccountDtoObject();

                // Build Fake CustomFieldDto
                var fakeCustomFieldDto = myContext.GetFakeCustomFieldDto();

                // Build Fake SubscriberDto
                var fakeSubscriberDto = myContext.GetFakeSubscriberDto(subscriberID, firstName, lastName, subscriberContactPhone, fakeCustomFieldDto, fakeAccountDto);

                // Build Fake PhoneNumberAsIdDto (internally builds the Fake TelephoneNumberDto)
                var fakePhoneNumberAsIdDto = myContext.GetFakePhoneNumberAsIdDto(subscriberContactPhone);

                // Build Fake BillingAccountIdDto
                var fakeBillingAccountIdDto = myContext.GetFakeBillingAccountIdDto(subscriberID, fakePhoneNumberAsIdDto);

                // Build Fake CustomerAccountIdDto
                var fakeCustomerAccountIdDto = myContext.GetFakeCustomerAccountIdDto(subscriberID, fakePhoneNumberAsIdDto);

                // Build Fake CustomerAccountDto (internaly builds the Fake IndividualNameDto,
                // the Fake IndividualDto, and the Fake CustomerDto)
                var fakeCustomerAccountDto = myContext.GetFakeCustomerAccountDto(firstName, lastName, subscriberID, fakeBillingAccountIdDto, fakeCustomerAccountIdDto);

                // Build Fake CompositeSubscriber
                var fakeCompositeSubscriber = new CompositeSubscriber()
                {
                    SubscriberTriad = fakeSubscriberDto,
                    SubscriberDpi = fakeCustomerAccountDto,
                };

                // Fake the BusinessFacade.LoadCompositeSubscriber call
                ShimBusinessFacade.AllInstances.LoadCompositeSubscriberStringStringUserDto =
                    delegate { return fakeCompositeSubscriber; };

                // Build Fake fakeEquipmentDto
                var fakeEquipmentDto = new List<EquipmentDto>();

                // Fake the RosettianClient.SearchEquipment call
                ShimRosettianClient.AllInstances.SearchEquipmentSearchFieldsDtoUserDto =
                    (myRosettianClient, mySubscriberID, myUserObject) => fakeEquipmentDto;

                // Fake the EquipmentExtension.ToONTList call
                // Returning new List<ONT> as this is valid for this test as the subscriber doesn't have any equipment
                SIMPL.Areas.Common.Extensions.Fakes.ShimEquipmentExtension.ToONTListIEnumerableOfEquipmentDto =
                    (myEquipmentList) => new List<ONT>();

                // No Video Devices
                var fakeVideoDeviceList = new List<SerializableVideoDevice>();

                // Fake the EquipmentExtension.ToVideoDeviceList call
                ShimEquipmentExtension.ToVideoDeviceListIEnumerableOfEquipmentDto =
                    (myVideoDeviceList) => fakeVideoDeviceList;

                var currentSubscriber = new ShimCurrentSubscriber
                {
                    SubIdGet = () => "SubId",
                    ProvisionedServicesListGet = () => new List<ServiceDto>()
                };
                ShimCurrentSubscriber.GetInstance = () => currentSubscriber;

                // Fake the CurrentSubscriber.SetInstance call
                ShimCurrentSubscriber.SetInstanceCompositeSubscriberSubscriberModel = (myCompositeSubscriber, mySubscriberModel) => { };

                // Fake the CurrentSubscriber.DataProductType call
                ShimCurrentSubscriber.AllInstances.DataProductTypeGet = (myResult) => SubscriberEnums.DataProductType.Ftth;

                // Fake the CurrentSubscriber.VideoProductType call
                ShimCurrentSubscriber.AllInstances.VideoProductTypeGet = (myResult) => SubscriberEnums.VideoProductType.FiberRf;

                // Fake the CurrentSubscriber.DataProductType call
                ShimCurrentSubscriber.AllInstances.VoiceProductTypeGet = (myResult) => SubscriberEnums.VoiceProductType.FiberPots;

                // Fake the CurrentSubscriber.DataProductType call
                ShimCurrentSubscriber.AllInstances.StateGet = (myResult) => "CT";

                //Fake DB call to get Headends
                var headends = new List<HeadEnd>()
                {
                    new HeadEnd()
                    {
                        EntityKey = new EntityKey(),
                        headend_code = "1",
                        headend_loc = "1",
                        headend_name = "1",
                        headend_nbr = 1,
                        location_id = "1",
                        location_nbr = 1
                    }
                };

                ShimDBCache.HeadEndCodesGet = delegate { return headends; };

                //Fake Line Results DB Call.
                var testResultsDbSet = new ShimDbSet<test_results>();

                testResultsDbSet.Bind(new List<test_results>().AsQueryable());

                ShimLineTestEntities.AllInstances.test_resultsGet = delegate { return testResultsDbSet; };

                ShimCurrentUser.RetrieveUserRolesString = (myUniqueId) => new List<int>() { 1 };

                // 1st Act
                var result = SubscriberControllerForTests.Index(subscriberID, deviceID) as ViewResult;

                // 1st set of Asserts
                Assert.IsNotNull(result, "SubscriberController Index method returned null");
                Assert.IsNotNull(result.ViewName, "result.ViewName method returned null");
                Assert.IsTrue(result.ViewName.Equals("Index2"));
                Assert.IsTrue(result.Model is SubscriberModel, "Not SubscriberModel");

                // 2nd Act
                var testSubscriberModel = result.Model as SubscriberModel;

                // 2nd set of Asserts
                var successCode = "200";
                Assert.AreEqual(successCode, testSubscriberModel.ActionResponse.Code, "Test threw an exception {0}{0}{1}", Environment.NewLine, testSubscriberModel.ActionResponse.Message);

                var jss = new JavaScriptSerializer();
                var expectedModel = fakeCompositeSubscriber.MapToSubscriberModel();
                expectedModel.SubEquipmentModel.ONTOnlyList = new List<ONT>();
                expectedModel.SubEquipmentModel.RGOnlyList = new List<ONT>();
                expectedModel.SubEquipmentModel.LoadedSubID = subscriberID;
                expectedModel.SubEquipmentModel.LoadedLocID = expectedModel.SubLocationModel.LocationID;
                expectedModel.SubEquipmentModel.WanIpAddress = string.Empty;
                expectedModel.SubEquipmentModel.MaxStb = string.Empty;
                Assert.AreEqual(jss.Serialize(expectedModel.ActionResponse), jss.Serialize(testSubscriberModel.ActionResponse));

                Assert.AreEqual(jss.Serialize(expectedModel.SubDetailsModel), jss.Serialize(testSubscriberModel.SubDetailsModel));
                Assert.AreEqual(jss.Serialize(expectedModel.SubLocationModel),jss.Serialize(testSubscriberModel.SubLocationModel));

                // Since deviceID is null, check to verify that LoadedDeviceID is string.Empty
                Assert.AreEqual(string.Empty, expectedModel.SubLocationModel.LoadedDeviceID, "LoadedDeviceID should be string.Empty is deviceID is null");
                Assert.AreEqual(jss.Serialize(expectedModel.SubServicesModel),jss.Serialize(testSubscriberModel.SubServicesModel));
                Assert.AreEqual(jss.Serialize(expectedModel.SubEquipmentModel.ONTList), jss.Serialize(testSubscriberModel.SubEquipmentModel.ONTList), "SubscriberEquipmentModel ONTList");
                Assert.AreEqual(jss.Serialize(expectedModel.SubEquipmentModel.ONTOnlyList), jss.Serialize(testSubscriberModel.SubEquipmentModel.ONTOnlyList), "SubscriberEquipmentModel ONTOnlyList");
                Assert.AreEqual(jss.Serialize(expectedModel.SubEquipmentModel.RGOnlyList), jss.Serialize(testSubscriberModel.SubEquipmentModel.RGOnlyList), "SubscriberEquipmentModel RGOnlyList");
                Assert.AreEqual(jss.Serialize(expectedModel.SubEquipmentModel.VideoDeviceList), jss.Serialize(testSubscriberModel.SubEquipmentModel.VideoDeviceList), "SubscriberEquipmentModel VideoDeviceList");
                Assert.AreEqual(jss.Serialize(expectedModel.SubEquipmentModel), jss.Serialize(testSubscriberModel.SubEquipmentModel));
            }
        }