public async Task MarkProfileAsDeletedTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options));

            foreach (var item in this.GetApplicationUserData())
            {
                await repository.AddAsync(item);

                await repository.SaveChangesAsync();
            }

            var store = new Mock <IUserStore <ApplicationUser> >();

            var userManager = new Mock <UserManager <ApplicationUser> >(store.Object, null, null, null, null, null, null, null, null);

            var service = new AccountTypeService(userManager.Object, repository);

            await service.MarkProfileAsDeleted("1");

            var user = repository.AllWithDeleted().Where(x => x.Id == "1").FirstOrDefault();

            Assert.True(user.IsDeleted);
        }
        public async Task RestoreUserAccountAsyncShouldWorkCorrectly()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var testAccountRepository = new EfDeletableEntityRepository <Account>(context);

            var testAccounts = TestDataHelpers.GetTestData();

            foreach (var testAccount in testAccounts)
            {
                if (testAccount.Id == 1)
                {
                    testAccount.IsDeleted = true;
                }

                await testAccountRepository.AddAsync(testAccount);

                await testAccountRepository.SaveChangesAsync();
            }

            var testAccountManagementService = new AccountManagementService(this.userManager.Object, this.userRepository.Object, testAccountRepository, this.positionService.Object, this.feePaymentsRepository.Object);

            await testAccountManagementService.RestoreUserAccountAsync("1", 1);

            var account = testAccountRepository
                          .AllWithDeleted()
                          .FirstOrDefault(a => a.Id == 1);

            Assert.IsFalse(account.IsDeleted);
        }
        public async Task MarkJobPostingsAsDeleted()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfDeletableEntityRepository <JobPosting>(new ApplicationDbContext(options.Options));

            foreach (var item in this.GetJobPostingData())
            {
                await repository.AddAsync(item);

                await repository.SaveChangesAsync();
            }

            var service = new JobPostingsService(repository);

            var listIds = new List <string> {
                "2222"
            };

            await service.MarkJobPostingsAsDeleted(listIds);

            foreach (var id in listIds)
            {
                var user = repository.AllWithDeleted().Where(x => x.Id == id).FirstOrDefault();
                Assert.True(user.IsDeleted);
            }
        }
Esempio n. 4
0
        public async Task DeletAllReplaysByMessageId_WithData_ShouldReturnEmptyRepository()
        {
            var context    = SteuDbContextInMemoryFactory.InitializeContext();
            var service    = this.IntializeReplayService(context);
            var repository = new EfDeletableEntityRepository <Replay>(context);

            var replay = new Replay()
            {
                Id        = "replayId1",
                MessageId = "messageId",
            };

            var replay2 = new Replay()
            {
                Id        = "replayId2",
                MessageId = "messageId",
            };
            await repository.AddAsync(replay);

            await repository.AddAsync(replay2);

            await repository.SaveChangesAsync();

            await service.DeletAllReplaysByMessageId("messageId");

            var actualResult = await repository.AllWithDeleted().ToListAsync();

            Assert.Empty(actualResult);
        }
        public async Task EfDeletableEntityRepoAllWithDeletedShouldWork()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "EfDeletableEntityRepoAllWithDeletedShouldWork").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 = repository.AllWithDeleted().ToList();

            Assert.Equal(3, result.Count);
        }
        public async Task ChangeStateAsyncDeletesOrdersTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Orders.Add(new Order
            {
                Id        = "First order",
                UserId    = "Test",
                ProductId = 1,
                State     = DeliveryState.OnTheAdress,
            });
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Order>(dbContext);
            var service    = new OrdersService(repository);

            var newState = new EditStateViewModel
            {
                Id       = "First order",
                NewState = (int)DeliveryState.Received,
            };
            await service.ChangeStateAsync(newState);

            var orderIsGetsDeleted = repository.All().Any(a => a.Id == "First order");
            var orderIsStillInDb   = repository.AllWithDeleted().Any(a => a.Id == "First order");

            Assert.True(orderIsStillInDb);
            Assert.False(orderIsGetsDeleted);
        }
