Ejemplo n.º 1
0
        public async Task CreateNews_WhenAllParametersAreValid()
        {
            var dabataseName = nameof(CreateNews_WhenAllParametersAreValid);

            var options = NewsTestUtils.GetOptions(dabataseName);

            var mappingProviderMock = new Mock <IMappingProvider>();

            DateTime createdOn = DateTime.Now;
            string   newsTitle = "Spider-Man Far From Home soon in cinemas";
            string   text      = " Spider-Man: Far From Home will be released in theaters on July 5, 2019";
            string   imageUrl  = "anyimage.jpg";

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


                await sut.CreateNewsAsync(createdOn, newsTitle, text, imageUrl);

                arrangeContext.SaveChanges();
            }

            using (var actAndAssertContext = new MovieManagementContext(options))
            {
                Assert.IsTrue(actAndAssertContext.News.Count() == 1);
                Assert.IsTrue(actAndAssertContext.News.Any(m => m.Title == newsTitle));
            }
        }
Ejemplo n.º 2
0
        public async void Should_NewsService_InsertTo_Database()
        {
            var service = new NewsService(_setupBeforeEachTest.NewsRepository.Object, _setupBeforeEachTest.Mapper,
                                          _setupBeforeEachTest.NewsGroupRepository.Object);
            await service.CreateNewsAsync(new CreateNewsDto()
            {
                Headline = "TestHeadline"
            });

            var found = service.GetAllNews().FirstOrDefault(x => x.Headline.Equals("TestHeadline"));

            found.Should().NotBeNull();
        }
Ejemplo n.º 3
0
        public async Task ReturnCorrectViewModel()
        {
            var dabataseName = nameof(ReturnCorrectViewModel);

            var options = NewsTestUtils.GetOptions(dabataseName);

            var mappingProviderMock = new Mock <IMappingProvider>();

            mappingProviderMock.Setup(x => x.MapTo <NewsViewModel>(It.IsAny <News>())).Returns(new NewsViewModel());

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

                DateTime createdOn = DateTime.Now;
                string   newsTitle = "Spider-Man Far From Home soon in cinemas";
                string   text      = " Spider-Man: Far From Home will be released in theaters on July 5, 2019";
                string   imageUrl  = "anyimage.jpg";

                var result = await sut.CreateNewsAsync(createdOn, newsTitle, text, imageUrl);

                Assert.IsInstanceOfType(result, typeof(NewsViewModel));
            }
        }
Ejemplo n.º 4
0
        public async Task Throw_WhenNews_DoExist()
        {
            var dabataseName = nameof(Throw_WhenNews_DoExist);

            var options = NewsTestUtils.GetOptions(dabataseName);

            NewsTestUtils.FillContextWithNews(options);

            var mappingProviderMock = new Mock <IMappingProvider>();

            DateTime createdOn = DateTime.Now;
            string   newsTitle = "Spider-Man Far From Home soon in cinemas";
            string   text      = " Spider-Man: Far From Home will be released in theaters on July 5, 2019";
            string   imageUrl  = "anyimage.jpg";

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


                await Assert.ThrowsExceptionAsync <EntityAlreadyExistsException>(
                    async() => await sut.CreateNewsAsync(createdOn, newsTitle, text, imageUrl));
            }
        }