public void Index_HappyPath() { using (ShimsContext.Create()) { //Arrange var myContext = new SIMPLTestContext(); //Build FakeDto var fakeUserDto = myContext.GetFakeUserDtoObject(); //Fake call to CurrentUser.AsUserDto() ShimCurrentUser.AsUserDto = () => fakeUserDto; // Fake the HttpContext var context = new ShimHttpContext(); ShimHttpContext.CurrentGet = () => context; // SIMPL.Session.Fakes.ShimCurrentSubscriber.SessionInstanceGet = () => new ShimCurrentSubscriber(); // Fake the session state for HttpContext var session = new ShimHttpSessionState { ItemGetString = s => { if (s == "") return null; return null; } }; // When the Fake HttpContext is called, provide the fake session state ShimHttpContext.AllInstances.SessionGet = o => session; //Expected result const string expectedIpAddressLabel = "WAN_IP_ADDR"; const string expectedIpAddressValue = "10.143.22.1"; const string expectedBaseModelValue = "A5550"; const string expectedSerialNumber = "PACE99999991"; const string expectedUnitAddress = "0D-U9-M6-D2-D7"; const string expectedLocationId = "locId"; const string expectedRoomLocationLabel = "ROOM_LOCATION"; const string expectedRoomLocationValue = "TEST ROOM"; const string expectedMacAddressLable = "ENET_MAC_ADDR"; const string expectedMacAddressValue = "A0B1C2D3E4F5"; var customFieldsDto = new List<CustomFieldDto>(); var expectedIpAddressCustomField = new CustomFieldDto { Label = expectedIpAddressLabel, Value = expectedIpAddressValue, }; customFieldsDto.Add(expectedIpAddressCustomField); var expectedRoomLocationCustomField = new CustomFieldDto { Label = expectedRoomLocationLabel, Value = expectedRoomLocationValue }; customFieldsDto.Add(expectedRoomLocationCustomField); var expectedMacAddressCustomField = new CustomFieldDto { Label = expectedMacAddressLable, Value = expectedMacAddressValue }; customFieldsDto.Add(expectedMacAddressCustomField); var customFieldsCollection = new CustomFieldCollectionDto { expectedIpAddressCustomField, expectedRoomLocationCustomField, expectedMacAddressCustomField }; var RgType = new EquipmentTypeDto { ONTModel = new ONTModelDto { BaseModel = expectedBaseModelValue }, Category = EquipmentCategoryDto.RGDataPort }; var IPVideoType = new EquipmentTypeDto { ONTModel = new ONTModelDto { BaseModel = expectedBaseModelValue }, Category = EquipmentCategoryDto.DVR, IptvCapable = true }; var equipmentDataDto = new EquipmentDto { SerialNumber = expectedSerialNumber + "D01", CustomFields = customFieldsDto, UnitAddress = expectedUnitAddress, LocationId = expectedLocationId, Type = RgType, Status = "ACTIVE" }; var equipmentPhoneDto = new EquipmentDto { SerialNumber = expectedSerialNumber + "P01", CustomFields = customFieldsDto, UnitAddress = expectedUnitAddress, LocationId = expectedLocationId, Type = RgType, Status = "ACTIVE" }; var ipVideoDevice = new EquipmentDto { SerialNumber = expectedSerialNumber + "P01", CustomFields = customFieldsDto, UnitAddress = expectedUnitAddress, LocationId = expectedLocationId, Type = IPVideoType, Status = "ACTIVE" }; var searchEquipmentsResult = new List<EquipmentDto>(); searchEquipmentsResult.Add(equipmentDataDto); searchEquipmentsResult.Add(equipmentPhoneDto); searchEquipmentsResult.Add(ipVideoDevice); var loadSubscriberPhonesResult = new List<PhoneDto>(); // shim CurrentSubscriber WanIpAddress ShimCurrentSubscriber.GetInstance = () => new ShimCurrentSubscriber { WanIpAddressGet = () => expectedIpAddressValue, ProvisionedPhonesListGet = () => loadSubscriberPhonesResult }; ShimRosettianClient.AllInstances.SearchEquipmentSearchFieldsDtoUserDto = (myTestClient, mySearchFields, myUserDto) => searchEquipmentsResult; equipmentDataDto.CustomFields = customFieldsDto; ShimRosettianClient.AllInstances.LoadEquipmentStringBooleanUserDto = (myTestClient, myEquipmentId, returnExtraData, myUserDto) => equipmentDataDto; ShimRosettianClient.AllInstances.GetCustomFieldsUserDto = (myTestClient, myUserDto) => customFieldsCollection; ShimVirtualPathUtility.ToAbsoluteString = (myTestString) => @"http://testapp/images/DVR.png"; ShimDBCache.LocationsGet = delegate { return new List<Location>(); }; var residentialController = DependencyResolver.Current.GetService<ResidentialGatewayController>(); var result = residentialController.Index("subID", "locID", "devID") as PartialViewResult ?? new PartialViewResult(); Assert.IsNotNull(result, "Partial view result returned is null."); Assert.IsTrue(result.ViewName.Equals("Index"), "View names do not match."); Assert.AreEqual(expectedIpAddressValue, ((ResidentialGatewayModel)(result.Model)).IPAddress, "Expected IP does not match with actual IP."); Assert.AreEqual(expectedUnitAddress, ((ResidentialGatewayModel)(result.Model)).UnitAddress, "Expected UnitAddress does not match with actual Unit Address."); Assert.AreEqual(expectedMacAddressValue, ((ResidentialGatewayModel)(result.Model)).MacAddress, "Expected MacAddress does not match with actual Mac Address."); Assert.AreEqual(expectedBaseModelValue, ((ResidentialGatewayModel)(result.Model)).Model, "Expected Model number does not match with actual Model number."); Assert.AreEqual(expectedSerialNumber, ((ResidentialGatewayModel)(result.Model)).ID, "Expected serial number does not match with actual serial number."); Assert.IsTrue(((ResidentialGatewayModel)(result.Model)).VideoDevices.Any(), "No video devices found."); Assert.IsTrue(((ResidentialGatewayModel)(result.Model)).VideoDevices.First().Type.Equals("DVR"), "IP Video device type mismatch."); Assert.IsTrue(((ResidentialGatewayModel)(result.Model)).VideoDevices.First().RoomLocation.Any(), "No Room locations found."); } }
public void ActivateResidentialGateway_hasNoMainRg_hasListOtherRgs_hasIpVideoDevice_ValidateSuccessScenario() { using (ShimsContext.Create()) { //Arrange var myContext = new SIMPLTestContext(); //Build FakeDto var fakeUserDto = myContext.GetFakeUserDtoObject(); //Fake call to CurrentUser.AsUserDto() ShimCurrentUser.AsUserDto = () => fakeUserDto; // Fake the HttpContext var context = new ShimHttpContext(); ShimHttpContext.CurrentGet = () => context; // Fake the session state for HttpContext var session = new ShimHttpSessionState { ItemGetString = s => { if (s == "") return null; return null; } }; // When the Fake HttpContext is called, provide the fake session state ShimHttpContext.AllInstances.SessionGet = o => session; //Expected result const string expectedIpAddressLabel = "WAN_IP_ADDR"; const string expectedIpAddressValue = "10.143.22.1"; const string expectedBaseModelValue = "A5550"; const string expectedSerialNumber = "PACE99999991"; const string expectedUnitAddress = "001E46"; const string expectedLocationId = "123456789"; const string expectedRoomLocationLabel = "ROOM_LOCATION"; const string expectedRoomLocationValue = "TEST ROOM"; const string expectedMacAddressLable = "ENET_MAC_ADDR"; const string expectedMacAddressValue = "A0B1C2D3E4F5"; const string expectedSelectedRoomLabel = "SELECTED_ROOM"; const string expectedSelectedRoomValue = "MASTER BED ROOM"; var customFieldsDto = new List<CustomFieldDto>(); // RG custom fields var expectedIpAddressCustomField = new CustomFieldDto { Label = expectedIpAddressLabel, Value = expectedIpAddressValue, }; customFieldsDto.Add(expectedIpAddressCustomField); var expectedMacAddressCustomField = new CustomFieldDto { Label = expectedMacAddressLable, Value = expectedMacAddressValue }; customFieldsDto.Add(expectedMacAddressCustomField); // ip video device custom fields var expectedRoomLocationCustomField = new CustomFieldDto { Label = expectedRoomLocationLabel, Value = expectedRoomLocationValue }; customFieldsDto.Add(expectedRoomLocationCustomField); var expectedSelectedRoomCustomField = new CustomFieldDto { Label = expectedSelectedRoomLabel, Value = expectedSelectedRoomValue }; customFieldsDto.Add(expectedSelectedRoomCustomField); var customFieldsCollection = new CustomFieldCollectionDto { expectedIpAddressCustomField, expectedRoomLocationCustomField, expectedMacAddressCustomField }; var rgType = new EquipmentTypeDto { ONTModel = new ONTModelDto { BaseModel = expectedBaseModelValue }, Category = EquipmentCategoryDto.RGDataPort }; var ipVideoType = new EquipmentTypeDto { Model = "ISP7500", Category = EquipmentCategoryDto.DVR, IptvCapable = true }; // main active RG var equipmentDataDto = new EquipmentDto { SerialNumber = expectedSerialNumber + "D01", CustomFields = customFieldsDto, UnitAddress = expectedUnitAddress, LocationId = expectedLocationId, Type = rgType, Status = "ACTIVE" }; var mainRg = new List<EquipmentDto> { equipmentDataDto, new EquipmentDto { SerialNumber = expectedSerialNumber + "P01", CustomFields = customFieldsDto, UnitAddress = expectedUnitAddress, LocationId = expectedLocationId, Type = rgType, Status = "ACTIVE" }, new EquipmentDto { SerialNumber = expectedSerialNumber + "P02", CustomFields = customFieldsDto, UnitAddress = expectedUnitAddress, LocationId = expectedLocationId, Type = rgType, Status = "ACTIVE" } }; // ip video device var ipVideoDevice = new EquipmentDto { SerialNumber = "STBTEST1234", CustomFields = new List<CustomFieldDto> { expectedRoomLocationCustomField }, UnitAddress = "1234567890", LocationId = expectedLocationId, Type = ipVideoType, Status = "ACTIVE" }; // other RGs on the account var otherRgs = new List<EquipmentDto> { new EquipmentDto { SerialNumber = "RGCREATE1234" + "D01", CustomFields = customFieldsDto, UnitAddress = expectedUnitAddress, LocationId = expectedLocationId, Type = rgType, Status = "IGNORE" }, new EquipmentDto { SerialNumber = "RGCREATE2345" + "D01", CustomFields = customFieldsDto, UnitAddress = expectedUnitAddress, LocationId = expectedLocationId, Type = rgType, Status = "IGNORE" }, new EquipmentDto { SerialNumber = "RGCREATE3456" + "D01", CustomFields = customFieldsDto, UnitAddress = expectedUnitAddress, LocationId = expectedLocationId, Type = rgType, Status = "IGNORE" }, }; // set location ShimCurrentSubscriber.AllInstances.LocationIdGet = o => expectedLocationId; // set WanIpAddress ShimCurrentSubscriber.AllInstances.SubIdGet = o => "1234567"; ShimCurrentSubscriber.AllInstances.WanIpAddressGet = o => "12:12:12:12"; ShimRosettianClient.AllInstances.LoadSubscriberStringUserDto = (client, subId, userDto) => new SubscriberDto(); ShimCurrentSubscriber.UpdateWanIpAddressString = (myWanIpAddress) => { }; // set activate residential gateway to true ShimRosettianClient.AllInstances.ActivateResidentialGatewayStringStringUserDto = (myTestclient, mylocationId, myDeviceId, userDto) => true; // expected search results after Activate RG var searchEquipmentsResult = new List<EquipmentDto>(); searchEquipmentsResult.AddRange(mainRg); searchEquipmentsResult.AddRange(otherRgs); searchEquipmentsResult.Add(ipVideoDevice); // set search results to expected ShimRosettianClient.AllInstances.SearchEquipmentSearchFieldsDtoUserDto = (myTestClient, mySearchFields, myUserDto) => searchEquipmentsResult; // expected custom fields equipmentDataDto.CustomFields = customFieldsDto; // set load eqiupment for main RG ShimRosettianClient.AllInstances.LoadEquipmentStringBooleanUserDto = (myTestClient, myEquipmentId, returnExtraData, myUserDto) => equipmentDataDto; // set custom fields ShimRosettianClient.AllInstances.GetCustomFieldsUserDto = (myTestClient, myUserDto) => customFieldsCollection; // set ip video device path ShimVirtualPathUtility.ToAbsoluteString = (myTestString) => @"http://testapp/images/DVR.png"; // get service for ResidentialGatewayController var residentialController = DependencyResolver.Current.GetService<ResidentialGatewayController>(); // call ActivateResidentialGateway of ResidentialGatewayController var result = residentialController.ActivateResidentialGateway(expectedSerialNumber, expectedLocationId) as JsonResult; // validate json result Assert.IsNotNull(result, "Returned Json result is null"); dynamic resultData = result.Data; var status = resultData.status as string; var errorMessage = string.Empty; if (status == "error") { errorMessage = resultData.errorMessage; } Assert.AreEqual("valid", status, "status is not valid - {0}", errorMessage); var renderedPartial = resultData.returnedPartial as string; Assert.IsNotNull(renderedPartial, "Prerendered partial is null."); } }
private static List<EquipmentDto> RgTestData_OtherRgList(CustomFieldCollectionDto customFieldsDto, string expectedLocationId) { var rgType = new EquipmentTypeDto { ONTModel = new ONTModelDto { BaseModel = "Pace RG" }, Category = EquipmentCategoryDto.RGDataPort }; // other RGs on the account var otherRgs = new List<EquipmentDto> { new EquipmentDto { SerialNumber = "RGCREATE1234" + "D01", CustomFields = customFieldsDto.ToList(), UnitAddress = "1234567", LocationId = expectedLocationId, Type = rgType, Status = "IGNORE" }, new EquipmentDto { SerialNumber = "RGCREATE2345" + "D01", CustomFields = customFieldsDto.ToList(), UnitAddress = "1234567", LocationId = expectedLocationId, Type = rgType, Status = "IGNORE" }, new EquipmentDto { SerialNumber = "RGCREATE3456" + "D01", CustomFields = customFieldsDto.ToList(), UnitAddress = "1234567", LocationId = expectedLocationId, Type = rgType, Status = "IGNORE" }, }; return otherRgs; }
private static List<EquipmentDto> RgTestData_MainRg(CustomFieldCollectionDto customFieldsDto, string expectedLocationId) { const string expectedSerialNumber = "RGARRIS1234"; const string expectedUnitAddress = "1234567"; var rgType = new EquipmentTypeDto { ONTModel = new ONTModelDto { BaseModel = "ARRIS RG" }, Category = EquipmentCategoryDto.RGDataPort }; var mainRg = new List<EquipmentDto> { new EquipmentDto { SerialNumber = expectedSerialNumber + "D01", CustomFields = customFieldsDto.ToList(), UnitAddress = "234567", LocationId = expectedLocationId, Type = rgType, Status = "ACTIVE" }, new EquipmentDto { SerialNumber = expectedSerialNumber + "P01", CustomFields = customFieldsDto.ToList(), UnitAddress = expectedUnitAddress, LocationId = expectedLocationId, Type = rgType, Status = "ACTIVE" }, new EquipmentDto { SerialNumber = expectedSerialNumber + "P02", CustomFields = customFieldsDto.ToList(), UnitAddress = "234567", LocationId = expectedLocationId, Type = rgType, Status = "ACTIVE" } }; return mainRg; }
private static EquipmentDto RgTestData_IpVideoDevice2(CustomFieldCollectionDto customFieldsDto, string expectedLocationId) { var ipVideoType = new EquipmentTypeDto { Model = "ISP7005", Category = EquipmentCategoryDto.DVR, IptvCapable = true }; // ip video device var ipVideoDevice = new EquipmentDto { SerialNumber = "STBTEST3457", CustomFields = customFieldsDto.Where(x => x.Label == "ROOM_LOCATION" || x.Label == "SELECTED_ROOM").ToList(), UnitAddress = null, LocationId = expectedLocationId, Type = ipVideoType, Status = "ACTIVE" }; return ipVideoDevice; }
private static CustomFieldCollectionDto RgTestData_CustomFieldsCollection() { const string expectedIpAddressLabel = "WAN_IP_ADDR"; const string expectedIpAddressValue = "10.143.22.1"; const string expectedRoomLocationLabel = "ROOM_LOCATION"; const string expectedRoomLocationValue = "TEST ROOM"; const string expectedMacAddressLable = "ENET_MAC_ADDR"; const string expectedMacAddressValue = "A0B1C2D3E4F5"; const string expectedSelectedRoomLabel = "SELECTED_ROOM"; const string expectedSelectedRoomValue = "MASTER BED ROOM"; var customFieldsDto = new CustomFieldCollectionDto(); // RG custom fields var expectedIpAddressCustomField = new CustomFieldDto { Label = expectedIpAddressLabel, Value = expectedIpAddressValue, }; customFieldsDto.Add(expectedIpAddressCustomField); var expectedMacAddressCustomField = new CustomFieldDto { Label = expectedMacAddressLable, Value = expectedMacAddressValue }; customFieldsDto.Add(expectedMacAddressCustomField); // ip video device custom fields var expectedRoomLocationCustomField = new CustomFieldDto { Label = expectedRoomLocationLabel, Value = expectedRoomLocationValue }; customFieldsDto.Add(expectedRoomLocationCustomField); var expectedSelectedRoomCustomField = new CustomFieldDto { Label = expectedSelectedRoomLabel, Value = expectedSelectedRoomValue }; customFieldsDto.Add(expectedSelectedRoomCustomField); return customFieldsDto; }