public void CreateSubscriber_With_BasicInfo_ContactPhone_Email_Pin_PPV_AccountType_ValidateUserAbleToCreateNewSubscriber() { using (ShimsContext.Create()) { // Given a user that has permission to create new subscriber ShimCurrentUser.AsUserDto = new SIMPLTestContext().GetFakeUserDtoObject; // And the new subscriber has a valid id // And the new subscriber has a valid name // And the new subscriber has a service enabled default to false // And the new subscriber has a contact phone // And the new subscriber has a email // And the new subscriber has a pin // And the new subscriber has ppv settings // And the new subscriber has residential account type var createSubModel = new CreateSubscriberModel { USI = "subid", Name = "subname", AccountType = AccountTypeDto.Residential, ServiceEnabled = false, CBR = "4250010001", Email = "*****@*****.**", PIN = "subpin", PPVCap = "150.00", PPVResetDay = "15", PPVPrivilege = SubscriberEnums.PPVPrivilegeEnum.Capped }; // When creating new subscriber ShimRosettianClient.AllInstances.CreateSubscriberSubscriberDtoUserDto = (myClient, mySubscriberDto, myUserDto) => true; var searchController = DependencyResolver.Current.GetService<SearchController>(); var actionResponse = searchController.CreateSubscriber(createSubModel) as JsonResult; // Then the user receives a response Assert.IsNotNull(actionResponse, "CreateSubscriber json result is null"); Assert.IsNotNull(actionResponse.Data, "CreateSubscriber json result data is null"); // And the response is successful var jss = new JavaScriptSerializer(); var expectedResult = new { status = "valid", isModal = false, newSubscriberID = createSubModel.USI }.ToJSON(); Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResponse.Data.ToJSON())); } }
public void User_Attempts_To_create_a_new_subscriber_with_correct_data_and_an_error_is_returned() { using (ShimsContext.Create()) { //Arrange // Given a user that has permission to create new subscriber ShimCurrentUser.AsUserDto = new SIMPLTestContext().GetFakeUserDtoObject; //And good data is used in the model var createSubModel = new CreateSubscriberModel { USI = "subid", Name = "subname", AccountType = AccountTypeDto.Residential, ServiceEnabled = false, CBR = "4250010001", Email = "*****@*****.**", PIN = "subpin", PPVCap = "150.00", PPVResetDay = "15", PPVPrivilege = SubscriberEnums.PPVPrivilegeEnum.Capped }; var searchController = DependencyResolver.Current.GetService<SearchController>(); //This is for creating a Fault exception const string expectedErrorMessage = "This is a fault exception message"; var faultDetail = new ValidationDetailDto() { Message = expectedErrorMessage }; var faultDetails = new List<ValidationDetailDto>(); faultDetails.Add(faultDetail); var validationFault = new ValidationFaultDto() { Details = faultDetails }; var fault = new FaultException<ValidationFaultDto>(validationFault); //Have Controller CreateSubscriber method throw the fault when called ShimRosettianClient.AllInstances.CreateSubscriberSubscriberDtoUserDto = delegate { throw fault; }; //Act //Call the actual controller method var actionResponse = searchController.CreateSubscriber(createSubModel) as JsonResult; //Assert // Then the user receives a response Assert.IsNotNull(actionResponse, "CreateSubscriber json result is null"); Assert.IsNotNull(actionResponse.Data, "CreateSubscriber json result data is null"); // And the expected response is a Fault exception var jss = new JavaScriptSerializer(); var expectedResult = new { status = "error", isModal = false, errorMessage = "This is a fault exception message" }.ToJSON(); Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResponse.Data.ToJSON())); } }
public void User_attempts_to_create_a_new_subscriber_with_correct_data_and_an_non_Rosettian_error_is_returned() { using (ShimsContext.Create()) { //Arrange // Given a user that has permission to create new subscriber ShimCurrentUser.AsUserDto = new SIMPLTestContext().GetFakeUserDtoObject; var createSubModel = new CreateSubscriberModel() { USI = "subid", Name = "subname", AccountType = AccountTypeDto.Residential, ServiceEnabled = false, CBR = "4250010001", Email = "*****@*****.**", PIN = "subpin", PPVCap = "150.00", PPVResetDay = "15", PPVPrivilege = SubscriberEnums.PPVPrivilegeEnum.Capped }; // When creating new subscriber ShimRosettianClient.AllInstances.CreateSubscriberSubscriberDtoUserDto = (myClient, mySubscriberDto, myUserDto) => true; //Create a non-Fault exception string exceptionMessage = "This is my argument exception"; ShimSubscriberExtension.MapToNewSubscriberCreateSubscriberModel = delegate { throw new ArgumentException(exceptionMessage); }; //Act var searchController = DependencyResolver.Current.GetService<SearchController>(); var actionResponse = searchController.CreateSubscriber(createSubModel) as JsonResult; //Assert // Then the user receives a response Assert.IsNotNull(actionResponse, "CreateSubscriber json result is null"); Assert.IsNotNull(actionResponse.Data, "CreateSubscriber json result data is null"); // And the response is successful var jss = new JavaScriptSerializer(); var expectedResult = new { status = "error", isModal = false, errorMessage = exceptionMessage }.ToJSON(); Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(actionResponse.Data.ToJSON())); } }
public void CreateSubscriber_With_BasicInfo_ContactPhone_Email_Pin_PPV_AccountType_ValidateUserAbleToCreateNewSubscriber() { var sub = new SubscriberDto(); try { // Given a user that has permission to create new subscriber // And a new subscriber with all valid info // And the new subscriber has a valid id // And the new subscriber has a valid name // And the new subscriber has a valid cbr // And the new subscriber has a valid email // And the new subscriber has a valid pin sub = DataHelper.NewSubscriberData(); // And the new subscriber has a residential account Assert.IsTrue(!string.IsNullOrWhiteSpace(sub.ID) && sub.Accounts != null && sub.Accounts.Any()); sub.Accounts.First().AccountType = AccountTypeDto.Residential; // And the new subscriber has ppv settings Assert.AreEqual("2", sub.Accounts.First().PPVPrivilege); var createSubModel = new CreateSubscriberModel { USI = sub.ID, Name = sub.Name, AccountType = sub.Accounts.First().AccountType, ServiceEnabled = false, CBR = sub.SubContactPhone, Email = sub.SubContactEmail, PIN = sub.Accounts.First().PIN, PPVCap = sub.Accounts.First().PPVCap, PPVResetDay = sub.Accounts.First().PPVResetDay, PPVPrivilege = SubscriberEnums.PPVPrivilegeEnum.Capped }; // When creating new subscriber with the valid subscriber info var result = SearchControllerForTest.CreateSubscriber(createSubModel) as JsonResult; // Then the user receives a response Assert.IsNotNull(result, "CreateSubscriber json result is null"); Assert.IsNotNull(result.Data, "CreateSubscriber json result data is null"); // And the response is successful var jss = new JavaScriptSerializer(); var expectedResult = new { status = "valid", isModal = false, newSubscriberID = sub.ID }.ToJSON(); Assert.AreEqual(jss.Serialize(expectedResult), jss.Serialize(result.Data.ToJSON())); // And the new subscriber created in provisioning system var actualSub = DataHelper.LoadSubscriber(sub.ID); Assert.IsTrue(actualSub != null && actualSub.Accounts != null && actualSub.Accounts.Any(), "Subscriber account is null"); // And the new subscriber created with the requested id Assert.AreEqual(sub.ID, actualSub.ID, "Id does not match"); // And the new subscriber created with the requested name Assert.AreEqual(sub.Name, actualSub.Name, "Name does not match"); // And the new subscriber created with the requested cbr Assert.AreEqual(sub.SubContactPhone, actualSub.SubContactPhone, "SubContactPhone does not match"); // And the new subscriber created with the requested email Assert.AreEqual(sub.SubContactEmail, actualSub.SubContactEmail, "SubContactEmail does not match"); // And the new subscriber created with the requested pin Assert.AreEqual(sub.Accounts.First().PIN, actualSub.Accounts.First().PIN, "PIN does not match"); // And the new subscriber created with the requested ppv settings Assert.AreEqual(sub.Accounts.First().PPVCap, actualSub.Accounts.First().PPVCap, "PPVCap does not match"); Assert.AreEqual(sub.Accounts.First().PPVPrivilege, actualSub.Accounts.First().PPVPrivilege, "PPVPrivilege does not match"); Assert.AreEqual(sub.Accounts.First().PPVResetDay, actualSub.Accounts.First().PPVResetDay, "PPVPrivilege does not match"); // And the new subscriber created with the requested account type Assert.AreEqual(sub.Accounts.First().AccountType, actualSub.Accounts.First().AccountType, "Account type does not match"); } catch (Exception ex) { Assert.IsTrue(ex is AssertFailedException, ex.ToString()); throw; } finally { DataHelper.DeleteSubscriber(sub.ID); } }