public async Task GetAllByExperienceId_ShouldWorkCorrectly()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository   = new EfDeletableEntityRepository <ExperienceImage>(context);
            var service      = new ImagesService(repository);
            var experienceId = context.Experiences.First().Id;
            var count        = service.GetAllByExperienceId <ImagesViewModel>(experienceId).Count();

            Assert.True(count == 1, "Create method does not work correctly");
        }
Пример #2
0
        public async Task Exist_ShouldWorkCorrectly()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            int testExperienceId = context.Comments.First().Id;

            var repository = new EfDeletableEntityRepository <Comment>(context);
            var service    = new CommentsService(repository);
            var result     = service.Exists(testExperienceId);

            Assert.True(result);
        }
Пример #3
0
        public async Task GetIdByName_WithInvalidData_ShouldWorkCorrectly(string name)
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository = new EfDeletableEntityRepository <Location>(context);
            var service    = new LocationsService(repository);


            var actualId = service.GetIdByName(name);

            Assert.True(actualId == 0);
        }
Пример #4
0
        public async Task GetNameById_WithInvalidData_ShouldWorkCorrectly(int?id)
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository = new EfDeletableEntityRepository <Location>(context);
            var service    = new LocationsService(repository);


            var name = service.GetNameById(id);

            Assert.Null(name);
        }
Пример #5
0
        public async Task GetAll_ShouldReturnCorrectCountAsync()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository = new EfDeletableEntityRepository <Comment>(context);
            var service    = new CommentsService(repository);

            var experience = context.Experiences.FirstOrDefault();

            var count = service.GetAll <CommentViewModel>(experience.Id).Count();

            Assert.True(count == 1, "Create method does not work correctly");
        }
Пример #6
0
        public async Task IsAuthorBy_ShouldWorkCorrectly()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            int    testCommentId = context.Comments.First().Id;
            string author        = context.Comments.First().UserId;

            var repository = new EfDeletableEntityRepository <Comment>(context);
            var service    = new CommentsService(repository);
            var actual     = service.IsAuthoredBy(testCommentId, author);

            Assert.True(actual);
        }
        public async Task DeleteAsync_ShouldWorkCorrectly()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var imageId = context.ExperienceImages.First().Id;

            var repository = new EfDeletableEntityRepository <ExperienceImage>(context);
            var service    = new ImagesService(repository);
            await service.DeleteAsync(imageId);

            var deletedImage = repository.AllWithDeleted().Where(x => x.Id == imageId).FirstOrDefault();

            Assert.True(deletedImage.IsDeleted == true, "Delete method does not work correctly");
        }
Пример #8
0
        public async Task GetNameById_ShouldWorkCorrectly()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository = new EfDeletableEntityRepository <Location>(context);
            var service    = new LocationsService(repository);

            var firstLocation = context.Locations.First();
            var expectedName  = firstLocation.Name;
            var id            = firstLocation.Id;

            var actualName = service.GetNameById(id);

            Assert.True(expectedName == actualName);
        }
        public async Task GetById_ShouldWorkCorrectly()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository = new EfDeletableEntityRepository <ExperienceImage>(context);
            var service    = new ImagesService(repository);

            var imageId = context.ExperienceImages.First().Id;
            var model   = service.GetById <ImagesViewModel>(imageId);

            var expectedExperience = repository.All().Where(x => x.Id == imageId).FirstOrDefault();

            Assert.Equal(expectedExperience.Name, model.Name);
            Assert.Equal(expectedExperience.ExperienceId.ToString(), model.ExperienceId.ToString());
        }
Пример #10
0
        public async Task GetById_ShouldWorkCorrectly()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository = new EfDeletableEntityRepository <Comment>(context);
            var service    = new CommentsService(repository);

            var commentId = 1;
            var model     = service.GetById <CommentViewModel>(commentId);

            var expectedComment = repository.All().Where(x => x.Id == commentId).FirstOrDefault();

            Assert.Equal(expectedComment.Content, model.Content);
            Assert.Equal(expectedComment.UserId.ToString(), model.UserId.ToString());
            Assert.Equal(expectedComment.ExperienceId.ToString(), model.ExperienceId.ToString());
        }
Пример #11
0
        public async Task Search_ShouldWorkCorrectly()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var repository = new EfDeletableEntityRepository <Location>(context);
            var service    = new LocationsService(repository);

            var firstLocation = context.Locations.First();
            var name          = firstLocation.Name;

            var resultLocation      = service.Search <LocationViewModel>(name);
            var firstResultLocation = resultLocation.FirstOrDefault();

            Assert.True(resultLocation.Count() == 1);
            Assert.Equal(firstLocation.Name, firstResultLocation.Name);
        }
Пример #12
0
        public async Task EditAsync_ShouldThrowException()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            await this.SeedData(context);

            var expectedTitle = "New Title";

            var input = new ExperienceEditViewModel()
            {
                Id          = 3,
                Title       = expectedTitle,
                Description = "Description of test",
            };

            var repository = new EfDeletableEntityRepository <Experience>(context);
            var service    = new ExperiencesService(repository);

            Task act() => service.EditAsync(input);

            await Assert.ThrowsAsync <ArgumentNullException>(act);
        }
Пример #13
0
        private ApplicationDbContext InitializeContext()
        {
            var context = WilderExperienceContextInMemoryFactory.InitializeContext();

            return(context);
        }