public void Upsell_Order_is_successfully_submitted_to_Offline_Order_System_with_required_fields()
        {
            using (ShimsContext.Create())
            {
                #region Initial Setup

                SIMPLTestContext testContext = new SIMPLTestContext();
                var session = GetShimmedSession();

                var context = new ShimHttpContext();
                ShimHttpContext.CurrentGet = () => context;
                ShimHttpContext.AllInstances.SessionGet = (o) => session;

                ShimCurrentSubscriber.GetInstance = () => new ShimCurrentSubscriber
                {
                    DataProductTypeGet = () => SubscriberEnums.DataProductType.XDsl,
                    VideoProductTypeGet = () => SubscriberEnums.VideoProductType.IpTv,
                    StateGet = () => "CT",
                    WtnGet = () => "2061272727",
                    ProvisionedServicesListGet = () => new List<ServiceDto>
                    {
                        new ServiceDto
                        {
                            Action = "None",
                            ClassName = "DATA - DSL SPEED",
                            Description = "12 MBPS/1.5 MBPS",
                            Name = "D12M1M",
                            Type = ServiceClassTypeDto.None
                        },
                        new ServiceDto
                        {
                            Action = "None",
                            ClassName = "DSL - TECHNOLOGY CODE",
                            Description = "HSIA SERVICES",
                            Name = "VDSL",
                            Type = ServiceClassTypeDto.None
                        }
                    }
                };

                ShimUpsellRepository.AllInstances.GetUpsellProductClassesDefinitions = delegate
                {
                    return new List<UpsellProductClassDefinitionDto>();
                };

                //Given a user
                //And user is authenticated to process Upsell submission
                var fakeUser = testContext.GetFakeUserDtoObject();
                ShimCurrentUser.AsUserDto = () => fakeUser;
                ShimCurrentUser.GetInstance = () => new ShimCurrentUser
                {
                    UniqueIdGet = () => "mjw425"
                };

                string upsellJsonData =
                    "[{'ClassName':'DATA - DSL SPEED','Name':'D12M1M','Description':'12MBPS / 1.5MBPS'},{'ClassName':'DATA - DSL SPEED','Name':'D18M1M','Description':'18MBPS / 1.5MBPS'},{'ClassName':'F-SECURE','Name':'CANYW','Description':'Content Anywhere'},{'ClassName':'F-SECURE','Name':'DCPRO','Description':'Dropcam Pro'}]";
                string autorizeBy = "Mark";

                //No need to call Update subscriber hence shimming the method
                ShimRosettianClient.AllInstances.UpdateSubscriberSubscriberDtoBooleanUserDto = delegate { return true; };

                ShimCurrentSubscriber.UpdateSubscriberDto = delegate { };
                //ShimMailHelper.AllInstances.Send = delegate { };

                #endregion

                // And all required fields are captured for Upsell submission
                UpsellSubmittedOrder subReq = new UpsellSubmittedOrder
                {
                    SimpleId = 2,
                    SubscriberId = "490000608154",
                    SubscriberName = "DWAYNE BROWN",
                    TelephoneNumber = "9999999999",
                    SubmittedBy = "mjw425",
                    SubmissionDate = new DateTimeOffset(DateTime.Now).ToString(),
                    StatusDescription = UpsellStatus.New.ToString(),
                    AuthorizedBy = "Mark",
                    AccountType = "R",
                };

                List<UpsellSubmittedProduct> prodInReq = new List<UpsellSubmittedProduct>()
                {
                    new UpsellSubmittedProduct()
                    {
                        ProductId = 1,
                        ProductName = "D18M1M",
                        ProductDescription = "18MBPS / 1.5MBPS",
                        productAction = "A"
                    },
                    new UpsellSubmittedProduct()
                    {
                        ProductId = 2,
                        ProductName = "D12M1M",
                        ProductDescription = "12MBPS / 1.5MBPS",
                        productAction = "R"
                    }
                };

                // And submitting order to Offline Order System is enabled
                ShimFeatureFlags.IsEnabledString = (o) => true;

                // When Upsell submission is send to Offline Order System
                //Shimming method which sends request to Offline Order System
                OfflineOrderSubmitResponse offlineSubmissionResponse = null;
                bool isSubmitToOfflineCalled = false;
                ShimOfflineOrderSystemClient.AllInstances.SubmitOrderToOfflineOrderSystemOfflineOrderSubmitRequest =
                    delegate
                    {
                        isSubmitToOfflineCalled = true;
                            //Then Upsell submission is successful
                             offlineSubmissionResponse = new OfflineOrderSubmitResponse
                            {
                                Content = "",
                                IsSuccess = true,
                                StatusCode = HttpStatusCode.Created
                            };

                        return offlineSubmissionResponse;
                    };

                //Shimming method which save the upsell order in SIMPL - Satisfy saving submit outside Offline Order Sytem
                bool isRecordSavedInSIMPL = false;
                UpsellAddRecordResult addedRecord = null;
                ShimUpsellRepository.AllInstances.AddRecordUpsellSubmissionDtoIEnumerableOfUpsellProductChangeDto =
                    delegate
                    {
                        isRecordSavedInSIMPL = true;
                        //And all required fields are captured for Upsell submission
                        addedRecord = new UpsellAddRecordResult()
                        {
                            UpsellNewRecord = subReq,

                            UpsellNewlyAddedProducts = prodInReq,
                        };
                        return addedRecord;
                    };

                //Shimming the databse update which changes the status of the record
                bool didRecordStatusUpdatedInSIML = false;
                ShimUpsellRepository.UpdateRecordStatusInt32UpsellStatus = delegate
                {
                    return didRecordStatusUpdatedInSIML = true;
                };

                //Action
                var result = UpsellControllerForTests.SubmitUpsell(upsellJsonData, autorizeBy) as PartialViewResult;

                //Was data returned?
                Assert.IsNotNull(result, "No result returned from UpdateUpsellRecord");

                // And Upsell Submission is saved outside Offline Order System
                Assert.IsTrue(isRecordSavedInSIMPL, "Order is not saved in SIMPL");
                Assert.IsNotNull(addedRecord,"Record added in SIMPL is Null");
                // Then Upsell submission is successful
                // And successful response is returned by Offline Order System
                Assert.IsTrue(isSubmitToOfflineCalled,"Offline Service was not called");
                Assert.IsNotNull(offlineSubmissionResponse,"The offline response is null");
                Assert.IsTrue(offlineSubmissionResponse.IsSuccess,
                    String.Format("Upsell submission is not successful. The returned response is: {0}",
                        offlineSubmissionResponse.IsSuccess));
                Assert.AreEqual(offlineSubmissionResponse.StatusCode, HttpStatusCode.Created,
                    string.Format("Invalid code the recieved from the service call. Expected: {0}, Recieved: {1}",
                        HttpStatusCode.Created, offlineSubmissionResponse.StatusCode));

                // And record indicates that the submission to the Offline Order System was successful
                Assert.IsTrue(didRecordStatusUpdatedInSIML,
                    "Record status is not updated, which indicates usccessful submission to Offline Order System");
            }
        }
        public void Upsell_submit_is_partially_successful()
        {
            using (ShimsContext.Create())
            {
                #region Initial Setup
                SIMPLTestContext testContext = new SIMPLTestContext();
                var session = GetShimmedSession();

                var context = new ShimHttpContext();
                ShimHttpContext.CurrentGet = () => context;
                ShimHttpContext.AllInstances.SessionGet = (o) => session;

                ShimCurrentSubscriber.GetInstance = () => new ShimCurrentSubscriber
                {
                    DataProductTypeGet = () => SubscriberEnums.DataProductType.XDsl,
                    VideoProductTypeGet = () => SubscriberEnums.VideoProductType.IpTv,
                    StateGet = () => "CT",
                    WtnGet = () => "2061272727",
                    ProvisionedServicesListGet = () => new List<ServiceDto>
                    {
                        new ServiceDto
                        {
                            Action = "None",
                            ClassName = "DATA - DSL SPEED",
                            Description = "12 MBPS/1.5 MBPS",
                            Name = "D12M1M",
                            Type =  ServiceClassTypeDto.None
                        },
                        new ServiceDto
                        {
                            Action = "None",
                            ClassName = "DSL - TECHNOLOGY CODE",
                            Description = "HSIA SERVICES",
                            Name = "VDSL",
                            Type =  ServiceClassTypeDto.None
                        }
                    }
                };

                ShimUpsellRepository.AllInstances.GetUpsellProductClassesDefinitions = delegate
                {
                    return new List<UpsellProductClassDefinitionDto>();
                };

                //Given a user
                //And user is authenticated to process Upsell submission
                var fakeUser = testContext.GetFakeUserDtoObject();
                ShimCurrentUser.AsUserDto = () => fakeUser;
                ShimCurrentUser.GetInstance = () => new ShimCurrentUser
                {
                    UniqueIdGet = () => "mjw425"
                };

                string upsellJsonData = "[{'ClassName':'DATA - DSL SPEED','Name':'D12M1M','Description':'12MBPS / 1.5MBPS'},{'ClassName':'DATA - DSL SPEED','Name':'D18M1M','Description':'18MBPS / 1.5MBPS'},{'ClassName':'F-SECURE','Name':'CANYW','Description':'Content Anywhere'},{'ClassName':'F-SECURE','Name':'DCPRO','Description':'Dropcam Pro'}]";
                string autorizeBy = "Mark";

                //No need to call Update subscriber hence shimming the method
              //  bool isUpdateSubscriberCalled = false;
                ShimRosettianClient.AllInstances.UpdateSubscriberSubscriberDtoBooleanUserDto = delegate { return true; };

                ShimCurrentSubscriber.UpdateSubscriberDto = delegate { };
                //ShimMailHelper.AllInstances.Send = delegate { };

                #endregion

                const int numOfProductsInTheReq = 2;
                //If num of products are even then half of them will fail. If num of products are odd then every even item in the req will fail.
                const int numOfProductsThatShouldFail = 1;

                //And all the required fields are captured for Upsell submission
                UpsellSubmittedOrder subReq = new UpsellSubmittedOrder
                {
                    SimpleId = 2,
                    SubscriberId = "490000608154",
                    SubscriberName = "DWAYNE BROWN",
                    TelephoneNumber = "9999999999",
                    SubmittedBy = "mjw425",
                    SubmissionDate = new DateTimeOffset(DateTime.Now).ToString(),
                    StatusDescription = UpsellStatus.New.ToString(),
                    AuthorizedBy = "Mark",
                    AccountType = "R",

                };

                List<UpsellSubmittedProduct> prodInReq = new List<UpsellSubmittedProduct>()
            {
                new UpsellSubmittedProduct()
                               {
                                   ProductId = 1,
                                   ProductName = "D18M1M",
                                   ProductDescription = "18MBPS / 1.5MBPS",
                                   productAction = "A"
                               },
                               new UpsellSubmittedProduct()
                               {
                                   ProductId = 2,
                                   ProductName = "D12M1M",
                                   ProductDescription = "12MBPS / 1.5MBPS",
                                   productAction = "R"
                               }
            };

                //And submitting order to Offline Order System is enabled
                bool isFeatureFlagOn = false;
                ShimFeatureFlags.IsEnabledString = (o) => isFeatureFlagOn = true;

                //And failure occurs processing Offline Order Submission
                //When Order is submitted
                OfflineOrderSubmitResponse offlineSubmissionResponse = null;
                bool shouldFailTheSubmission = false;

                ShimOfflineOrderSystemClient.AllInstances.SubmitOrderToOfflineOrderSystemOfflineOrderSubmitRequest =
                              delegate
                              {
                                  if (isFeatureFlagOn)
                                  {

                                      // Since request going to be partially successful we need a way to control that.
                                      //The way control is acheived is by toggeling 'shouldFailTheSubmission' boolean
                                      if (shouldFailTheSubmission)
                                      {
                                          shouldFailTheSubmission = false;
                                          return offlineSubmissionResponse = new OfflineOrderSubmitResponse
                                          {
                                              //return dummy content. this will be different for each
                                              Content = "{'message': 'The request is invalid.','modelState': {'simple.simpleId': ['An error has occurred.','\'Simple Id\' should not be empty.']}}",
                                              IsSuccess = false,
                                              StatusCode = HttpStatusCode.BadRequest
                                          };
                                      }
                                      else
                                      {
                                          shouldFailTheSubmission = true;
                                          //Then Upsell submission is successful
                                          return offlineSubmissionResponse = new OfflineOrderSubmitResponse
                                          {
                                              Content = "",
                                              IsSuccess = true,
                                              StatusCode = HttpStatusCode.Created
                                          };
                                      }

                                  }
                                  return offlineSubmissionResponse;
                              };

                //Then Upsell Submission is saved outside Offline Order System
                ShimUpsellRepository.AllInstances.AddRecordUpsellSubmissionDtoIEnumerableOfUpsellProductChangeDto =
                     delegate
                     {
                         //And all required fields are captured for Upsell submission
                         return new UpsellAddRecordResult()
                         {
                             UpsellNewRecord = subReq,

                             UpsellNewlyAddedProducts = prodInReq,
                         };
                     };

                //Shimming logging of product level failures
                bool didProductFailsLogged = false;
                int numOfProductFailed = 0;
                ShimUpsellRepository.AddOfflineProductFailuresInt32OfflineOrderSubmitResponse = delegate
                {
                    didProductFailsLogged = true;
                    numOfProductFailed++;  //Keeping track of how many products failed to reach Offline Order System
                };

                //Shimming the update status database call
                bool didRecordStatusUpdatedInSIML = false;
                UpsellStatus recStatus = UpsellStatus.Offline_Submission_Successful;
                ShimUpsellRepository.UpdateRecordStatusInt32UpsellStatus = delegate
                {

                    if (numOfProductFailed == numOfProductsInTheReq)  //Two since there are only two product in the data.
                    {
                        recStatus = UpsellStatus.Offline_Submission_Failed;
                    }
                    else if (numOfProductFailed < numOfProductsInTheReq)
                    {
                        recStatus = UpsellStatus.Offline_Submission_Partially_Successful;
                    }

                    return didRecordStatusUpdatedInSIML = true;
                };

                //Shimming method that sends email
                bool isEmailSend = false;
                ShimEmailRepository.AllInstances.SendMail = delegate
                {
                    return isEmailSend = true;
                };

                //Action
                var result = UpsellControllerForTests.SubmitUpsell(upsellJsonData, autorizeBy) as PartialViewResult;

                //Was data returned?
                Assert.IsNotNull(result, "No result returned from UpdateUpsellRecord");

                //And Upsell Offline Order Submission is unsuccessful
                //Assert.IsNotNull(offlineSubmissionResponse, "Offline submission response is null");
                //Assert.IsFalse(offlineSubmissionResponse.IsSuccess, String.Format("Offline submission returned response: {0} and Status Code: {1}", offlineSubmissionResponse.IsSuccess, offlineSubmissionResponse.StatusCode));

                //And record indicate that the submission to the Offline Order System was unsuccessful
                Assert.IsTrue(didRecordStatusUpdatedInSIML, "Record status was not updated in SIMPL. Set value: {0}", didRecordStatusUpdatedInSIML);
                Assert.AreEqual(recStatus, UpsellStatus.Offline_Submission_Partially_Successful, "Record status should be 'Partially Successful'.Instead it was updated to: {0}", recStatus);

                //And Upsell product failed to reach Offline Order System are saved
                Assert.IsTrue(didProductFailsLogged, "Adding product failures to db is not called.");
                Assert.AreEqual(numOfProductFailed, numOfProductsThatShouldFail, String.Format("Num of product logged are not same as the products in request. Failed Product: {0} and Products in req: {1}", numOfProductFailed, numOfProductsThatShouldFail));

                //And email with failure details is send to Offline Order System
                Assert.IsTrue(isEmailSend, "No email is send.");
            }
        }
Example #3
0
        private UpsellAddRecordResult GetRecordResult(int newRecordId,UpsellSubmissionDto submittedRecord,string submittedDate, 
            List<UpsellSubmittedProduct> submittedProducts)
        {
            var newRecord = new UpsellSubmittedOrder()
            {
                SimpleId = newRecordId,
                SubscriberId = submittedRecord.SubscriberId,
                SubscriberName = submittedRecord.SubscriberName,
                TelephoneNumber = submittedRecord.TelephoneNumber,
                SubmittedBy = submittedRecord.SubmittedBy,
                SubmissionDate = submittedDate,
                StatusDescription = UpsellStatus.New.ToString(),
                AuthorizedBy = submittedRecord.AuthorizedBy,
                AccountType = submittedRecord.AccountType.ToUpsellAccountType(),
            };

            return   new UpsellAddRecordResult()
            {
                UpsellNewRecord = newRecord,
                UpsellNewlyAddedProducts = submittedProducts
            };
        }