Ejemplo n.º 1
0
        public async Task GetAllFavAdsOnCurrentUserTests()
        {
            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);

            await SeedData(carRepository);

            var car1 = await carRepository.All().FirstOrDefaultAsync(x => x.MoreInformation == "firstCar");

            var car2 = await carRepository.All().FirstOrDefaultAsync(x => x.MoreInformation == "secondCar");

            await service.AddAdToFavAsync(car1.Id, "1");

            await service.AddAdToFavAsync(car2.Id, "1");

            AutoMapperConfig.RegisterMappings(typeof(UserAdViewModel).Assembly);

            var result = await service.GetAllFavAdsOnCurrentUserAsync <UserAdViewModel>("1");

            Assert.Equal(2, result.Count);
        }
Ejemplo n.º 2
0
        public async Task RemoveFavAdAsync()
        {
            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 car = new Car();
            await carRepository.AddAsync(car);

            await carRepository.SaveChangesAsync();

            var userId = "UserId";
            var carId  = car.Id;

            await service.AddAdToFavAsync(carId, userId);

            await service.RemoveFavAdAsync(carId, userId);

            var userCarFavRecord = await favoriteRepository.All().FirstOrDefaultAsync(x => x.UserId == userId);

            Assert.Null(userCarFavRecord);
        }
Ejemplo n.º 3
0
        public async Task AddToFavWithNotFoundCarShouldReturnNullRefferenceException()
        {
            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 userId = "UserId";
            var carId  = "notFoundId";
            await Assert.ThrowsAsync <NullReferenceException>(async() => await service.AddAdToFavAsync(carId, userId));
        }
Ejemplo n.º 4
0
        public async Task GetMyCarsTest()
        {
            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 adService             = new Mock <IAdService>();

            var service = new MyAccountService(carRepository, adService.Object, viewsRepository, commentRepository, searchModelRepository, favoriteRepository);

            await SeedData(carRepository);

            AutoMapperConfig.RegisterMappings(typeof(MyCarsViewModel).Assembly);
            var result = await service.GetMyCarsAsync("1");

            Assert.Equal(1, result.Count);
        }
Ejemplo n.º 5
0
 public MyAccountController(UnitOfWork unitOfWork, MyAccountService myAccountService)
 {
     _unitOfWork       = unitOfWork;
     _myAccountService = myAccountService;
 }
Ejemplo n.º 6
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());
        }