public IList <CustomFieldDto> GetEditCustomFields(Guid assetId, string company) { IList <CustomFieldDto> cfList = new List <CustomFieldDto>(); var @entity = _assetManager.GetAssetCustomFields(assetId, company).ToList(); if (@entity == null) { throw new UserFriendlyException("No se pudo encontrar el ArtÃculo, fue borrado o no existe."); } int index = 0; foreach (var item in @entity) { CustomFieldDto cfItem = new CustomFieldDto(); cfItem.Id = item.Id; cfItem.Name = item.Name; cfItem.AssetId = item.AssetId; cfItem.SetValue(item.CustomFieldType, item.Value); cfItem.AssetId = item.AssetId; //cfItem.Asset = item.Asset; cfItem.Index = index; cfItem.Update = 1; cfItem.Saved = 1; cfItem.Delete = 0; cfItem.ErrorCode = 0; cfItem.ErrorDescription = ""; cfItem.CompanyName = company; cfList.Add(cfItem); index++; } return(cfList); }
// POST api/<controller> public async Task <IHttpActionResult> Post(CustomFieldDto customFieldDto) { var errorMessage = await _customFieldValidator.ValidateCustomField(customFieldDto); if (!string.IsNullOrEmpty(errorMessage)) { return(BadRequest(errorMessage)); } return(Ok(await _customFieldsService.Add(customFieldDto))); }
public async Task <CustomFieldDto> Add(CustomFieldDto customFieldDto) { var customField = Mapper.Map <CustomField>(customFieldDto); customField.Id = ObjectId.GenerateNewId().ToString(); ; var result = await _repository.AddAsync(customField).ConfigureAwait(false); return(result == null ? null : Mapper.Map <CustomFieldDto>(result)); }
public async Task <CustomFieldDto> Update(CustomFieldDto customFieldDto) { var customField = await _repository.GetByIdAsync(customFieldDto.Id).ConfigureAwait(false); if (customField == null) { return(null); } customField = Mapper.Map(customFieldDto.FixMeUp(), customField); var result = await _repository.UpdateAsync(customField).ConfigureAwait(false); return(result == null ? null : Mapper.Map <CustomFieldDto>(result)); }
private static IEnumerable <CustomFieldDto> CreateFieldDto(CustomField field, short fieldId, short eventId, int requestId, short?parentId) { var list = new List <CustomFieldDto> { CustomFieldDto.Create(field, fieldId, eventId, requestId, parentId) }; foreach (var children in field.Children) { list.AddRange(CreateFieldDto(children, (short)(fieldId + list.Count), eventId, requestId, fieldId)); } return(list); }
// PUT api/<controller>/5 public async Task <IHttpActionResult> Put(string id, CustomFieldDto customFieldDto) { if (customFieldDto.Id != id || string.IsNullOrEmpty(id)) { return(BadRequest("The customField ID is invalid!")); } var errorMessage = await _customFieldValidator.ValidateCustomField(customFieldDto); if (!string.IsNullOrEmpty(errorMessage)) { return(BadRequest(errorMessage)); } return(Ok(await _customFieldsService.Update(customFieldDto))); }
public ActionResult AddAndRenderListCustomFields(IList <string> jsonCustomFieldsList, Guid assetId, string name, object value, int type) { try { IEnumerable <CustomFieldDto> customList = new JavaScriptSerializer().Deserialize <IList <CustomFieldDto> >(jsonCustomFieldsList[0]); if (string.IsNullOrEmpty(name)) { return(Json(new { Error = -1, Message = "Por Favor indique el nombre del campo." })); } object valueParse = ((IEnumerable <string>)value).FirstOrDefault(); if (string.IsNullOrEmpty(Convert.ToString(valueParse))) { return(Json(new { Error = -1, Message = "Por Favor ingrese un valor al campo." })); } CustomFieldDto custom = new CustomFieldDto(); custom.Name = name; custom.SetValue((CustomFieldType)type, valueParse); custom.Saved = 0; custom.Update = 1; custom.Delete = 0; custom.ErrorDescription = ""; custom.ErrorCode = 0; custom.Id = Guid.Empty; IList <CustomFieldDto> newList = new List <CustomFieldDto>(); int index = 0; foreach (var item in customList) { item.Index = index; newList.Add(item); index++; } custom.Index = index; newList.Add(custom); return(PartialView("_customFieldsPartial", newList)); } catch (Exception e) { return(Json(new { Error = -1, Message = "Error al Agregar/Modificar el campo customizable" })); } }
public async Task <string> ValidateCustomField(CustomFieldDto customFieldDto) { if (string.IsNullOrEmpty(customFieldDto.Id)) { // Check customfields var result = await _customFieldsService.CustomFieldExists(customFieldDto.Name); return(result ? $"CustomField with Name #{customFieldDto.Name} already exists!" : string.Empty); } else { // Check customfields var result = await _customFieldsService.GetById(customFieldDto.Id); if (result.Name == customFieldDto.Name) { return(string.Empty); } var exists = await _customFieldsService.CustomFieldExists(customFieldDto.Name); return(exists ? $"CustomField with Name #{customFieldDto.Name} already exists!" : string.Empty); } }
/// <inheritdoc/> public DopplerSubscriberDto ToDopplerSubscriberDto(IDictionary <string, IList <object> > rawSubscriber, ItemsDto allowedFields) { var email = GetEmailValue(rawSubscriber); if (rawSubscriber.ContainsKey("email")) { email = rawSubscriber["email"][0].ToString(); rawSubscriber.Remove("email"); } else { _log.LogWarning("The current user has not included an EMAIL field"); } var fieldsUpperNameAllowed = allowedFields.Items.Select(i => i.Name.ToUpper()).ToList(); var fieldsNameAllowed = allowedFields.Items.Select(i => i.Name).ToList(); var fields = new List <CustomFieldDto>(); var fieldsNotEnabled = new List <string>(); foreach (KeyValuePair <string, IList <object> > entry in rawSubscriber) { var index = fieldsUpperNameAllowed.IndexOf(entry.Key.ToUpper()); if (index >= 0) { var type = allowedFields.Items[index].Type; var value = entry.Value[0].ToString(); if (type == FieldTypes.Boolean.GetDescription()) { value = GetBooleanValue(value); } else if (GENDER_FIELD_NAMES.Contains(fieldsNameAllowed[index])) { value = GetGenderValue(value); } else if (COUNTRY_FIELD_NAMES.Contains(fieldsNameAllowed[index])) { value = GetCountryValue(value); } var newCustomeField = new CustomFieldDto { Name = fieldsNameAllowed[index], Value = value }; fields.Add(newCustomeField); } else { fieldsNotEnabled.Add(entry.Key); } } if (fieldsNotEnabled.Count > 0) { LogFieldsRejected(fieldsNotEnabled); } return(new DopplerSubscriberDto { Email = email, Fields = fields }); }
private TableRow CreateRowForCustomField(TypeField typeField, string group, List <CrmCustomField> valueFields, CustomFieldDto Field) { var tr = new TableRow() { ID = "TableRow" + group + Field.Id }; var tcName = new TableCell() { ID = "TableCellName" + group + Field.Id }; var labelName = new Label() { ID = "LabelFieldName" + group + Field.Id, Text = Field.Name // + "_" + Field.TypeId }; tcName.Controls.Add(labelName); tr.Cells.Add(tcName); var tcValue = new TableCell() { ID = "TableCellValue" + group + Field.Id }; var hfIdField = new HiddenField() { ID = "HiddenFieldIdField" + group + Field.Id, Value = Field.Id.ToString() }; tcValue.Controls.Add(hfIdField); var hfGroup = new HiddenField() { ID = "HiddenFieldGroupField" + group + Field.Id, Value = group }; tcValue.Controls.Add(hfGroup); var hfTypeField = new HiddenField() { ID = "HiddenFieldTypeField" + group + Field.Id, Value = Field.TypeId.ToString() }; tcValue.Controls.Add(hfTypeField); switch (Field.TypeId) { case 5: { var selectValue = new CheckBoxList() { ID = "CheckBoxListFieldValue" + group + Field.Id }; var enums = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(Field.Enums.ToString()); foreach (var option in enums) { selectValue.Items.Add(new ListItem() { Value = option.Key.ToString(), Text = option.Value }); } ; var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id); if (selectedValue != null) { foreach (var _val in selectedValue.Values) { var option = selectValue.Items.FindByValue(_val.Enum); if (option != null) { option.Selected = true; } } } ; tcValue.Controls.Add(selectValue); } break; case 4: { var selectValue = new DropDownList() { ID = "DropDownListFieldValue" + group + Field.Id, CssClass = "form-control" }; var enums = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(Field.Enums.ToString()); selectValue.Items.Add(new ListItem() { Value = "", Text = "-----" }); foreach (var option in enums) { selectValue.Items.Add(new ListItem() { Value = option.Key.ToString(), Text = option.Value }); } ; var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id); if (selectedValue != null && selectValue.Items.FindByValue(selectedValue.Values.FirstOrDefault().Enum) != null) { selectValue.SelectedValue = selectedValue.Values.FirstOrDefault().Enum; } ; tcValue.Controls.Add(selectValue); } break; case 2: { var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id); var val = selectedValue != null && selectedValue.Values != null && selectedValue.Values.FirstOrDefault() != null?selectedValue.Values.FirstOrDefault().Value : ""; var numValue = new TextBox() { ID = "TextBoxFieldValue" + group + Field.Id, Text = val, TextMode = TextBoxMode.Number, CssClass = "form-control" }; tcValue.Controls.Add(numValue); } break; case 1: { var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id); var val = selectedValue != null && selectedValue.Values != null && selectedValue.Values.FirstOrDefault() != null?selectedValue.Values.FirstOrDefault().Value : ""; var numValue = new TextBox() { ID = "TextBoxFieldValue" + group + Field.Id, Text = val, TextMode = TextBoxMode.SingleLine, CssClass = "form-control" }; tcValue.Controls.Add(numValue); } break; case 3: { var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id); var val = selectedValue != null && selectedValue.Values != null && selectedValue.Values.FirstOrDefault() != null?selectedValue.Values.FirstOrDefault().Value : ""; var numValue = new CheckBox() { ID = "CheckBoxFieldValue" + group + Field.Id, Checked = val == "True" }; tcValue.Controls.Add(numValue); } break; case 8: { if (Session.Contents["MultiFields" + group + Field.Id.ToString()] == null) { Session.Contents["MultiFields" + group + Field.Id.ToString()] = new Dictionary <String, Panel>(); } var sessionFields = (Session.Contents["MultiFields" + group + Field.Id.ToString()] as Dictionary <String, Panel>); var it = 0; var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id); var vals = selectedValue != null && selectedValue.Values != null ? selectedValue.Values : new List <CrmCustomFieldValue>(); foreach (var val in vals) { var lc = new Panel() { ID = "Panel" + group + Field.Id + it, CssClass = "input-group" }; var ddl = new DropDownList() { ID = "DropDownListValue" + group + Field.Id + it, Width = 100, CssClass = "input-group-prepend" }; var enums = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(Field.Enums.ToString()); foreach (var option in enums) { ddl.Items.Add(new ListItem() { Value = option.Key.ToString(), Text = option.Value }); } ; ddl.SelectedValue = val.Enum; lc.Controls.Add(ddl); var numValue = new TextBox() { ID = "TextBoxFieldValue" + group + Field.Id + it, Text = val.Value, CssClass = "form-control" }; lc.Controls.Add(numValue); var addValue = new Button() { ID = "ButtonFieldValue" + group + Field.Id + it, Text = "+", CssClass = "input-group-append input-group-text" }; addValue.Click += addValue_Click; addValue.CommandArgument = JsonConvert.SerializeObject(Field); lc.Controls.Add(addValue); if (sessionFields.ContainsKey(lc.ID) != null) { sessionFields.Remove(lc.ID); } tcValue.Controls.Add(lc); it++; } foreach (var panel in sessionFields) { tcValue.Controls.Add(panel.Value); it++; } if (it == 0) { var lc = new Panel() { ID = "Panel" + group + Field.Id + it, CssClass = "input-group" }; var ddl = new DropDownList() { ID = "DropDownListValue" + group + Field.Id + it, Width = 100, CssClass = "input-group-prepend" }; var enums = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(Field.Enums.ToString()); foreach (var option in enums) { ddl.Items.Add(new ListItem() { Value = option.Key.ToString(), Text = option.Value }); } ; ddl.SelectedIndex = 0; lc.Controls.Add(ddl); var numValue = new TextBox() { ID = "TextBoxFieldValue" + group + Field.Id + it, Text = "", CssClass = "form-control" }; lc.Controls.Add(numValue); var addValue = new Button() { ID = "ButtonFieldValue" + group + Field.Id + it, Text = "+", CssClass = "input-group-append input-group-text" }; addValue.Click += addValue_Click; lc.Controls.Add(addValue); tcValue.Controls.Add(lc); } Session.Contents["MultiFields" + group + Field.Id.ToString()] = sessionFields; } break; case 9: { var selectedValue = valueFields.FirstOrDefault(r => r.Id == Field.Id); var val = selectedValue != null && selectedValue.Values != null && selectedValue.Values.FirstOrDefault() != null?selectedValue.Values.FirstOrDefault().Value : ""; var numValue = new TextBox() { ID = "TextBoxFieldValue" + group + Field.Id, Text = val, TextMode = TextBoxMode.MultiLine, CssClass = "form-control" }; tcValue.Controls.Add(numValue); } break; } tr.Cells.Add(tcValue); return(tr); }
/// <summary> /// GetFakeSubscriberDto - returns SubscriberDto /// </summary> /// <param name="subscriberID"></param> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="subscriberContactPhone"></param> /// <param name="fakeCustomFieldDto"></param> /// <param name="fakeAccountDto"></param> /// <returns></returns> public SubscriberDto GetFakeSubscriberDto(string subscriberID, string firstName, string lastName, string subscriberContactPhone, CustomFieldDto fakeCustomFieldDto, AccountDto fakeAccountDto) { // Build Fake SubscriberDto var fakeSubscriberDto = new SubscriberDto() { ID = subscriberID, Name = string.Format("{0} {1}", firstName, lastName), SubContactPhone = subscriberContactPhone, SubContactEmail = "*****@*****.**", }; fakeSubscriberDto.CustomFields.Add(fakeCustomFieldDto); fakeSubscriberDto.Accounts.Add(fakeAccountDto); return fakeSubscriberDto; }
/// <summary> /// GetFakeCustomFieldDto - returns CustomFieldDto /// </summary> /// <returns></returns> public CustomFieldDto GetFakeCustomFieldDto() { var fakeCustomFieldDto = new CustomFieldDto() {Label = "Sub_WTN", Value = string.Empty}; return fakeCustomFieldDto; }
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 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; }
public void SwapIpVideoDevice_SwapOutVAPForAnotherVAP() { using (ShimsContext.Create()) { //Arrange const string selectedRoomConst = "testroom"; var myContext = new SIMPLTestContext(); var fakeUserDto = myContext.GetFakeUserDtoObject(); ShimCurrentUser.AsUserDto = () => fakeUserDto; ShimCurrentUser.AllInstances.RolesGet = x => { return new List<int>(); }; var context = new ShimHttpContext(); ShimHttpContext.CurrentGet = () => context; ShimResidentialGatewayController.AllInstances.ValidateDeviceEquipmentDto = (controller, dto) => { return new RozResponseDto { Code = "200", Message = String.Empty }; }; var session = new ShimHttpSessionState { ItemGetString = s => { if (s == "") return null; return null; } }; ShimHttpContext.AllInstances.SessionGet = o => session; // VAP device to test EquipmentDto VAPDevice1 = new EquipmentDto(); VAPDevice1.Type.Category = EquipmentCategoryDto.VideoAccessPoint; CustomFieldDto cf = new CustomFieldDto(); cf.Label = "ROOM_LOCATION"; VAPDevice1.CustomFields.Add(cf); // Another VAP device to test EquipmentDto VAPDevice2 = new EquipmentDto(); VAPDevice2.Type.Category = EquipmentCategoryDto.VideoAccessPoint; VAPDevice2.CustomFields.Add(cf); // Shim Equipment Search ShimRosettianClient.AllInstances.SearchEquipmentSearchFieldsDtoUserDto = (client, dto, arg3) => { List<EquipmentDto> lst = new List<EquipmentDto>(); lst.Add(VAPDevice1); lst.Add(VAPDevice2); return lst; }; ShimRosettianClient.AllInstances.ReturnToHeadendListOfStringUserDto = (client, list, arg3) => { return true; }; // current location const string currentLocationId = "LOCIDWITHANYVALUE"; // set location Id ShimCurrentSubscriber.AllInstances.LocationIdGet = o => currentLocationId; // get service for ResidentialGatewayController var residentialController = DependencyResolver.Current.GetService<ResidentialGatewayController>(); // Test for s string selectedRoomValue = "testroom"; ShimRosettianClient.AllInstances.UpdateEquipmentEquipmentDtoUserDto = (client, dto, arg3) => { return true; }; ShimRosettianClient.AllInstances.PerformEquipmentOperationListOfEquipmentOperationDtoUserDto = (client, dtos, arg3) => { return true; }; // Try to replace VAP device with another VAP device string result = residentialController.SwapIpVideoDevices(VAPDevice1, VAPDevice2, selectedRoomValue).ToJSON(); XmlDictionaryReader jsonReader = JsonReaderWriterFactory.CreateJsonReader( Encoding.UTF8.GetBytes(result), new XmlDictionaryReaderQuotas()); XElement root = XElement.Load(jsonReader); int code = Convert.ToInt32(root.XPathSelectElement(@"//code").Value); string status = root.XPathSelectElement(@"//status").Value.ToString(); string selectedRoomReturned = root.XPathSelectElement(@"//sRoom").Value.ToString(); string errorString = root.XPathSelectElement(@"//errorMessage").Value.ToString(); if ((code == 200 || code == 202) && status == "valid") { Assert.IsTrue(true); } else if ((code == 200 || code == 202) && status == "error") { Assert.Inconclusive("Device untestable as validation failed."); } else if (code == 400 && errorString.Contains("Error swapping old video device")) { Assert.Inconclusive("Device untestable because endpoint failed."); } else { Assert.Fail("Swap of two VAP devices failed."); } Assert.AreEqual(selectedRoomConst, selectedRoomReturned, "Selected room changed."); } }