Esempio n. 7
0
        public async Task DeleteNewsFeedPostShouldWorkCorrectlyAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryArticle         = new EfDeletableEntityRepository <Article>(dbContext);
            var repositoryNewsFeedPost    = new EfDeletableEntityRepository <NewsFeedPost>(dbContext);
            var repositoryNewsFeedComment = new EfDeletableEntityRepository <NewsFeedComment>(dbContext);
            var repositoryCategory        = new EfDeletableEntityRepository <Category>(dbContext);
            var repositoryComment         = new EfDeletableEntityRepository <Comment>(dbContext);

            var service = new AdministratorService(repositoryNewsFeedPost, repositoryArticle, repositoryNewsFeedComment, repositoryCategory, repositoryComment);

            var post = new NewsFeedPost
            {
                Id      = 1,
                Content = "test",
                UserId  = "1",
            };

            await repositoryNewsFeedPost.AddAsync(post);

            await repositoryNewsFeedPost.SaveChangesAsync();

            await service.DeleteNewsFeedPostAsync(post);

            Assert.Equal(1, repositoryNewsFeedPost.AllWithDeleted().Count());
        }
Esempio n. 8
0
        public async Task UnDeleteBooking_ShouldUnDeleteTheBookingByIdForTheUser()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var userRepository    = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options));
            var bookingRepository = new EfDeletableEntityRepository <Model4You.Data.Models.Booking>(new ApplicationDbContext(options));

            var service = new BookingService.BookingService(bookingRepository, userRepository, null);
            var user1   = await this.CreateUserWithNoInformationAsync(
                "*****@*****.**", "Pesho", "Peshev", userRepository);

            var booking = await this.CreateBookingForTest(
                user1,
                DateTime.UtcNow,
                "TestName",
                "TestCompany",
                "*****@*****.**",
                "059593",
                1,
                "descriptionTest",
                true,
                userRepository,
                bookingRepository);

            for (int i = 0; i < 2; i++)
            {
                await this.CreateBookingForTest(
                    user1,
                    DateTime.UtcNow,
                    $"TestName{i}",
                    "TestCompany",
                    $"test{i}@abv.bg",
                    $"059593{i}",
                    1,
                    $"descriptionTest{i}",
                    false,
                    userRepository,
                    bookingRepository);
            }

            var getBookingId = await bookingRepository.AllWithDeleted()
                               .Where(x => x.UserId == user1 && x.HireDescription == "descriptionTest")
                               .Select(x => x.Id)
                               .FirstOrDefaultAsync();

            await service.UnDeleteBooking(getBookingId);

            var bookingCount = await bookingRepository
                               .All()
                               .Where(x => x.UserId == user1)
                               .CountAsync();

            Assert.Equal(3, bookingCount);
        }
        public async Task DeleteSetsProjectToDeleted()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            await SeedDataAsync(dbContext);

            var projectsRepository = new EfDeletableEntityRepository <Project>(dbContext);

            var service = this.InitializeService(projectsRepository, dbContext);

            await service.DeleteAsync("First test title", "*****@*****.**");

            var result = projectsRepository.AllWithDeleted().Where(p => p.Title == "First test title").FirstOrDefault().IsDeleted;

            Assert.True(result);
        }
        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");
        }
Esempio n. 11
0
        public async Task TestDeleteExerciseAsync_WithValidData_ShouldDeleteExerciseCorrectly()
        {
            var context    = ApplicationDbContextInMemoryFactory.InitializeContext();
            var repository = new EfDeletableEntityRepository <Exercise>(context);

            var exerciseId = "asdf";
            await repository.AddAsync(new Exercise { Id = exerciseId });

            await repository.SaveChangesAsync();

            var service = new ExercisesService(repository);

            await service.DeleteExerciseAsync(exerciseId);

            var deletedExercise = repository.AllWithDeleted().Where(e => e.Id == exerciseId).FirstOrDefault();

            Assert.True(deletedExercise.IsDeleted);
        }
Esempio n. 12
0
        public async Task TestDeleteCommentAsync_WithValidData_ShouldCreateExerciseCorrectly()
        {
            var context    = ApplicationDbContextInMemoryFactory.InitializeContext();
            var repository = new EfDeletableEntityRepository <Comment>(context);

            var commentId = "asdf";
            await repository.AddAsync(new Comment { Id = commentId });

            await repository.SaveChangesAsync();

            var service = new CommentsService(repository);

            await service.DeleteCommentAsync(commentId);

            var deletedComment = repository.AllWithDeleted().Where(c => c.Id == commentId).FirstOrDefault();

            Assert.True(deletedComment.IsDeleted);
        }
