public ActionResult MonthlySubscription() { try { // Set your secret key: remember to change this to your live secret key in production // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.SetApiKey("sk_test_22k4YCpi8ZXIPNrbXknO9FBJ"); var items = new List <SubscriptionItemOption> { new SubscriptionItemOption { PlanId = "plan_ECiANlC1f0LmJ4" } }; var options = new SubscriptionCreateOptions { CustomerId = "cus_ECiBuW7SSWWOOD", Items = items, }; var service = new SubscriptionService(); Subscription subscription = service.Create(options); } catch (Exception e) { //do something with the exception here throw; } return(View("Success")); }
private Subscription GetOrCreateSubscription( SubscriptionService subscriptionService, Customer customer, string plan, string paymentMethodId) { var subscription = subscriptionService.List( new SubscriptionListOptions { Customer = customer.Id, Plan = plan }).FirstOrDefault(); if (subscription != default(Subscription)) { return(subscription); } subscription = subscriptionService.Create(new SubscriptionCreateOptions { Customer = customer.Id, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Plan = plan, Quantity = 1 } }, DefaultPaymentMethod = paymentMethodId }); return(subscription); }
private IPaymentHandlerSubscriptionDTO CreateSubscription(string customerId, string priceId) { var subscriptionOptions = new SubscriptionCreateOptions { Customer = customerId, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Price = priceId, }, }, }; subscriptionOptions.AddExpand("latest_invoice.payment_intent"); var subscription = _subscriptionService.Create(subscriptionOptions); var id = subscription.Id; var status = subscription.Status; var latestInvoicePaymentIntentStatus = subscription.LatestInvoice.PaymentIntent.Status; var latestInvoicePaymentIntentClientSecret = subscription.LatestInvoice.PaymentIntent.ClientSecret; var subscriptionDTO = new StripePaymentHandlerSubscriptionDTO(id, status, latestInvoicePaymentIntentStatus, latestInvoicePaymentIntentClientSecret); return(subscriptionDTO); }
public async Task CreateSubscription(string days) { var testPlan = TEST_PLAN; if (days == "Two") { testPlan = TEST_PLAN2; } if (days == "Two") { testPlan = TEST_PLAN3; } StripeConfiguration.ApiKey = _stripeOptions.SecretKey; var options = new SubscriptionCreateOptions { Customer = TEST_CUSTOMER, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Plan = testPlan, }, }, }; var service = new SubscriptionService(); Subscription subscription = service.Create(options); }
public IActionResult AddCustomer(string email, string name) { StripeConfiguration.ApiKey = API_KEY; var options = new CustomerCreateOptions { Email = email, Name = name, }; var service = new CustomerService(); Customer customer = service.Create(options); var subOptions = new SubscriptionCreateOptions { Customer = customer.Id, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Price = "price_1IFcjaHVInnZqCxxolFGevVP", }, }, }; var subService = new SubscriptionService(); subService.Create(subOptions); return(Ok()); }
public Subscription Subscribe(string email, string name, string source, string monthlyPlanId, string overagePlanId) { var customerService = new CustomerService(); var customer = customerService.Create(new CustomerCreateOptions { Email = email, Description = name, Source = source }); var subscriptionService = new SubscriptionService(); var items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Plan = monthlyPlanId }, new SubscriptionItemOptions { Plan = overagePlanId } }; var subscription = subscriptionService.Create(new SubscriptionCreateOptions { Customer = customer.Id, Items = items, }); return(subscription); }
public void CreateSubscription([FromRoute] int planNumber) { StripeConfiguration.ApiKey = "sk_test_51GxEfiHhYK7K9XttqUpv12yjajZLs01TY95VhvzVfPEb5Ed8GaF3GFUV2iuhFZGkBgHoNib4iHBDlpALqWPplth6008EdMnnaw"; string plan = ""; if (planNumber == 1) { plan = "price_1GxFdVHhYK7K9Xttie9i0RqL"; } else if (planNumber == 2) { plan = "price_1GxEu5HhYK7K9XttdYlMhRBn"; } var options = new SubscriptionCreateOptions { Customer = "cus_HWIVyLfT0yhlOg", Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Price = plan, }, }, }; var service = new SubscriptionService(); Subscription subscription = service.Create(options); }
public void When_subsctiption_created_scheduler_should_be_called() { // act var service = new SubscriptionService(serviceContext, scheduler, settings); var subs = service.Create(new CreateSubscriptionModel(), default); // assert subs.Id.Should().NotBe(default);
public ActionResult <Subscription> CreateSubscription([FromBody] CreateSubscriptionRequest req) { // Attach payment method PaymentMethod paymentMethod; try { var options = new PaymentMethodAttachOptions { Customer = req.Customer, }; var service = new PaymentMethodService(); paymentMethod = service.Attach(req.PaymentMethod, options); } catch (StripeException e) { return(Ok(new { error = new { message = e.Message } })); } // Update customer's default invoice payment method var customerOptions = new CustomerUpdateOptions { InvoiceSettings = new CustomerInvoiceSettingsOptions { DefaultPaymentMethod = paymentMethod.Id, }, }; var customerService = new CustomerService(); customerService.Update(req.Customer, customerOptions); // Create subscription var subscriptionOptions = new SubscriptionCreateOptions { Customer = req.Customer, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Price = Environment.GetEnvironmentVariable(req.Price), }, }, }; subscriptionOptions.AddExpand("latest_invoice.payment_intent"); var subscriptionService = new SubscriptionService(); try { Subscription subscription = subscriptionService.Create(subscriptionOptions); return(subscription); } catch (StripeException e) { Console.WriteLine($"Failed to create subscription.{e}"); return(BadRequest()); } }
public void CreateSubscription(int UsernameId, int CategoryId) { Subscription subscription = new Subscription() { UsernameId = UsernameId, CategoryId = CategoryId }; subscriptionService.Create(subscription); }
public string SignUserUpToSubscription(string paymentMethodId, User user, ClubSubscription clubSubscription) { var options = new PaymentMethodAttachOptions { Customer = user.StripeUserId, }; var service = new PaymentMethodService(); var paymentMethod = service.Attach(paymentMethodId, options); // Update customer's default invoice payment method var customerOptions = new CustomerUpdateOptions { InvoiceSettings = new CustomerInvoiceSettingsOptions { DefaultPaymentMethod = paymentMethod.Id, }, }; var customerService = new CustomerService(); customerService.Update(user.StripeUserId, customerOptions); // Create subscription var subscriptionOptions = new SubscriptionCreateOptions { Customer = user.StripeUserId, Items = new List <SubscriptionItemOptions>() { new SubscriptionItemOptions { Price = clubSubscription.StripePriceId, }, }, Metadata = new Dictionary <string, string>() { { "UserId", user.UserId.ToString() }, { "ClubSubscriptionId", clubSubscription.ClubSubscriptionId.ToString() }, } }; subscriptionOptions.AddExpand("latest_invoice.payment_intent"); var subscriptionService = new SubscriptionService(); try { Subscription subscription = subscriptionService.Create(subscriptionOptions); return("Went good"); } catch (StripeException e) { Console.WriteLine($"Failed to create subscription.{e}"); return("Went bad"); // return BadRequest(); } }
public SubscriptionResult Create(User user, string email, string paymentToken, string planId) { var paymentMethodCreate = new PaymentMethodCreateOptions { Card = new PaymentMethodCardCreateOptions { Token = paymentToken }, Type = "card" }; var pmService = new PaymentMethodService(); var paymentMethod = pmService.Create(paymentMethodCreate); Console.WriteLine("Payment method: " + paymentMethod.Id); var custOptions = new CustomerCreateOptions { Email = email, PaymentMethod = paymentMethod.Id, InvoiceSettings = new CustomerInvoiceSettingsOptions { DefaultPaymentMethod = paymentMethod.Id, }, Metadata = new Dictionary <string, string> { { "userid", user.Id.ToString() } } }; var custService = new CustomerService(); var customer = custService.Create(custOptions); Console.WriteLine("Customer: " + customer.Id); var items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Plan = planId, } }; var subscriptionOptions = new SubscriptionCreateOptions { Customer = customer.Id, Items = items, TrialPeriodDays = 7 }; subscriptionOptions.AddExpand("latest_invoice.payment_intent"); var subService = new SubscriptionService(); var subscription = subService.Create(subscriptionOptions); Console.WriteLine("Subscription: " + subscription.Id); return(new SubscriptionResult( customerId: customer.Id, subscriptionId: subscription.Id)); }
public ActionResult <SubscriptionResponse> CreateSubscription([FromBody] CreateSubscriptionRequest req) { var customerId = HttpContext.Request.Cookies["customer"]; // Attach payment method PaymentMethod paymentMethod; try { var options = new PaymentMethodAttachOptions { Customer = customerId, }; var service = new PaymentMethodService(); paymentMethod = service.Attach(req.PaymentMethod, options); } catch (StripeException e) { return(BadRequest(new { error = new { message = e.Message } })); } // Create subscription var subscriptionOptions = new SubscriptionCreateOptions { DefaultPaymentMethod = paymentMethod.Id, Customer = customerId, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Price = Environment.GetEnvironmentVariable(req.Price.ToUpper()), }, }, }; subscriptionOptions.AddExpand("latest_invoice.payment_intent"); var subscriptionService = new SubscriptionService(); try { Subscription subscription = subscriptionService.Create(subscriptionOptions); return(new SubscriptionResponse { Subscription = subscription }); } catch (StripeException e) { Console.WriteLine($"Failed to create subscription.{e}"); return(BadRequest()); } }
public async Task <IActionResult> CreateSubscription([FromBody] CreateSubscription sub) { var option = new PaymentMethodAttachOptions { Customer = sub.Customer, }; var service = new PaymentMethodService(); var paymentMethod = service.Attach(sub.PaymentMethod, option); // Update customer's default invoice payment method var customerOptions = new CustomerUpdateOptions { InvoiceSettings = new CustomerInvoiceSettingsOptions { DefaultPaymentMethod = paymentMethod.Id, }, }; var customerService = new CustomerService(); await customerService.UpdateAsync(sub.Customer, customerOptions); var subscriptionOptions = new SubscriptionCreateOptions { Customer = sub.Customer, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Price = Environment.GetEnvironmentVariable(sub.Price), } }, }; subscriptionOptions.AddExpand("latest_invoice.payment_intent"); var subscriptionService = new SubscriptionService(); try { Subscription subscription = subscriptionService.Create(subscriptionOptions); return(Ok(new ResponseViewModel <Subscription> { Data = subscription, Message = StripeConstants.SubscriptionAdded })); } catch (StripeException e) { Console.WriteLine($"Failed to create subscription.{e}"); return(BadRequest()); } }
public ActionResult Create(MyServices model) { if (model.Id == 0) // { Service requestedService = this._serviceRepo.GetServiceById(model.ServiceId); model.MemberId = this._userTable.GetmemberId(User.Identity.Name); model.Status = "InActive"; // InActive untill payment not done. model.IsPaid = false; model.PaymentConfirmed = false; if (requestedService.ServiceType.ToUpper() == "MONTHLY") { model.ValidDate = model.StartDate.AddMonths(1); int memberServiceId = this._mySubscriptionRepo.AddService(model); var items = new List <SubscriptionItemOption> { new SubscriptionItemOption { PlanId = requestedService.StripePlanName } }; var options = new SubscriptionCreateOptions { CustomerId = model.StripeCustomerId,// "cus_ExQd0tzJcBzqlw", Items = items, Metadata = new Dictionary <string, string>() { { "MemberServiceId", memberServiceId.ToString() }, { "PaymentUrl", "/Payment/Index?myserviceid=" + memberServiceId.ToString() }, } }; var service = new SubscriptionService(); Subscription subscription = service.Create(options); this._mySubscriptionRepo.UpdateSubscriptionStatus(memberServiceId, model.StripeCustomerId, subscription.Id); return(RedirectToAction("Index", "Subscriptions")); } else { model.ValidDate = model.StartDate.AddYears(50); // no need but value cannot be null so. int memberServiceId = this._mySubscriptionRepo.AddService(model); return(RedirectToAction("Index", "Payment", new { myserviceid = memberServiceId })); } } else { } var serviceList = this._serviceRepo.GetServiceList(); ViewBag.ServiceList = new SelectList(serviceList, "Id", "Name", model.ServiceId); return(View(model)); }
public IActionResult Subscribe(string cardEmail, string plan, string stripeToken) { var customerOptions = new CustomerCreateOptions { Email = cardEmail, Source = stripeToken, }; var customerService = new CustomerService(); var customer = customerService.Create(customerOptions); Models.Customer custToDb = new Models.Customer(); custToDb.CustomerID = customer.Id; custToDb.CustomerEmail = cardEmail; _database.Customers.Add(custToDb); _database.SaveChanges(); var planId = _configuration["Stripe:Daily5"]; if (plan == "Daily10") { planId = _configuration["Stripe:Daily10"]; } var subscriptionOptions = new SubscriptionCreateOptions { Customer = customer.Id, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Plan = planId }, }, }; subscriptionOptions.AddExpand("latest_invoice.payment_intent"); var subscriptionService = new SubscriptionService(); var subscription = subscriptionService.Create(subscriptionOptions); Models.Subscription subs = new Models.Subscription(); subs.SubID = subscription.Id; subs.CustomerID = customer.Id; subs.PlanID = planId; _database.Subscriptions.Add(subs); _database.SaveChanges(); ViewBag.stripeKey = _configuration["Stripe:PublishableKey"]; ViewBag.subscription = subscription.ToJson(); return(View("SubscribeResult")); }
public ActionResult Billing(BillingViewModel billingViewModel) { billingViewModel.Plan = PlanService.Find(billingViewModel.Plan.Id); try { SubscriptionService.Create(User.Identity.Name, billingViewModel.Plan, billingViewModel.StripeToken); } catch (StripeException stripeException) { ModelState.AddModelError(string.Empty, stripeException.Message); return(View(billingViewModel)); } return(RedirectToAction("Index", "Dashboard")); }
public IActionResult Subscribe(string email, string plan, string stripeToken) { StripeConfiguration.ApiKey = "sk_test_51Gzaa1HAh8lBnQxza9cOAzY7LbfgQ4FWX2sYqiuHsoVWJg4mNDppueQkAVd0XIPU4GhcrNBca8aemNgr24m4jDv200ooFw0Bhz"; var customerOptions = new CustomerCreateOptions { Email = email, Source = stripeToken, }; var customerService = new CustomerService(); var customer = customerService.Create(customerOptions); var planId = ""; if (plan == "Basic Plan") { planId = "price_1GzePPHAh8lBnQxzEOztVJZo"; } else if (plan == "Standard Plan") { planId = "price_1GzeOyHAh8lBnQxz1uv2YPwm"; } else if (plan == "Premium Plan") { planId = "price_1GzePbHAh8lBnQxzC9f5F9oh"; } var subscriptionOptions = new SubscriptionCreateOptions { Customer = customer.Id, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Plan = planId }, }, }; subscriptionOptions.AddExpand("latest_invoice.payment_intent"); var subscriptionService = new SubscriptionService(); var subscription = subscriptionService.Create(subscriptionOptions); ViewBag.stripeKey = _configuration["Stripe:pk_test_51Gzaa1HAh8lBnQxzdxo2zIn3mzr0lkJiQcsQowOZSd1S85Sou79t2Ub8OwI1lkGcAcgHYxJeB3wIhmFimN9DdKnD00BesCjDg3"]; ViewBag.subscription = subscription.ToJson(); return(View("SubscribeResult")); }
public Subscription Create(string customerId, string planId, SubscriptionCreateOptions createOptions = null) { if (createOptions == null) { createOptions = new SubscriptionCreateOptions(); } createOptions.Customer = customerId; createOptions.Items = new List <SubscriptionItemOption>(); createOptions.Items.Add(new SubscriptionItemOption { Plan = planId, Quantity = 1 }); return(_stripeSubscriptionService.Create(createOptions)); }
//public Subscription CreateSubscription([FromBody] CreateSubscriptionRequest req) public Subscription CreateSubscription(Customer customer, string price) { //// Attach payment method //var options = new PaymentMethodAttachOptions //{ // Customer = req.Customer, //}; //var service = new PaymentMethodService(); //var paymentMethod = service.Attach(req.PaymentMethod, options); //// Update customer's default invoice payment method //var customerOptions = new CustomerUpdateOptions //{ // InvoiceSettings = new CustomerInvoiceSettingsOptions // { // DefaultPaymentMethod = paymentMethod.Id, // }, //}; //var customerService = new CustomerService(); //customerService.Update(req.Customer, customerOptions); // Create subscription var subscriptionOptions = new SubscriptionCreateOptions { Customer = customer.Id, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Price = Environment.GetEnvironmentVariable(price), }, }, }; subscriptionOptions.AddExpand("latest_invoice.payment_intent"); var subscriptionService = new SubscriptionService(); try { Subscription subscription = subscriptionService.Create(subscriptionOptions); return(subscription); } catch (StripeException e) { Console.WriteLine($"Failed to create subscription.{e}"); return(null); } }
public Subscription CreateSubscription(string PlanId, string CustomerId) { var subService = new SubscriptionService(); return(subService.Create(new SubscriptionCreateOptions() { Items = new List <SubscriptionItemOption>() { new SubscriptionItemOption() { PlanId = PlanId } }, CustomerId = CustomerId })); }
public ActionResult Subscribe(int id) { var user = _database.Users.Where(u => u.Id == id).FirstOrDefault(); try { // Use Stripe's library to make request StripeConfiguration.ApiKey = key; StripeConfiguration.MaxNetworkRetries = 2; var options = new SubscriptionCreateOptions { Customer = customerId, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Price = productPrice1, }, }, }; var service = new SubscriptionService(); Subscription subscription = service.Create(options); var model = new SubscriptionViewModel(); model.SubscriptionId = subscription.Id; user.CustomerId = subscription.CustomerId; user.RoleId = 2; _putItem.AddNewEntry(subscription.Id, subscription.LatestInvoiceId, user.Id); _database.Users.Update(user); _database.SaveChanges(); return(View("OrderStatus")); } catch (StripeException e) { var x = new { status = "Failed", message = e.Message }; return(this.Json(x)); } }
public async void Create() { var mock = new ServiceMockFacade <ISubscriptionRepository>(); var model = new ApiSubscriptionRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Subscription>())).Returns(Task.FromResult(new Subscription())); var service = new SubscriptionService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SubscriptionModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLSubscriptionMapperMock, mock.DALMapperMockFactory.DALSubscriptionMapperMock); CreateResponse <ApiSubscriptionResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.SubscriptionModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSubscriptionRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Subscription>())); }
public static Subscription CreateSubscription(CreateSubscriptionRequest request) { List <SubscriptionItemOption> items = new List <SubscriptionItemOption> { new SubscriptionItemOption { Plan = request.PlanId } }; SubscriptionCreateOptions options = new SubscriptionCreateOptions { Customer = request.StripeCustomerId, Items = items }; options.AddExpand("latest_invoice.payment_intent"); SubscriptionService service = new SubscriptionService(); return(service.Create(options)); }
public void Subscribe(StripeChargeRequest req, int userId) { // do a data provider call for AppUser GetById // that will give you the email address var plan = GetById(req.TenantId, req.SubscriptionLevel); var customers = new Stripe.CustomerService(); var customer = customers.Create(new CustomerCreateOptions { SourceToken = req.StripeToken, Email = req.Email, }); var items = new List <SubscriptionItemOption> { new SubscriptionItemOption { PlanId = plan.StripePlanId } }; var options = new SubscriptionCreateOptions { Items = items, CustomerId = customer.Id }; var service = new SubscriptionService(); Subscription subscription = service.Create(options); dataProvider.ExecuteNonQuery( "Subscriptions_Insert", (parameters) => { parameters.AddWithValue("@TenantId", req.TenantId); parameters.AddWithValue("@BusinessId", req.BusinessId); parameters.AddWithValue("@SubscriptionLevel", req.SubscriptionLevel); parameters.AddWithValue("@StripeToken", req.StripeToken); parameters.AddWithValue("@StripeCustomerId", subscription.CustomerId); parameters.AddWithValue("@StripeSubscriptionId", subscription.Id); parameters.AddWithValue("@StartDate", subscription.CurrentPeriodStart); parameters.AddWithValue("@EndDate", subscription.CurrentPeriodEnd); parameters.Add("@Id", SqlDbType.Int).Direction = ParameterDirection.Output; } ); }
private Subscription MonthlySubscription(string apiKey, string planId, string customerId) { // Set your secret key: remember to change this to your live secret key in production // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.SetApiKey(apiKey); var items = new List <SubscriptionItemOption> { new SubscriptionItemOption { PlanId = planId } }; var options = new SubscriptionCreateOptions { CustomerId = customerId, Items = items, }; var service = new SubscriptionService(); return(service.Create(options)); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <ISubscriptionService, ISubscriptionRepository>(); var model = new ApiSubscriptionServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Subscription>())).Returns(Task.FromResult(new Subscription())); var service = new SubscriptionService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.SubscriptionModelValidatorMock.Object, mock.DALMapperMockFactory.DALSubscriptionMapperMock); CreateResponse <ApiSubscriptionServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.SubscriptionModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSubscriptionServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Subscription>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SubscriptionCreatedNotification>(), It.IsAny <CancellationToken>())); }
public ActionResult Index(stripeModel model) { var customers = new CustomerService(); var customer = customers.Create(new CustomerCreateOptions { Email = model.StripeEmail, Source = model.StripeToken, Name = model.fullName, }); var subscriptionOptions = new SubscriptionCreateOptions() { PlanId = model.PlanId, CustomerId = customer.Id, TrialFromPlan = false, Expand = new List <string> { "latest_invoice.payment_intent", "pending_setup_intent" }, }; var subscriptionService = new SubscriptionService(); Subscription subscription = subscriptionService.Create(subscriptionOptions); if (subscription.LatestInvoice.PaymentIntent.NextAction != null) { if (subscription.LatestInvoice.PaymentIntent.Status == "requires_action") { model.IntentSecretis = subscription.LatestInvoice.PaymentIntent.ClientSecret; } } else { return(RedirectToAction("Index", "Home")); } return(View(model)); }
public dynamic Sheduldeplan(Common model) { StripeConfiguration.ApiKey = APIKey; dynamic d = Create(model); model.cusid = "cus_GXQijo0EPiMTkd"; var options = new SubscriptionCreateOptions { Customer = model.cusid, Items = new List <SubscriptionItemOptions> { new SubscriptionItemOptions { Plan = model.palnid, }, }, }; var service = new SubscriptionService(); return(service.Create(options)); }
public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <ISubscriptionService, ISubscriptionRepository>(); var model = new ApiSubscriptionServerRequestModel(); var validatorMock = new Mock <IApiSubscriptionServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiSubscriptionServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new SubscriptionService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALSubscriptionMapperMock); CreateResponse <ApiSubscriptionServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSubscriptionServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SubscriptionCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }