public void SettingUrlHelperWithoutRequest_Throws()
 {
     CustomersController controller = new CustomersController();
     Assert.Throws<InvalidOperationException>(
         () => controller.Url = new UrlHelper(),
         "The property 'Request' on 'CustomersController' is null. The property must be initialized with a non-null value.");
 }
        public void GetCreateShouldReturnCustomerView()
        {
            var customersController = new CustomersController();
            var result = customersController.Create() as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(Customer));
        }
        public void Get()
        {
            // Arrange
            CustomersController controller = new CustomersController();

            // Act
            IEnumerable<Customer> result = controller.Get();

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
        }
        public void Post_With_EmptyConfiguration_ThrowsNoRoute()
        {
            // Arrange
            CustomersController controller = new CustomersController();
            controller.Configuration = new HttpConfiguration();
            controller.Request = new HttpRequestMessage();

            // Act
            Assert.ThrowsArgument(
                () => controller.Post(new Customer { ID = 42 }),
                "name",
                "A route named 'default' could not be found in the route collection.");
        }
        public static CustomersController GetInitialisedCustomersController(ICustomerService customerService)
        {
            var controller = new CustomersController(customerService)
            {
                Request = new HttpRequestMessage { RequestUri = new Uri(Url) },
                Configuration = new HttpConfiguration()
            };

            controller.Configuration.MapHttpAttributeRoutes();
            controller.Configuration.EnsureInitialized();

            return controller;
        }
        public void Post_With_InitializeConfigurationAndRequestAndRouteData()
        {
            // Arrange
            CustomersController controller = new CustomersController();
            controller.Configuration = new HttpConfiguration();
            controller.Configuration.Routes.MapHttpRoute("default", "{controller}/{id}", new { id = RouteParameter.Optional });
            controller.RouteData = new HttpRouteData(new HttpRoute(), new HttpRouteValueDictionary { { "controller", "Customers" } });
            controller.Request = new HttpRequestMessage { RequestUri = new Uri("http://locahost/Customers") };

            // Act
            var result = controller.Post(new Customer { ID = 42 });

            // Assert
            Customer customer;
            Assert.Equal("http://locahost/Customers/42", result.Headers.Location.AbsoluteUri);
            Assert.True(result.TryGetContentValue<Customer>(out customer));
            Assert.Equal(42, customer.ID);
        }
        public void PostCreateShouldSaveCustomerAndReturnDetailsView()
        {
            var customersController = new CustomersController();
            var customer = new Customer
            {
                Name = "Hugo Reyes",
                Email = "*****@*****.**",
                Phone = "720-123-5477"
            };

            var result = customersController.Create(customer) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Details", result.ViewName);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(Customer));

            customer = result.ViewData.Model as Customer;
            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.Id > 0);
        }
        public void Post_With_EmptyRequest_And_MockUrlHelper()
        {
            // Arrange
            CustomersController controller = new CustomersController();
            controller.Configuration = new HttpConfiguration();
            controller.Request = new HttpRequestMessage();

            Mock<UrlHelper> url = new Mock<UrlHelper>();
            url.Setup(u => u.Link("default", new { id = 42 })).Returns("http://location_header/").Verifiable();
            controller.Url = url.Object;

            // Act
            var result = controller.Post(new Customer { ID = 42 });

            // Assert
            Customer customer;
            Assert.Equal("http://location_header/", result.Headers.Location.AbsoluteUri);
            Assert.True(result.TryGetContentValue<Customer>(out customer));
            Assert.Equal(42, customer.ID);
        }
        /// <summary>
        /// Successful response returned from an Create Installment Plan request.
        /// https://apidocs.securenet.com/docs/recurringbilling.html?lang=csharp#installment
        /// </summary>
        public string Recurring_Billing_Create_Installment_Plan_Request_Returns_Successfully(string customerId, string paymentMethodId)
        {
            // Arrange
            var request = new AddInstallmentPaymentPlanRequest
            {
                CustomerId = customerId,
                Plan = new InstallmentPaymentPlan
                {
                    CycleType = "monthly",
                    DayOfTheMonth = 1,
                    DayOfTheWeek = 1,
                    Frequency = 1,
                    NumberOfPayments = 12,
                    InstallmentAmount = 276.95m,
                    RemainderAmount = 12.90m,
                    BalloonPaymentAddedTo = "FIRST",
                    RemainderAmountAddedTo = "LAST",
                    StartDate = Convert.ToDateTime("10/1/2017"),
                    EndDate = Convert.ToDateTime("10/1/2020"),
                    MaxRetries = 4,
                    PrimaryPaymentMethodId = paymentMethodId,
                    Notes = "This is an installment plan",
                    Active = true,
                    UserDefinedFields = new List<UserDefinedField>
                    {
                        new UserDefinedField
                        {
                            UdfName = "Udf1",
                            UdfValue = "Udf1_Value"
                        },
                        new UserDefinedField
                        {
                            UdfName = "Udf2",
                            UdfValue = "Udf2_Value"
                        },
                        new UserDefinedField
                        {
                            UdfName = "Udf3",
                            UdfValue = "Udf3_Value"
                        },
                        new UserDefinedField
                        {
                            UdfName = "Udf4",
                            UdfValue = "Udf4_Value"
                        },
                        new UserDefinedField
                        {
                            UdfName = "Udf5",
                            UdfValue = "Udf5_Value"
                        }
                    },
                },
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<AddInstallmentPaymentPlanResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
            Assert.IsNotNull(response.PlanId);

            return response.PlanId;
        }
        private CustomersController GetCustomersControllerInitialized(INavigationService navigationService, List<Customer> customers)
        {
            CustomersController controller = new CustomersController(navigationService);
            StateValue<Customer>  currentCustomerState = new StateValue<Customer>();
            StateValue<List<Customer>> customersState = new StateValue<List<Customer>>(customers);

            controller.InitializeState(currentCustomerState, customersState);

            return controller;
        }
        /// <summary>
        /// Successful response returned from an Update Payment Account request.
        /// https://apidocs.securenet.com/docs/vault.html?lang=csharp#updateaccount
        /// </summary>
        public void SecureNet_Vault_Update_Payment_Account_Request_Returns_Successfully(string customerId, string paymentMethodId)
        {
            // Arrange
            var request = new UpdatePaymentMethodRequest
            {
                CustomerId = customerId,
                PaymentMethodId = paymentMethodId,
                Card = new Card
                {
                    Number = "4444 3333 2222 1111",
                    Cvv = "999",
                    ExpirationDate = "04/2016",
                    Address = new Address
                    {
                        Line1 = "123 Main St.",
                        City = "Austin",
                        State = "TX",
                        Zip = "78759"
                    },
                    FirstName = "Jack",
                    LastName = "Updated"
                },
                Phone = "512-250-7865",
                Notes = "Create a vault account",
                Primary = true,
                UserDefinedFields = new List<UserDefinedField>
                {
                    new UserDefinedField
                    {
                        UdfName = "Udf1",
                        UdfValue = "Udf1_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf2",
                        UdfValue = "Udf2_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf3",
                        UdfValue = "Udf3_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf4",
                        UdfValue = "Udf4_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf5",
                        UdfValue = "Udf5_Value"
                    }
                },
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<UpdatePaymentMethodResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
        }
        /// <summary>
        /// Successful response returned from a Create Customer request.
        /// https://apidocs.securenet.com/docs/vault.html?lang=csharp#createcustomer
        /// </summary>
        public string SecureNet_Vault_Create_Customer_Request_Returns_Successfully()
        {
            // Arrange
            var request = new CreateCustomerRequest
            {
                FirstName = "Jack",
                LastName = "Test",
                PhoneNumber = "512-122-1211",
                EmailAddress = "*****@*****.**",
                SendEmailReceipts = true,
                Notes = "test notes",
                Address = new Address
                {
                    Line1 = "123 Main St.",
                    City = "Austin",
                    State = "TX",
                    Zip = "78759"
                },
                Company = "Test Company",
                UserDefinedFields = new List<UserDefinedField>
                {
                    new UserDefinedField
                    {
                        UdfName = "Udf1",
                        UdfValue = "Udf1_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf2",
                        UdfValue = "Udf2_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf3",
                        UdfValue = "Udf3_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf4",
                        UdfValue = "Udf4_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf5",
                        UdfValue = "Udf5_Value"
                    },
                },
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<CreateCustomerResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
            Assert.IsNotNull(response.CustomerId);
            Assert.IsTrue(response.CustomerId.Length > 0);

            return response.CustomerId;
        }
        public void Recurring_Billing_Update_Variable_Payment_Plan_Request_Returns_Successfully(string customerId, string planId)
        {
            // Arrange
            var request = new UpdateVariablePaymentPlanRequest
            {
                CustomerId = customerId,
                PlanId = planId,
                Plan = new StoredVariablePaymentPlan
                {
                    PlanStartDate = Convert.ToDateTime("07/12/2014"),
                    ScheduledPayments = new List<StoredScheduledVariablePaymentPlan>
                    {
                        new StoredScheduledVariablePaymentPlan
                        {
                            ScheduleId = 1093749,
                            PaymentDate = Convert.ToDateTime("12/05/2014"),
                            Amount = 200
                        }

                    },
                    MaxRetries = 4,
                    Notes = "This is an updated variable Payment Plan"
                },
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<UpdateVariablePaymentPlanResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
        }
        /// <summary>
        /// Successful response returned from a Retrieve Payment Account request.
        /// https://apidocs.securenet.com/docs/vault.html?lang=csharp#retrieveaccount
        /// </summary>
        public void SecureNet_Vault_Retrieve_Payment_Account_Request_Returns_Successfully(string customerId, string paymentMethodId)
        {
            // Arrange
            var request = new RetrievePaymentAccountRequest
            {
                CustomerId = customerId,
                PaymentMethodId = paymentMethodId
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<RetrievePaymentAccountResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
        }
        /// <summary>
        /// Successful response returned from an Update Recurring Payment Plan request.
        /// https://apidocs.securenet.com/docs/recurringbilling.html?lang=csharp#updaterecurring
        /// </summary>
        public void Recurring_Billing_Update_Recurring_Payment_Plan_Request_Returns_Successfully(string customerId, string planId)
        {
            // Arrange
            var request = new UpdateRecurringPaymentPlanRequest
            {
                CustomerId = customerId,
                PlanId = planId,
                Plan = new RecurringPaymentPlan
                {
                    CycleType = "monthly",
                    DayOfTheMonth = 1,
                    DayOfTheWeek = 1,
                    Month = 6,
                    Frequency = 10,
                    Amount = 52.95m,
                    StartDate = Convert.ToDateTime("09/01/2014"),
                    EndDate = Convert.ToDateTime("12/01/2018"),
                    MaxRetries = 4,
                    Notes = "This is an updated recurring plan",
                    Active = true
                },
                IncludeRawObjects = true,
                IncludeRequest = true,
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<UpdateRecurringPaymentPlanResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
        }
        /// <summary>
        /// Successful response returned from a Pay with Stored Vault Account request.
        /// https://apidocs.securenet.com/docs/vault.html?lang=csharp#payaccount
        /// </summary>
        public void SecureNet_Vault_Pay_With_Stored_Vault_Account_Request_Returns_Successfully(string customerId, string paymentMethodId)
        {
            // Arrange
            var request = new ChargeRequest
            {
                Amount = 11.00m,
                PaymentVaultToken = new PaymentVaultToken
                {
                    CustomerId = customerId,
                    PaymentMethodId = paymentMethodId,
                    PaymentType = "CREDIT_CARD"
                },
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<ChargeResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
        }
        public void SecureNet_Vault_Store_Account_After_Charge_Request_Returns_Successfully()
        {
            // Arrange
            var request = new ChargeRequest
            {
                Amount = 11.00m,
                AddToVault = true,
                Card = new Card
                {
                    Number = "4444 3333 2222 1111",
                    ExpirationDate = "04/2016",
                    Address = new Address
                    {
                        Line1 = "123 Main St.",
                        City = "Austin",
                        State = "TX",
                        Zip = "78759"
                    }
                },
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<ChargeResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
        }
        public void SecureNet_Vault_Create_Customer_And_Payment_Account_Request_Returns_Successfully()
        {
            // Arrange
            var request = new VaultCustomerAndPaymentMethodRequest
            {
                FirstName = "Jack",
                LastName = "Test",
                PhoneNumber = "512-250-7865",
                Address = new Address
                {
                    Line1 = "123 Main St.",
                    City = "Austin",
                    State = "TX",
                    Zip = "78759",
                    Country = "US"
                },
                EmailAddress = "*****@*****.**",
                SendEmailReceipts = true,
                Company = "Test company",
                Notes = "This is test notes",
                UserDefinedFields = new List<UserDefinedField>
                {
                    new UserDefinedField
                    {
                        UdfName = "Udf1",
                        UdfValue = "Udf1_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf2",
                        UdfValue = "Udf2_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf3",
                        UdfValue = "Udf3_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf4",
                        UdfValue = "Udf4_Value"
                    },
                    new UserDefinedField
                    {
                        UdfName = "Udf5",
                        UdfValue = "Udf5_Value"
                    }
                },
                CustomerDuplicateCheckIndicator = 1,
                Card = new Card
                {
                    Number = "4444 3333 2222 1111",
                    ExpirationDate = "04/2016",
                    FirstName = "Jack",
                    LastName = "Test",
                    Address = new Address
                    {
                        Line1 = "123 Main St.",
                        City = "Austin",
                        State = "TX",
                        Zip = "78749",
                        Country = "US"
                    }
                },
                Phone = "512-250-7865",
                Primary = true,
                AccountDuplicateCheckIndicator = 1,
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<VaultCustomerAndPaymentMethodResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
        }
        /// <summary>
        /// Successful response returned from an Delete Payment Account request.
        /// https://apidocs.securenet.com/docs/vault.html?lang=csharp#removeaccount
        /// </summary>
        public void SecureNet_Vault_Delete_Payment_Account_Request_Returns_Successfully(string customerId, string paymentMethodId)
        {
            // Arrange
            var request = new RemovePaymentMethodRequest
            {
                CustomerId = customerId,
                PaymentMethodId = paymentMethodId,
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<RemovePaymentMethodResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
        }
        /// <summary>
        /// Successful response returned from an Update Installment Plan request.
        /// https://apidocs.securenet.com/docs/recurringbilling.html?lang=csharp#updateinstallment
        /// </summary>
        public void Recurring_Billing_Update_Installment_Plan_Request_Returns_Successfully(string customerId, string planId)
        {
            // Arrange
            var request = new UpdateInstallmentPaymentPlanRequest
            {
                CustomerId = customerId,
                PlanId = planId,
                Plan = new InstallmentPaymentPlan
                {
                    CycleType = "monthly",
                    DayOfTheMonth = 1,
                    DayOfTheWeek = 1,
                    Frequency = 1,
                    NumberOfPayments = 15,
                    InstallmentAmount = 300.95m,
                    RemainderAmount = 17.90m,
                    BalloonPaymentAddedTo = "FIRST",
                    RemainderAmountAddedTo = "LAST",
                    StartDate = Convert.ToDateTime("11/01/2014"),
                    EndDate = Convert.ToDateTime("10/01/2020"),
                    MaxRetries = 4,
                    Notes = "This is an updated installment plan",
                    Active = true
                },
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<UpdateInstallmentPaymentPlanResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
        }
        public string Recurring_Billing_Create_Variable_Payment_Plan_Request_Returns_Successfully(string customerId, string paymentMethodId)
        {
            // Arrange
            var request = new AddVariablePaymentPlanRequest
            {
                CustomerId = customerId,
                Plan = new VariablePaymentPlan
                {
                    PlanStartDate = Convert.ToDateTime("10/01/2014"),
                    PlanEndDate = Convert.ToDateTime("01/01/2020"),
                    PrimaryPaymentMethodId = paymentMethodId,
                    ScheduledPayments = new List<StoredScheduledVariablePaymentPlan>
                    {
                        new StoredScheduledVariablePaymentPlan
                        {
                            Amount = 132.89m,
                            PaymentDate = Convert.ToDateTime("10/1/2014"),
                        }

                    },
                    MaxRetries = 4,
                    Notes = "This is a variable payment plan",
                    UserDefinedFields = new List<UserDefinedField>
                    {
                        new UserDefinedField
                        {
                            UdfName = "Udf1",
                            UdfValue = "Udf1_Value"
                        },
                        new UserDefinedField
                        {
                            UdfName = "Udf2",
                            UdfValue = "Udf2_Value"
                        },
                        new UserDefinedField
                        {
                            UdfName = "Udf3",
                            UdfValue = "Udf3_Value"
                        },
                        new UserDefinedField
                        {
                            UdfName = "Udf4",
                            UdfValue = "Udf4_Value"
                        },
                        new UserDefinedField
                        {
                            UdfName = "Udf5",
                            UdfValue = "Udf5_Value"
                        }
                    },

                },
                DeveloperApplication = new DeveloperApplication
                {
                    DeveloperId = 12345678,
                    Version = "1.2"
                }
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<AddVariablePaymentPlanResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
            Assert.IsNotNull(response.PlanId);

            return response.PlanId;
        }
 public void Setup()
 {
     _customerController =
         ControllerHelper.GetInitialisedCustomersController(_mockCustomerService.Object);
     AutoMapperConfig.Bootstrap();
 }
        /// <summary>
        /// Successful response returned from a Retrieve Payment Plan request.
        /// https://apidocs.securenet.com/docs/recurringbilling.html?lang=csharp#retrieve
        /// </summary>
        public void Recurring_Billing_Retrieve_Payment_Plan_Request_Returns_Successfully(string customerId, string planId)
        {
            // Arrange
            var request = new RetrievePaymentPlanRequst
            {
                CustomerId = customerId,
                PlanId = planId
            };

            var apiContext = new APIContext();
            var controller = new CustomersController();

            // Act
            var response = controller.ProcessRequest<RetrievePaymentPlanResponse>(apiContext, request);

            // Assert
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success);
        }