public void User_can_load_a_subscriber_that_is_provisioned_but_not_billed() { using (ShimsContext.Create()) { // Setup ShimRosettianClient.AllInstances.LoadLocationStringUserDto = delegate { return new LocationDto(); }; ShimRosettianClient.AllInstances.GetServicesUserDto = delegate { return new ServiceCollectionDto();}; const string subscriberID = "999999999999"; const string subscriberContactPhone = "9999999999"; string firstName = "Test"; string lastName = "Account"; string deviceID = null; SIMPLTestContext myContext = new SIMPLTestContext(); // Given a user var fakeUserDto = myContext.GetFakeUserDtoObject(); ShimCurrentUser.AsUserDto = () => fakeUserDto; // And a known subscriber var fakeAccountDto = myContext.GetFakeAccountDtoObject(); var fakeCustomFieldDto = myContext.GetFakeCustomFieldDto(); var fakeSubscriberDto = myContext.GetFakeSubscriberDto(subscriberID, firstName, lastName, subscriberContactPhone, fakeCustomFieldDto, fakeAccountDto); ShimRosettianClient.AllInstances.SearchEquipmentSearchFieldsDtoUserDto = (myRosettianClient, mySubscriberID, myUserObject) => new List<EquipmentDto>(); ShimCurrentSubscriber.SetInstanceCompositeSubscriberSubscriberModel = (myCompositeSubscriber, mySubscriberModel) => { }; ShimCurrentSubscriber.GetInstance = () => new ShimCurrentSubscriber { DataProductTypeGet = () => SubscriberEnums.DataProductType.Unknown, VideoProductTypeGet = () => SubscriberEnums.VideoProductType.Unknown, VoiceProductTypeGet = () => SubscriberEnums.VoiceProductType.Unknown, ProvisionedServicesListGet = () => new List<ServiceDto>() }; //And the subscriber is not billed ShimEnterpriseClient.AllInstances.GetBillingServiceAccountsStringHeaderArgs = delegate { return null; }; // And the subscriber is provisioned ShimRosettianClient.AllInstances.LoadSubscriberStringUserDto = (myRosettianClient, mySubId, myUser) => fakeSubscriberDto; ShimRosettianClient.AllInstances.LoadSubscriberPhonesStringUserDto = delegate { return new List<PhoneDto>();}; //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; }; // When loading that subscriber var result = SubscriberControllerForTests.Index(subscriberID, deviceID) as ViewResult; //Then the user receives a successful response Assert.IsNotNull(result, "SubscriberController Index method returned null"); Assert.IsNotNull(result.Model, "result.Model method returned null"); var testSubscriberModel = result.Model as SubscriberModel; Assert.IsNotNull(testSubscriberModel, "Subscriber Model returned null"); Assert.IsNotNull(testSubscriberModel.ActionResponse, "Subscriber Model returned null"); Assert.AreEqual("200", testSubscriberModel.ActionResponse.Code, "Test threw an exception {0}{0}{1}", Environment.NewLine, testSubscriberModel.ActionResponse.Message); // And the response contains the subscriber name var subscriberFullName = string.Format("{0} {1}", firstName, lastName); Assert.AreEqual(subscriberFullName, testSubscriberModel.SubDetailsModel.DisplayedName, "Provisioned Name was missing or incorrect"); // And the response contains the subscriber id Assert.AreEqual(subscriberID, testSubscriberModel.SubDetailsModel.USI, "USI was missing or incorrect"); // And the response does not contain the WTN Assert.IsTrue(string.IsNullOrEmpty(testSubscriberModel.SubDetailsModel.WTN), "Reponse contained a WTN"); // And the response also contains a message that indicated the subscriber was not found in DPI Assert.IsFalse(testSubscriberModel.SubDetailsModel.FoundInBilling,"The found in DPI flag was set to true when it should have been false."); } }
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_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)); } }