Esempio n. 1
0
        public void SubscribeAlreadySubscribed()
        {
            Subscription subscription = CreateSubscriptionData("*****@*****.**");
            var          mockDbSet    = GetMockDbSet(subscription);
            var          mockContext  = new Mock <NewsletterContext>();

            mockContext.Setup(m => m.Subscriptions).Returns(mockDbSet.Object);

            SubscriptionRepository repository        = new SubscriptionRepository(mockContext.Object);
            NewsletterService      newsletterService = new NewsletterService(repository);

            SubscriptionRequest request = new SubscriptionRequest();

            request.Subscription = subscription;
            SubscriptionResponse response = newsletterService.Subscribe(request);

            mockDbSet.Verify(m => m.Add(It.IsAny <Subscription>()), Times.Never());
            mockContext.Verify(m => m.SaveChanges(), Times.Never());
            Assert.AreEqual(response.Status, StatusCode.AlreadySubscribed);
            Assert.IsNotNull(response.Subscription);
            Assert.AreEqual(response.Subscription.EmailAddress, request.Subscription.EmailAddress);
        }
Esempio n. 2
0
 private void Submit_Click(object sender, EventArgs e)
 {
     Response.Text = NewsletterService.Subscribe(Email.Text);
 }