public void When_GetSubscriptionIsCalled_AndSubscriptionIsPresent_Then_SubscriptionIsReturned()
        {
            var repository = new SubscriptionRepository();

            var subscription1 = new SubscriptionDataModel
            {
                Username    = "******",
                AccessToken = "testtoken",
                TotalNotificationsPushed = 0,
            };

            repository.Add(subscription1);

            var subscription2 = new SubscriptionDataModel
            {
                Username    = "******",
                AccessToken = "newtoken",
                TotalNotificationsPushed = 0,
            };

            repository.Add(subscription2);

            var result = repository.GetSubscription("bbc");

            // Assert
            Assert.AreEqual(subscription1.Username, result.Username);
            Assert.AreEqual(subscription1.AccessToken, result.AccessToken);
        }
        public void When_GetSubscriptionIsCalled_AndSubscriptionIsNotPresent_Then_SubscriptionListIsEmpty()
        {
            var repository = new SubscriptionRepository();

            var subscription1 = new SubscriptionDataModel
            {
                Username    = "******",
                AccessToken = "testtoken",
                TotalNotificationsPushed = 0,
            };

            repository.Add(subscription1);

            var subscription2 = new SubscriptionDataModel
            {
                Username    = "******",
                AccessToken = "newtoken",
                TotalNotificationsPushed = 0,
            };

            repository.Add(subscription2);

            var result = repository.GetSubscription("bbc1");

            // Assert
            Assert.IsNull(result);
        }
        public void When_UpdateIsCalled_AndSubscriptionIsNotPresent_Then_FalseIsReturned()
        {
            var repository = new SubscriptionRepository();

            var subscription1 = new SubscriptionDataModel
            {
                Username    = "******",
                AccessToken = "testtoken",
                TotalNotificationsPushed = 0,
            };

            repository.Add(subscription1);

            var subscription2 = new SubscriptionDataModel
            {
                Username    = "******",
                AccessToken = "newtoken",
                TotalNotificationsPushed = 0,
            };

            repository.Add(subscription2);

            var result = repository.Update(new SubscriptionDataModel {
                AccessToken = "newToken", Username = "******"
            });

            // Assert
            Assert.IsFalse(result);
        }
Пример #4
0
        public void SaveSubscriptionWithStudentDeclaration()
        {
            //取未征订学生申报
            var studentDeclarations = _appl.GetNotSubscriptionStudentDeclarationJiaoWu("2013-2014-2");
            var teacherDeclarations = _appl.GetNotSubscriptionTeacherDeclarationJiaoWu("2013-2014-2");
            //生成订单
            var subscriptions = SubscriptionService.CreateSubscriptionsByPress(studentDeclarations, teacherDeclarations);
            //保存
            var repo = new SubscriptionRepository(_context);

            for (int i = 0; i < subscriptions.Count(); i = i + 300)
            {
                foreach (var item in subscriptions.Skip(i).Take(300))
                {
                    repo.Add(item);
                }
                repo.Context.Commit();
            }

            var ids    = subscriptions.Select(d => d.ID);
            var result = repo.Find(t => ids
                                   .Contains(t.ID)
                                   );

            Assert.AreEqual(subscriptions.Count(), result.Count());
        }
Пример #5
0
        public void Send(AddPeerSubscription message)
        {
            if (_ids.ContainsKey(message.SubscriptionId))
            {
                return;
            }

            _ids.Add(message.SubscriptionId, message);

            _repository.Add(message.PeerId, _peerUri, message.SubscriptionId, message.EndpointUri, message.MessageName,
                            message.CorrelationId);

            if (_ids.Count > 1)
            {
                return;
            }

            _subscriptionId = NewId.NextGuid();
            _endpointUri    = message.EndpointUri;

            var add = new SubscriptionAddedMessage
            {
                SubscriptionId = _subscriptionId,
                EndpointUri    = _endpointUri,
                MessageName    = _messageName,
                CorrelationId  = _correlationId,
            };

            _log.DebugFormat("PeerSubscriptionAdded: {0}, {1} {2}", _messageName, _endpointUri, _subscriptionId);

            _observer.OnSubscriptionAdded(add);
        }
        public void When_AddIsCalled_AndSubscriptionIsNull_Then_SubscriptionIsNotAddedAndNullIsReturned()
        {
            SubscriptionDataModel subscription = null;

            var repository = new SubscriptionRepository();
            var result     = repository.Add(subscription);

            // Assert
            Assert.IsNull(result);
        }
