Example #1
0
        public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit()
        {
            var testName = "TestName";

            // Arrange
            var context            = ApplicationDbContextInMemoryFactory.InitializeContext();
            var categoryRepository = new EfDeletableEntityRepository <Category>(context);
            var categoriesService  = new CategoriesService(categoryRepository);

            var inputModel = new CreateCategoryInputModel()
            {
                Name = testName,
            };

            await categoriesService.CreateAsync(inputModel);

            var category = categoryRepository.All().FirstOrDefault(c => c.Name == testName);

            // Act
            var expectedCategoryName = "Edited_TestName";
            var editInputModel       = new CategoryInfoViewModel()
            {
                Id   = category.Id,
                Name = expectedCategoryName,
            };
            await categoriesService.EditAsync(editInputModel);

            var actualCategoryName = category.Name;

            // Assert
            category = await categoryRepository.GetByIdWithDeletedAsync(category.Id);

            Assert.Equal(expectedCategoryName, actualCategoryName);
        }
Example #2
0
        public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit()
        {
            var testContent = "TestContent";

            // Arrange
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var replyRepository = new EfDeletableEntityRepository <Reply>(context);
            var repliesService  = new RepliesService(replyRepository);

            var inputModel = new CreateReplyInputModel()
            {
                Content = testContent,
            };

            await repliesService.CreateAsync(inputModel);

            var reply = replyRepository.All().FirstOrDefault(c => c.Content == testContent);

            // Act
            var expectedReplyContent = "Edited_TestContent";
            await repliesService.EditAsync(reply.Id, expectedReplyContent);

            var actualReplyContent = reply.Content;

            // Assert
            reply = await replyRepository.GetByIdWithDeletedAsync(reply.Id);

            Assert.Equal(expectedReplyContent, actualReplyContent);
        }
        public async Task EfDeletableEntityRepoGetByIdWithDeletedShouldWork()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "EfDeletableEntityRepoGetByIdWithDeletedShouldWork").Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Category>(dbContext);
            var service    = new CategoriesService(repository);
            await service.AddAsync("test", new Image()
            {
                Url = "https://miau.bg/files/lib/600x350/agresive-cat1.jpg"
            }, "description");

            await service.AddAsync("test2", new Image()
            {
                Url = "https://miau.bg/files/lib/600x350/agresive-cat1.jpg"
            }, "description2");

            await service.AddAsync("test3", new Image()
            {
                Url = "https://miau.bg/files/lib/600x350/agresive-cat1.jpg"
            }, "description3");

            var categoryToDelete = service.GetCategoryByName("test3");

            repository.Delete(categoryToDelete);
            await repository.SaveChangesAsync();

            var result = await repository.GetByIdWithDeletedAsync(3);

            Assert.Equal(3, result.Id);
            Assert.True(result.IsDeleted);
        }
        public async Task EditeProjectionShouldWorkCorrectly()
        {
            var context    = new ApplicationDbContext(this.options.Options);
            var repository = new EfDeletableEntityRepository <Projection>(context);
            var service    = this.GetProjectionsService(repository, context);

            await service.AddAsync(this.projection);

            var id = repository.All().Select(p => p.Id).FirstOrDefault();

            var diffProjection = new AddProjectionInputModel
            {
                Id                 = id,
                HallId             = 2,
                MovieId            = 3,
                ProjectionDateTime = new DateTime(2020, 05, 10),
            };

            await service.EditAsync(diffProjection);

            var dbProjection = await repository.GetByIdWithDeletedAsync(id);

            Assert.Equal(2, dbProjection.HallId);
            Assert.Equal(3, dbProjection.MovieId);
        }
Example #5
0
        public async Task AddHallShouldAddCorrectData()
        {
            var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options));
            var service    = new HallsService(repository);

            await service.AddAsync(this.hall);

            var dbHall = await repository.GetByIdWithDeletedAsync(1);

            Assert.Equal(ProjectionType.TwoD, dbHall.ProjectionType);
            Assert.Equal(50, dbHall.Seats.Count());
        }
