Exemplo n.º 1
0
        public async Task AddStory_ShouldThrow_IfDestinationNotExist()
        {
            var destRepoBuilder = new DestinationsRepositoryBuilder();
            var destRepo        = destRepoBuilder
                                  .WithAll()
                                  .Build();


            var storiesRepoBuilder = new StoriesRepositoryBuilder();
            var storiesRepo        = storiesRepoBuilder
                                     .WithAll()
                                     .Build();

            var sut = new StoriesService(storiesRepo, destRepo, null, null, Mapper);

            var createStoryViewModel = new CreateStoryViewModel
            {
                Content       = "Niki otiva na ski",
                Title         = "Niki",
                DestinationId = "11",
            };

            var user = new GoUser {
                Id = "7"
            };

            var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await sut.AddStory(createStoryViewModel, "11", user));

            Assert.Equal("Destination not exist!", ex.Message);

            storiesRepoBuilder.StoriesRepoMock.Verify(r => r.AddAsync(It.IsAny <Story>()), Times.Never);
            storiesRepoBuilder.StoriesRepoMock.Verify(r => r.SaveChangesAsync(), Times.Never);
        }
Exemplo n.º 2
0
        public async Task AddStory_ShouldAddNewStoryCorrectly()
        {
            var destRepoBuilder = new DestinationsRepositoryBuilder();
            var destRepo        = destRepoBuilder
                                  .WithAll()
                                  .Build();


            var storiesRepoBuilder = new StoriesRepositoryBuilder();
            var storiesRepo        = storiesRepoBuilder
                                     .WithAll()
                                     .Build();

            var sut = new StoriesService(storiesRepo, destRepo, null, null, Mapper);

            var createStoryViewModel = new CreateStoryViewModel
            {
                Content       = "Niki otiva na ski",
                Title         = "Niki",
                DestinationId = "2",
            };

            var user = new GoUser {
                Id = "7"
            };

            await sut.AddStory(createStoryViewModel, "2", user);

            storiesRepoBuilder.StoriesRepoMock.Verify(r => r.AddAsync(It.IsAny <Story>()), Times.Once);
            storiesRepoBuilder.StoriesRepoMock.Verify(r => r.SaveChangesAsync(), Times.Once);
        }