Esempio n. 13
0
        public async Task Delete_WithCorrectId_ShouldRemoveComment()
        {
            MapperInitializer.InitializeMapper();
            var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext();

            await this.CreateTestComments(dbContext);

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

            var model = new CommentEditModel();

            model.Id = 1;

            await service.Delete(model);

            var result = repository.AllWithDeleted().Where(p => p.Id == 1).FirstOrDefault().IsDeleted;

            Assert.True(result);
        }
Esempio n. 14
0
        public async Task UndeleteCourseTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var courseRepository = new EfDeletableEntityRepository <Course>(new ApplicationDbContext(options.Options));

            var mockUserCourseRepository = new Mock <IRepository <UserCourse> >();
            var mockConfiguration        = new Mock <IConfiguration>();
            var mockCategoryService      = new Mock <ICategoriesService>();
            var store           = new Mock <IUserStore <ApplicationUser> >();
            var mockUserManager = new Mock <UserManager <ApplicationUser> >(store.Object, null, null, null, null, null, null, null, null);

            var service      = new CoursesService(courseRepository, mockUserCourseRepository.Object, mockConfiguration.Object, mockCategoryService.Object, mockUserManager.Object);
            var coursesToAdd = this.GetCourseData();

            foreach (var item in coursesToAdd)
            {
                await courseRepository.AddAsync(item);

                await courseRepository.SaveChangesAsync();
            }

            var course = new Course
            {
                Name        = "Course5",
                Id          = "6",
                UserId      = "User3",
                Description = "Course Description 134",
                CategoryId  = 4,
                IsDeleted   = true,
            };
            await courseRepository.AddAsync(course);

            await courseRepository.SaveChangesAsync();

            await service.UndeleteCourse("6");

            var courses = courseRepository.AllWithDeleted();

            Assert.Equal(5, courses.Count());
        }
Esempio n. 15
0
        public async Task TestDeleteReservationIsInDatabase()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var reservationRepository = new EfDeletableEntityRepository <Reservation>(new ApplicationDbContext(options.Options));
            var reservationId         = Guid.NewGuid().ToString();

            await reservationRepository.AddAsync(new Reservation()
            {
                Id = reservationId
            });

            await reservationRepository.SaveChangesAsync();

            var reservationsService = new ReservationsService(reservationRepository);

            await reservationsService.DeleteAsync(reservationId, Guid.NewGuid().ToString());

            Assert.Equal(1, reservationRepository.AllWithDeleted().Count());
        }
Esempio n. 16
0
        public async Task MarkUserInfoAsDeletedTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfDeletableEntityRepository <UserInfo>(new ApplicationDbContext(options.Options));

            foreach (var item in this.GetUserInfoData())
            {
                await repository.AddAsync(item);

                await repository.SaveChangesAsync();
            }

            var service = new UserInfoService(repository);

            await service.MarkUserInfoAsDeleted("1");

            var user = repository.AllWithDeleted().Where(x => x.UserId == "1").FirstOrDefault();

            Assert.True(user.IsDeleted);
        }