Example #6
0
        public async Task DeleteHallShouldWorkCorrectly()
        {
            var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options));
            var service    = new HallsService(repository);

            await service.AddAsync(this.hall);

            await service.DeleteAsync(1);

            var dbHall = await repository.GetByIdWithDeletedAsync(1);

            Assert.True(dbHall.IsDeleted);
        }
Example #7
0
        public async Task DeleteMovieShouldWorkCorrectly()
        {
            var repository = new EfDeletableEntityRepository <Movie>(new ApplicationDbContext(this.options.Options));
            var service    = new MoviesService(repository);

            await service.AddAsync(this.movie);

            await service.DeleteAsync(1);

            var movie = await repository.GetByIdWithDeletedAsync(1);

            Assert.True(movie.IsDeleted);
        }
Example #8
0
        public async Task DeleteReviewShouldWorkCorrectly()
        {
            var context    = new ApplicationDbContext(this.options.Options);
            var repository = new EfDeletableEntityRepository <Review>(context);
            var service    = this.GetReviewsService(repository);

            var added = await service.AddAsync(this.review);

            await service.DeleteAsync(added.Id);

            var deleted = await repository.GetByIdWithDeletedAsync(added.Id);

            Assert.True(deleted.IsDeleted);
        }
        public async Task DeleteProjectionShouldWorkCorrectly()
        {
            var context    = new ApplicationDbContext(this.options.Options);
            var repository = new EfDeletableEntityRepository <Projection>(context);
            var service    = this.GetProjectionsService(repository, context);

            await service.AddAsync(this.projection);

            var id = repository.All().Select(p => p.Id).FirstOrDefault();
            await service.DeleteAsync(id);

            var dbProjection = await repository.GetByIdWithDeletedAsync(id);

            Assert.True(dbProjection.IsDeleted);
        }
        public async Task PayByIdAsync_ShouldRetutnCorrectResult_RankPlatinumUser()
        {
            MapperInitializer.InitializeMapper();
            var context            = ApplicationDbContextInMemoryFactory.InitializeContext();
            var transferRepository = new EfDeletableEntityRepository <Transfer>(context);
            var userRepository     = new EfDeletableEntityRepository <ApplicationUser>(context);
            var transfersService   = new TransfersService(transferRepository, userRepository);
            var seeder             = new DbContextTestsSeeder();
            await seeder.SeedTransfersAsync(context);

            await seeder.SeedUsersAsync(context);

            var transfer = transferRepository.GetByIdWithDeletedAsync(8);
            var result   = await transfersService.PayByIdAsync(7, "efg");

            Assert.True(result == 9, ErrorMessage);
        }
Example #11
0
        public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit()
        {
            // Arrange
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var topicRepository = new EfDeletableEntityRepository <Topic>(context);
            var userRepository  = new EfDeletableEntityRepository <ApplicationUser>(context);
            var topicsService   = new TopicsService(topicRepository, userRepository);

            var createInputModel = new CreateTopicInputModel()
            {
                Title   = "TestTitle",
                Content = "TestContent_TestContent_TestContent_TestContent_TestContent_TestContent",
            };

            await topicsService.CreateAsync(createInputModel);

            var topic = topicRepository.All().FirstOrDefault(t => t.Title == "TestTitle");

            var editInputModel = new TopicEditViewModel()
            {
                Id      = topic.Id,
                Title   = "Edited_TestTitle",
                Content = "Edited_TestContent_TestContent_TestContent_TestContent_TestContent_TestContent",
            };

            // Act
            var expectedTopicTitle   = "Edited_TestTitle";
            var expectedTopicContent = "Edited_TestContent_TestContent_TestContent_TestContent_TestContent_TestContent";
            await topicsService.EditAsync(editInputModel);

            // Assert
            topic = await topicRepository.GetByIdWithDeletedAsync(editInputModel.Id);

            Assert.Equal(expectedTopicTitle, topic.Title);
            Assert.Equal(expectedTopicContent, topic.Content);
        }