コード例 #1
0
        public void ChangeSubscriptionShouldRemoveSubscriptionFromRepositoryAndSendConfirmationIfAllTopicsAreRemovedAndReturn204()
        {
            const string testMail   = "*****@*****.**";
            var          testTopicA = new Topic {
                Abbreviation = "TA", Description = "Test Topic A"
            };
            var testTopicB = new Topic {
                Abbreviation = "TB", Description = "Test Topic A"
            };

            var testSubscription = new Subscription {
                Mail = testMail, Topics = new List <Topic> {
                    testTopicA, testTopicB
                }
            };

            var repositoryMock = new Mock <ISubscriptionRepository>();

            repositoryMock
            .Setup(repository => repository.GetSubscription(testMail))
            .Returns(testSubscription);

            var sendContentMock = new Mock <ISendContent>();

            var controller = new SubscriptionController(repositoryMock.Object, sendContentMock.Object);

            IActionResult result       = controller.ChangeSubscription(testMail, Enumerable.Empty <string>().ToArray());
            var           objectResult = result as NoContentResult;

            Assert.NotNull(objectResult);

            repositoryMock.Verify(repository => repository.RemoveSubscription(It.IsAny <Subscription>()), Times.Once);
            sendContentMock.Verify(sendContent => sendContent.Send(testMail, It.IsAny <Content>()), Times.Once);
        }
コード例 #2
0
        public void ChangeSubscriptionShouldNotRemoveSubscriptionFromRepositoryAndNotSendConfirmationIfNotAllTopicsAreRemovedAndReturn201()
        {
            const string testMail   = "*****@*****.**";
            var          testTopicA = new Topic {
                Abbreviation = "TA", Description = "Test Topic A"
            };
            var testTopicB = new Topic {
                Abbreviation = "TB", Description = "Test Topic A"
            };

            var testSubscription = new Subscription {
                Mail = testMail, Topics = new List <Topic> {
                    testTopicA, testTopicB
                }
            };

            var repositoryMock = new Mock <ISubscriptionRepository>();

            repositoryMock
            .Setup(repository => repository.GetSubscription(testMail))
            .Returns(testSubscription);

            repositoryMock
            .Setup(repository => repository.GetTopics())
            .Returns(new List <Topic> {
                testTopicA, testTopicB
            });

            var sendContentMock = new Mock <ISendContent>();

            var controller = new SubscriptionController(repositoryMock.Object, sendContentMock.Object);

            IActionResult result       = controller.ChangeSubscription(testMail, new string[] { testTopicA.Abbreviation });
            var           objectResult = result as ObjectResult;

            Assert.NotNull(objectResult);
            Assert.Equal(201, objectResult.StatusCode.Value);

            repositoryMock.Verify(repository => repository.RemoveSubscription(It.IsAny <Subscription>()), Times.Never);
            sendContentMock.Verify(sendContent => sendContent.Send(testMail, It.IsAny <Content>()), Times.Never);
        }