Пример #1
0
        public async Task <Response <EquipmentDto> > GetEquipment(string id)
        {
            var item = await _context.Equipment.SingleOrDefaultAsync(x => x.Id == id);

            var itemType =
                await _context.EquipmentTypes.SingleOrDefaultAsync(x => x.Id == item.TypeId);

            var itemBrand =
                await _context.EquipmentBrands.SingleOrDefaultAsync(x => x.Id == item.BrandId);

            var itemPlace =
                await _context.EquipmentPlaces.SingleOrDefaultAsync(x => x.Id == item.PlaceId);

            if (item == null)
            {
                throw new BusinessLogicException("رکوردی یافت نشد");
            }
            if (itemType == null)
            {
                throw new BusinessLogicException("نوع تجهیزات مشخص  نیست ");
            }
            if (itemBrand == null)
            {
                throw new BusinessLogicException("برند تجهیزات مشخص  نیست");
            }
            if (itemPlace == null)
            {
                throw new BusinessLogicException("مکان تجهیزات مشخص  نیست");
            }

            var resultType = new EquipmentTypeDto
            {
                Id   = itemType.Id,
                Name = itemType.Name
            };

            var resultBrand = new EquipmentBrandDto
            {
                Id   = itemBrand.Id,
                Name = itemBrand.Name
            };
            var resultPlace = new EquipmentPlaceDto
            {
                Id   = itemPlace.Id,
                Name = itemPlace.Name
            };


            return(new Response <EquipmentDto>
            {
                Status = true,
                Message = "success",
                Data = new EquipmentDto
                {
                    Id = item.Id,
                    Name = item.Name,
                    Amval = item.Amval,
                    Brand = resultBrand,
                    Description = item.Description,
                    IsActive = item.IsActive,
                    IsInUse = item.IsInUse,
                    Model = item.Model,
                    Place = resultPlace,
                    Serial = item.Serial,
                    TechnicalCode = item.TechnicalCode,
                    Type = resultType
                }
            });
        }
