public async Task AddNewComment_WhenAllParametersAreValid()
        {
            var dabataseName = nameof(Throw_WhenText_IsEmpty);

            var options = CommentTestUtil.GetOptions(dabataseName);

            var mappingProviderMock = new Mock <IMappingProvider>();

            string commentText = "Very interesting.Would love to see it!";

            string title = "Avengers EndGame";

            string userName = "******";


            using (var arrangeContext = new MovieManagementContext(options))
            {
                var sut = new CommentService(arrangeContext, mappingProviderMock.Object);


                await sut.AddComment(commentText, title, userName);

                arrangeContext.SaveChanges();
            }

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                Assert.IsTrue(actAndAssertContext.Comments.Count() == 1);
                Assert.IsTrue(actAndAssertContext.Comments.Any(m => m.Text == commentText));
            }
        }
        public async Task ReturnCorrectViewModel()
        {
            var dabataseName = nameof(Throw_WhenText_IsEmpty);

            var options = CommentTestUtil.GetOptions(dabataseName);

            var mappingProviderMock = new Mock <IMappingProvider>();

            string commentText = "Very interesting.Would love to see it!";

            string title = "Avengers EndGame";

            string userName = "******";

            mappingProviderMock.Setup(x => x.MapTo <CommentViewModel>(It.IsAny <Comment>())).Returns(new CommentViewModel());

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var sut = new CommentService(actAndAssertContext, mappingProviderMock.Object);

                var result = await sut.AddComment(commentText, title, userName);

                Assert.IsInstanceOfType(result, typeof(CommentViewModel));
            }
        }
        public async Task Throw_WhenText_IsEmpty()
        {
            var dabataseName = nameof(Throw_WhenText_IsEmpty);

            var options = CommentTestUtil.GetOptions(dabataseName);

            var mappingProviderMock = new Mock <IMappingProvider>();

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var sut = new CommentService(actAndAssertContext, mappingProviderMock.Object);

                string commentText = null;

                string title = "Avengers EndGame";

                string userName = "******";

                await Assert.ThrowsExceptionAsync <EntityInvalidException>(
                    async() => await sut.AddComment(commentText, title, userName));
            }
        }
Beispiel #4
0
        public async Task Call_MapFunction_Once()
        {
            var dabataseName = nameof(Call_MapFunction_Once);

            var options = CommentTestUtil.GetOptions(dabataseName);

            var collectionOfComments = new List <Comment>();

            var mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock
            .Setup(x => x.MapTo <ICollection <CommentViewModel> >(It.IsAny <List <Comment> >()))
            .Callback <object>(inputargs => collectionOfComments = inputargs as List <Comment>);

            using (var arrangeContext = new MovieManagementContext(options))
            {
                arrangeContext.Comments.Add(new Comment()
                {
                    Text  = "Very interesting. Would love to see it!",
                    Title = "Avengers EndGame"
                });
                arrangeContext.Comments.Add(new Comment()
                {
                    Text  = "Every Marvel movie has achieved revenue of over 100million dollars",
                    Title = "Marvel movies are blockbusters"
                });
                await arrangeContext.SaveChangesAsync();
            }

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                var sut = new CommentService(actAndAssertContext, mappingProviderMock.Object);
                await sut.GetAllComments();

                mappingProviderMock.Verify(m => m.MapTo <ICollection <CommentViewModel> >(collectionOfComments), Times.Once);
            }
        }