Esempio n. 17
0
        public async Task MoveToAnswered_ShouldMoveUnAnsweredQuestionToAnswered()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var repository = new EfDeletableEntityRepository <ContactFormData>(new ApplicationDbContext(options));

            var service = new ContactDataService(repository);

            var form = await this.CreateContactForm("Pesho", "*****@*****.**", "Test", "Test", true, repository);

            var form2 = await this.CreateContactForm("Pesho2", "*****@*****.**", "Test2", "Test2", false, repository);

            var form3 = await this.CreateContactForm("Pesho2", "*****@*****.**", "Test2", "Test2", false, repository);

            var formIdToString = form2.ToString();

            await service.MoveToAnswered(formIdToString);

            var check = await repository.AllWithDeleted().Where(x => x.Id == form2 && x.IsDeleted).FirstOrDefaultAsync();

            Assert.NotNull(check);
        }
        public async Task DeleteUserAsyncShouldDeleteUserAccountCorrectly()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var testAccountRepository = new EfDeletableEntityRepository <Account>(context);
            var testAccounts          = TestDataHelpers.GetTestData();

            foreach (var acc in testAccounts)
            {
                await testAccountRepository.AddAsync(acc);

                await testAccountRepository.SaveChangesAsync();
            }

            var testUserRepository = new Mock <IDeletableEntityRepository <ApplicationUser> >();

            testUserRepository
            .Setup(a => a.GetByIdWithDeletedAsync(It.IsAny <string>()))
            .ReturnsAsync(new ApplicationUser()
            {
                Id        = "1",
                IsDeleted = false,
            });
            testUserRepository
            .Setup(a => a.Delete(It.IsAny <ApplicationUser>()));
            testUserRepository
            .Setup(a => a.SaveChangesAsync());

            var testAccountManagementService = new AccountManagementService(this.userManager.Object, testUserRepository.Object, testAccountRepository, this.positionService.Object, this.feePaymentsRepository.Object);

            await testAccountManagementService.DeleteUserAsync("1", 1);

            var account = testAccountRepository.AllWithDeleted().FirstOrDefault(a => a.Id == 1);

            Assert.IsTrue(account.IsDeleted);
        }
Esempio n. 19
0
        public async Task DeleteAccountDataTest()
        {
            var options               = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());
            var carRepository         = new EfDeletableEntityRepository <Car>(new ApplicationDbContext(options.Options));
            var viewsRepository       = new EfDeletableEntityRepository <AdView>(new ApplicationDbContext(options.Options));
            var commentRepository     = new EfDeletableEntityRepository <Comment>(new ApplicationDbContext(options.Options));
            var searchModelRepository = new EfDeletableEntityRepository <SearchModel>(new ApplicationDbContext(options.Options));
            var favoriteRepository    = new EfDeletableEntityRepository <UserCarFavorite>(new ApplicationDbContext(options.Options));
            var userManager           = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options));
            var adService             = new Mock <IAdService>();

            var service = new MyAccountService(carRepository, adService.Object, viewsRepository, commentRepository, searchModelRepository, favoriteRepository);
            var user    = new ApplicationUser {
                FirstName = "test"
            };
            await userManager.AddAsync(user);

            await userManager.SaveChangesAsync();

            var car = new Car
            {
                Cc               = 1,
                Color            = 0,
                Condition        = Condition.New,
                Door             = Doors.Three,
                EuroStandart     = EuroStandart.Euro1,
                Extras           = "4x4",
                Fuel             = Fuel.Diesel,
                Gearbox          = Gearbox.Automatic,
                Horsepowers      = 1,
                ImgsPaths        = GlobalConstants.DefaultImgCar,
                Km               = 100,
                Location         = Location.Sofia,
                Make             = Make.Audi,
                Model            = "test",
                Modification     = "test",
                MoreInformation  = "test test",
                Price            = 100,
                Type             = Types.Convertible,
                TypeOfVeichle    = TypeOfVeichle.Car,
                YearOfProduction = DateTime.Parse("01.01.1999"),
                UserId           = user.Id,
            };

            await carRepository.AddAsync(car);

            await carRepository.SaveChangesAsync();

            await viewsRepository.AddAsync(new AdView { CarId = car.Id, User = user.Id });

            await viewsRepository.SaveChangesAsync();

            await commentRepository.AddAsync(new Comment { CarId = car.Id, Title = "test", Content = "test", UserId = user.Id });

            await commentRepository.SaveChangesAsync();

            await searchModelRepository.AddAsync(new SearchModel { UserId = user.Id });

            await searchModelRepository.SaveChangesAsync();

            await favoriteRepository.AddAsync(new UserCarFavorite { CarId = car.Id, UserId = user.Id });

            await favoriteRepository.SaveChangesAsync();

            await service.DeleteAccountDataAsync(user.Id);

            Assert.Equal(0, await carRepository.AllWithDeleted().CountAsync());
            Assert.Equal(0, await viewsRepository.AllWithDeleted().CountAsync());
            Assert.Equal(0, await commentRepository.AllWithDeleted().CountAsync());
            Assert.Equal(0, await favoriteRepository.AllWithDeleted().CountAsync());
            Assert.Equal(0, await searchModelRepository.AllWithDeleted().CountAsync());
        }