Пример #2
0
        private static List<EquipmentDto> EquipTestData_Rg(string subId, string locId)
        {
            const string serialNumber = "RGARRIS1234";
            const string unitAddress = "1234567";
            const string baseModel = "ARRIS RG";

            var rgVoiceType = new EquipmentTypeDto
            {
                ONTModel = new ONTModelDto
                {
                    BaseModel = baseModel
                },
                Category = EquipmentCategoryDto.RGVoicePort
            };

            var rgDataType = new EquipmentTypeDto
            {
                ONTModel = new ONTModelDto
                {
                    BaseModel = baseModel
                },
                Category = EquipmentCategoryDto.RGDataPort
            };

            var mainRg = new List<EquipmentDto>
            {
                new EquipmentDto
                {
                    SerialNumber = serialNumber + "D01",
                    UnitAddress = "234567",
                    LocationId = locId,
                    Type = rgDataType,
                    Status = "ACTIVE",
                    AssociatedSubscriberId = subId
                },
                new EquipmentDto
                {
                    SerialNumber = serialNumber + "P01",
                    UnitAddress = unitAddress,
                    LocationId = locId,
                    Type = rgVoiceType,
                    Status = "ACTIVE",
                    AssociatedSubscriberId = subId
                },
                new EquipmentDto
                {
                    SerialNumber = serialNumber + "P02",
                    UnitAddress = unitAddress,
                    LocationId = locId,
                    Type = rgVoiceType,
                    Status = "ACTIVE",
                    AssociatedSubscriberId = subId
                }
            };
            return mainRg;
        }
        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 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.");
            }
        }
        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.");
            }
        }
        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 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;
        }
        public void RemoveResidentialGateway_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;

                var fakeServiceAccount = myContext.GetFakeServiceAccountDto();
                var listFakeServiceAccounts = new List<ServiceAccountDto>
                {
                    fakeServiceAccount
                };

                //Expected result
                const string expectedBaseModelValue = "A5550";
                const string expectedSerialNumber = "PACE99999991";
                const string expectedLocationId = "locId";

                ShimCurrentSubscriber.AllInstances.PhoneServicesListGet = (o) => listFakeServiceAccounts;
                ShimCurrentSubscriber.AllInstances.ServiceAccountListGet = (myTest) => listFakeServiceAccounts;
                ShimCurrentSubscriber.AllInstances.CurrentServiceAccountGet = (myTest) => fakeServiceAccount;
                ShimCurrentSubscriber.AllInstances.SubIdGet = (o) => "89451";
                ShimCurrentSubscriber.AllInstances.LocationIdGet = (o) => expectedLocationId;

                // set WanIpAddress
                ShimCurrentSubscriber.AllInstances.WanIpAddressGet = o => "12:12:12:12";
                ShimRosettianClient.AllInstances.LoadSubscriberStringUserDto = (client, subId, userDto) => new SubscriberDto();
                ShimCurrentSubscriber.UpdateWanIpAddressString = (myWanIpAddress) => { };

                var RgType = new EquipmentTypeDto
                {
                    ONTModel = new ONTModelDto
                    {
                        BaseModel = expectedBaseModelValue
                    },
                    Category = EquipmentCategoryDto.RGDataPort
                };

                var equipmentDataDto = new EquipmentDto
                {
                    SerialNumber = expectedSerialNumber + "D01",
                    LocationId = expectedLocationId,
                    Type = RgType,
                    Status = "ACTIVE"
                };

                var equipmentPhoneDto01 = new EquipmentDto
                {
                    SerialNumber = expectedSerialNumber + "P01",
                    LocationId = expectedLocationId,
                    Type = RgType,
                    Status = "ACTIVE"
                };

                var equipmentPhoneDto02 = new EquipmentDto
                {
                    SerialNumber = expectedSerialNumber + "P02",
                    LocationId = expectedLocationId,
                    Type = RgType,
                    Status = "ACTIVE"
                };

                var searchEquipmentsResult = new List<EquipmentDto>();
                searchEquipmentsResult.Add(equipmentDataDto);
                searchEquipmentsResult.Add(equipmentPhoneDto01);
                searchEquipmentsResult.Add(equipmentPhoneDto02);

                ShimRosettianClient.AllInstances.SearchEquipmentSearchFieldsDtoUserDto =
                    (myTestClient, mySearchFields, myUserDto) => searchEquipmentsResult;

                ShimRosettianClient.AllInstances.ReturnToHeadendListOfStringUserDto = (myTestClient, mySerialNumberList, myUserDto) => true;

                var compositeEquipment = new CompositeEquipment
                {
                    ErrorDetails = new ErrorDetails()
                    {
                        Code = ResidentialGatewayErrorCode.GatewayNotFound.ToString(),
                        Message = @"Active RG not Found on Account. Provide the RG serial number and click the button below to associate."
                    }
                };
                ShimBusinessFacade.AllInstances.LoadCompositeEquipmentSearchFieldsDtoUserDto =
                    (myFacade, mySearchFields, arg3) => compositeEquipment;

                // First Act
                var residentialController = DependencyResolver.Current.GetService<ResidentialGatewayController>();
                var result = residentialController.RemoveResidentialGateway("deviceID");

                // First Assert
                Assert.IsNotNull(result, "Returned Json result with rendered partial view is null.");
                Assert.IsTrue(result is JsonResult, "result is not a JsonResult");

                // Second Act
                var resultJson = result as JsonResult;

                // Second Assert
                Assert.IsNotNull(resultJson, "Returned Json result is null.");
                dynamic resultData = resultJson.Data;
                var status = resultData.status as string;
                var errorMessage = string.Empty;
                if (status == "error")
                {
                    errorMessage = resultData.errorMessage;
                }
                Assert.AreEqual("valid", status, "RemoveResidentialGateway_HappyPath() - unexpected status from RemoveResidentialGateway() - {0}", errorMessage);
                var renderedPartial = resultData.returnedPartial as string;
                Assert.IsNotNull(renderedPartial, "Prerendered partial is null.");
            }
        }
        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;
        }
Пример #10
0
        public void FilterByDeviceTypeAlcatelTest()
        {
            // Arrange
            var allProfiles = DataHelper.GetAllQueryProfiles();
            var expectedProfileNames = new List<string>
            {
                "ALGPON_PROVISION",
                "ALGPON_SOFTWARE",
                "RETRIEVE ALL INFO",
                "DATA_XCON_INFO",
                "RETRIEVE_ALL_STATS"
            };
            var equipType = new EquipmentTypeDto
            {
                ONTModel = new ONTModel {Manufacturer = "Alcatel", PONType = PONTypeDto.GPON}
            };

            // Act
            var actualProfileNames = allProfiles.FilterByDeviceType(equipType);

            // Assert
            Assert.IsTrue(expectedProfileNames.SequenceEqual(actualProfileNames));
        }
 private bool CompareInput(EquipmentTypeDto equipmentTypeDto, string name)
 {
     return(equipmentTypeDto.Name.ToLower().Contains(name.ToLower()));
 }
Пример #12
0
        public void FilterByDeviceTypeTellabsTest()
        {
            // Arrange
            var allProfiles = DataHelper.GetAllQueryProfiles();
            var expectedProfileNames = new List<string>
            {
                "TELLABS_PROVISION",
                "XCON_INFO"
            };
            var equipType = new EquipmentTypeDto
            {
                ONTModel = new ONTModel {Manufacturer = "Tellabs", PONType = PONTypeDto.BPON}
            };

            // Act
            var actualProfileNames = allProfiles.FilterByDeviceType(equipType);

            // Assert
            Assert.IsTrue(expectedProfileNames.SequenceEqual(actualProfileNames));
        }
Пример #13
0
        public void FilterByDeviceTypeMotorolaGPONTest()
        {
            // Arrange
            var allProfiles = DataHelper.GetAllQueryProfiles();
            var expectedProfileNames = new List<string>
            {
                "AXSGPON_PROVISION",
                "FULL_QUERY_GPON",
                "DATA_SERVICE_GPON",
                "ONT_SUMMARY_GPON",
                "ALL AXS GPON PARAMS"
            };
            var equipType = new EquipmentTypeDto
            {
                ONTModel = new ONTModel {Manufacturer = "Motorola", PONType = PONTypeDto.GPON}
            };

            // Act
            var actualProfileNames = allProfiles.FilterByDeviceType(equipType);

            // Assert
            Assert.IsTrue(expectedProfileNames.SequenceEqual(actualProfileNames));
        }
Пример #14
0
        public void FilterByDeviceTypeCalixTest()
        {
            // Arrange
            var allProfiles = DataHelper.GetAllQueryProfiles();
            var expectedProfileNames = new List<string>
            {
                "CALE7GPON_PROVISION",
                "CALE7GPON_DATA_SVC_PROVISION",
                "CALE7GPON_SIP_SVC_PROVISION",
                "CALE7GPON_POTS_SVC_PROVISION",
                "CALE7GPON_T1_SVC_PROVISION",
                "CALE7GPON_H248_SVC_PROVISION",
                "CALE7GPON_MGCP_SVC_PROVISION"
            };
            var equipType = new EquipmentTypeDto
            {
                ONTModel = new ONTModel {Manufacturer = "Calix", PONType = PONTypeDto.GPON}
            };

            // Act
            var actualProfileNames = allProfiles.FilterByDeviceType(equipType);

            // Assert
            Assert.IsTrue(expectedProfileNames.SequenceEqual(actualProfileNames));
        }
Пример #15
0
 /// <summary>
 /// NewEquipment - returns an EquipmentDto based on the data passed in
 /// </summary>
 /// <param name="devID"></param>
 /// <param name="type"></param>
 /// <param name="unitAddr"></param>
 /// <param name="status"></param>
 /// <returns></returns>
 protected static EquipmentDto NewEquipment(string devID, EquipmentTypeDto type, string unitAddr, string status)
 {
     return new EquipmentDto
     {
         SerialNumber = devID,
         Type = type,
         UnitAddress = unitAddr,
         Status = status
     };
 }
Пример #16
0
        /// <summary>
        /// NewSerialNumber - provide a new serial number
        /// </summary>
        /// <param name="type"></param>
        /// <param name="portNumber"></param>
        /// <returns></returns>
        public static string NewSerialNumber(EquipmentTypeDto type, string portNumber)
        {
            string serialNum = DateTime.Now.ToString("ddyyhhmmssff");
            string port = string.Empty;

            if (type.Manufacturer.Contains("Motorola"))
            {
                return serialNum;
            }

            switch (type.Category)
            {
                case EquipmentCategoryDto.ONTDataPort:
                case EquipmentCategoryDto.ONTGigePort:
                {
                    port = string.Format("D{0}", portNumber);
                    break;
                }
                case EquipmentCategoryDto.ONTMocaPort:
                case EquipmentCategoryDto.ONTHpnaPort:
                {
                    port = string.Format("M{0}", portNumber);
                    break;
                }
                case EquipmentCategoryDto.ONTVoicePort:
                {
                    port = string.Format("P{0}", portNumber);
                    break;
                }
                case EquipmentCategoryDto.ONTVideoPort:
                {
                    port = string.Format("V{0}", portNumber);
                    break;
                }
            }

            serialNum = string.Format("{0}{1}", serialNum, port);

            return serialNum;
        }