Пример #7
0
        public async Task AddUserSubscription_ShouldReturnTrue_ForValidUserId()
        {
            // arrange
            var userId = 1;

            // act
            var isAdded = await _subscriptionRepository.Add(userId);

            // assert
            Assert.True(isAdded);
        }
        public IActionResult Post(Subscription subscription)
        {
            var currentUser = GetCurrentUserProfile();

            subscription.SubscriberUserProfileId = currentUser.Id;

            subscription.BeginDateTime = DateTime.Now;

            _subscriptionRepository.Add(subscription);

            return(CreatedAtAction("Get", new { id = subscription.Id }, subscription));
        }
Пример #9
0
        public IActionResult Post(Subscription subscription)
        {
            var CurrentUserId   = GetCurrentUserProfile().Id;
            var CurrentUserSubs = _subscriptionRepository.GetByUserProfileId(CurrentUserId);

            if (CurrentUserSubs.Exists(s => s.ProviderUserProfileId == subscription.ProviderUserProfileId))
            {
                return(Unauthorized());
            }
            _subscriptionRepository.Add(subscription);
            return(CreatedAtAction("Get", new { id = subscription.Id }, subscription));
        }
        public void When_AddIsCalled_AndSubscriptionIsAlreadyAdded_Then_DuplicateSubscriptionExceptionIsThrown()
        {
            var subscription = new SubscriptionDataModel
            {
                Username    = "******",
                AccessToken = "testtoken",
                TotalNotificationsPushed = 1,
            };

            var repository = new SubscriptionRepository();
            var result     = repository.Add(subscription);

            try
            {
                result = repository.Add(subscription);
            }
            catch (Exception ex)
            {
                // Assert
                Assert.IsTrue(ex is DuplicateSubscriptionException);
            }
        }
        public void When_AddIsCalled_Then_SubscriptionIsAdded()
        {
            var subscription = new SubscriptionDataModel
            {
                Username    = "******",
                AccessToken = "testtoken",
                TotalNotificationsPushed = 1,
            };

            var repository = new SubscriptionRepository();
            var result     = repository.Add(subscription);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(0, subscription.TotalNotificationsPushed);
            Assert.AreEqual(DateTime.Now.ToString("dd MM yyyy"), subscription.CreationTime.ToString("dd MM yyyy"));
        }
 public ActionResult Index(int id, SubscribeViewModel vm)
 {
     try
     {
         int          currentUserId = GetCurrentUserProfileId();
         Subscription sub           = new Subscription()
         {
             SubscriberUserProfileId = currentUserId,
             ProviderUserProfileId   = vm.ProviderUserId
         };
         _subRepo.Add(sub);
         return(RedirectToAction("Details", "Post", new { id = vm.PostId }));
     }
     catch
     {
         return(View(vm));
     }
 }
        public void SaveSubscriptionWithStudentDeclaration()
        {
            //取未征订学生申报
            var studentDeclarations = _appl.GetNotSubscriptionStudentDeclarationJiaoWu("2013-2014-2");
            var teacherDeclarations = _appl.GetNotSubscriptionTeacherDeclarationJiaoWu("2013-2014-2");
            //生成订单
            var subscriptions = SubscriptionService.CreateSubscriptionsByPress(studentDeclarations, teacherDeclarations);
            //保存
            var repo = new SubscriptionRepository(_context);
            for (int i = 0; i < subscriptions.Count(); i = i + 300)
            {
                foreach (var item in subscriptions.Skip(i).Take(300))
                {
                    repo.Add(item);
                }
                repo.Context.Commit();
            }

            var ids = subscriptions.Select(d => d.ID);
            var result = repo.Find(t => ids
                .Contains(t.ID)
                );
            Assert.AreEqual(subscriptions.Count(), result.Count());
        }
        protected void SaveSubscriptionClick(object sender, EventArgs e)
        {
            var subscriptions = new Subscriptions();
            var isNew         = true;

            if (Request.Params["id"] != "0")
            {
                isNew           = false;
                subscriptions   = _subscriptions;
                _subscriptionId = _subscriptions.Id;
            }
            else
            {
                subscriptions.IsActive = true;
            }

            int productType = int.Parse(SubscriptionTypeDdl.SelectedValue);

            subscriptions.SubscriptionType = productType;
            subscriptions.Name             = SubscriptionNameText.Text.Trim();
            subscriptions.MaxGuest         = Int16.Parse(HidMaxGuest.Value);
            double price;

            double.TryParse(PriceText.Text, out price);
            subscriptions.Price = price;
            int maxPurchase;

            int.TryParse(MaxPurchaseText.Text, out maxPurchase);
            subscriptions.ProductHighlight = ProductHighlightText.Text;
            subscriptions.WhatYouGet       = WhatYouGetEditor.Text;
            subscriptions.MaxPurchases     = maxPurchase;

            // SEO Tab 2
            subscriptions.MetaDescription = MetaDescription.Text;
            subscriptions.MetaKeyword     = MetaKeyword.Text;

            // Photos on tab 3
            if (isNew)
            {
                switch (int.Parse(SubscriptionTypeDdl.SelectedValue))
                {
                case (int)Enums.SubscriptionType.Subscription:
                    string planId = SubscriptionNameText.Text.Trim().Replace(" ", "-").ToLower();
                    try
                    {
                        // Create Plans On Stripe
                        var planOptions = new StripePlanCreateOptions
                        {
                            Id       = planId,
                            Name     = SubscriptionNameText.Text.Trim(),
                            Amount   = Convert.ToInt32(price * 100),
                            Currency = "usd",
                            Interval = "month"
                        };
                        CreateStripePlan(planOptions);
                    }
                    catch (Exception ex)
                    {
                        ErrorMessageLabel.Visible = true;
                        ErrorMessageLabel.Text    = ex.Message + " - " + planId;
                        return;
                    }
                    subscriptions.StripePlanId      = planId;
                    subscriptions.StripePlanCreated = DateTime.UtcNow;
                    break;

                case (int)Enums.SubscriptionType.GiftCard:
                    break;
                }
                _subscriptionId = _subscriptionRepository.Add(subscriptions);
            }
            else
            {
                var photos = new List <SubscriptionImages>();
                foreach (ListViewDataItem item in SubscriptionImageListView.Items)
                {
                    //to get the dropdown of each line
                    HiddenField productPhotoId = (HiddenField)item.FindControl("PhotoId");

                    var photo     = _subscriptionRepository.GetImageById(int.Parse(productPhotoId.Value));
                    var orderItem = (HiddenField)item.FindControl("Order");
                    photo.Order = 1;
                    if (!string.IsNullOrEmpty(orderItem.Value))
                    {
                        photo.Order    = int.Parse(orderItem.Value);
                        photo.IsCover  = false;
                        photo.IsActive = true;
                    }

                    photos.Add(photo);
                }
                if (photos.FirstOrDefault(p => p.Order == 0 || p.Order == 1) != null)
                {
                    photos.First(p => p.Order == 0 || p.Order == 1).IsCover = true;
                }

                _subscriptionRepository.Update(subscriptions, photos);
            }

            string productImageDefault = Constant.ImageDefault;
            var    productImage        = _subscriptionRepository.SubscriptionImagesList.FirstOrDefault(x => x.SubscriptionId == subscriptions.Id && x.IsCover && x.IsActive);

            if (productImage != null)
            {
                productImageDefault = productImage.Url;
            }

            if (!string.IsNullOrEmpty(productImageDefault))
            {
                var    imageName = Helper.ReplaceLastOccurrence(productImageDefault, ".", "-ovl.");
                string imageUrl  = Server.MapPath(imageName);
                if (!File.Exists(imageUrl))
                {
                    System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(productImageDefault));
                    Bitmap newImage            = Helper.ChangeOpacity(image, 0.7f);
                    using (MemoryStream memory = new MemoryStream())
                    {
                        using (FileStream fs = new FileStream(imageUrl, FileMode.Create, FileAccess.ReadWrite))
                        {
                            newImage.Save(memory, ImageFormat.Jpeg);
                            byte[] bytes = memory.ToArray();
                            fs.Write(bytes, 0, bytes.Length);
                        }
                    }
                }
            }

            _subscriptionRepository.ResetCache();

            Response.Redirect(Constant.SubscriptionListPage);
        }