Esempio n. 1
0
        public void SubscriberServicesModel_When_MaxBandwidth_variable_is_null_MaxBandwidthList_matches_count_of_values_from_configuration_file_and_the_values_match_too()
        {
            // Arrange
            var output = new StringBuilder();
            Assert.IsNotNull(_expectedBandwidthValues, "The appSettings key MaxBandwidthValues is missing from the unit test App.Config file");

            // First item is empty string for the UI
            var expectedMaxBandwidthList = new List<string>
                {
                    string.Empty
                };

            // Other items are coming from the MaxBandwidthValues appSettings
            expectedMaxBandwidthList.AddRange(_expectedBandwidthValues.Split(','));

            // Act
            var actualSubscriberServicesModel = new SubscriberServicesModel();
            actualSubscriberServicesModel.MaxBandwidth = null;

            // Assert
            if (expectedMaxBandwidthList.Count != actualSubscriberServicesModel.MaxBandwidthList.Count())
            {
                output.AppendLine();
                output.AppendFormat("The expected and actual lists have different number of items, {0} compared to {1} respectively", expectedMaxBandwidthList.Count, actualSubscriberServicesModel.MaxBandwidthList.Count());
                output.AppendLine();
                output.AppendFormat("The expected list has the following values {0}", string.Join(", ", expectedMaxBandwidthList.ToList()));
                output.AppendLine();
                output.AppendFormat("The actual list has the following values {0}", string.Join(", ", actualSubscriberServicesModel.MaxBandwidthList.ToList()));
            }

            foreach (var expectedIndividualString in expectedMaxBandwidthList)
            {
                if (!actualSubscriberServicesModel.MaxBandwidthList.Contains(expectedIndividualString))
                {
                    output.AppendLine();
                    output.AppendFormat("The actual results is missing the value {0}", expectedIndividualString);
                }
            }

            if (output.Length != 0)
            {
                Assert.Fail(output.ToString());
            }
        }
        public void AddServices_ValidateSuccessScenario()
        {
            using (ShimsContext.Create())
            {
                // current subId
                const string subId = "sub12345";

                // current locationId
                const string locId = "loc12345";

                // current service list
                var existingService = new ServiceDto
                {
                    ClassName = ServiceClassType.ProvisionedOntDataPort.GetStringValue(),
                    Name = "ENET",
                    Description = "RJ-45 ETHERNET PORT"
                };
                var existingServicesList = new List<ServiceDto> { existingService };

                // current subscriber with service list
                var currentSubscriber = new ShimCurrentSubscriber
                {
                    SubIdGet = () => subId,
                    LocationIdGet = () => locId,
                    ProvisionedServicesListGet = () => existingServicesList
                };

                // set values
                ShimCurrentSubscriber.GetInstance = () => currentSubscriber;
                ShimCurrentUser.AsUserDto = () => new UserDto();

                // service to be added
                var serviceToAdd = new ServiceDto
                {
                    ClassName = "DATA - FTTH SPEED",
                    Name = "F50M20M",
                    Description = "50M DOWN 20M UP"
                };
                var serviceToAddAsJson = "[" + new JavaScriptSerializer().Serialize(serviceToAdd) + "]";

                // expected service list (includes existing service and service to add)
                var expectedServicesListAfterAdd = new List<ServiceDto> { existingService, serviceToAdd };

                // expected SubscriberServiceModel after service add succeed
                var expectedSubscriberServiceModel = new SubscriberServicesModel
                {
                    SubscriberID = subId,
                    LocationID = locId,
                    ProvisionedServicesList = expectedServicesListAfterAdd
                };

                // set ROZ UpdateSubscriber succeed
                ShimRosettianClient.AllInstances.UpdateSubscriberSubscriberDtoBooleanUserDto =
                    (myTestClient, mySubscriberDto, overWriteServices, myUserDto) => true;

                // set CurrentSubscriber UpdateSubscriber succeed
                ShimCurrentSubscriber.UpdateSubscriberDto =
                    (mySubscriberDto) => { };

                // set MapToSubServicesModel
                ShimSubscriberExtension.MapToSubServicesModelCurrentSubscriber =
                    (myCurrentSubscriber) => expectedSubscriberServiceModel;

                // get service for ServicesController
                var servicesController = DependencyResolver.Current.GetService<ServicesController>();

                // call AddServices action method
                var actualJsonResult = servicesController.AddServices(serviceToAddAsJson) as JsonResult;

                // verify returned JsonResult is not null
                Assert.IsNotNull(actualJsonResult);

                // verify the result
                dynamic actualJson = actualJsonResult.Data;
                var status = actualJson.status as string;
                Assert.AreEqual("success", status, "AddServices returned Json result status does not match");
            }
        }