Пример #1
0
        public async Task GetTopicTotalDisikes_WithCorrectTopicId_ShouldReturnCorrectTotalLikes()
        {
            // Arrange
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var topicRepository = new EfDeletableEntityRepository <Topic>(context);
            var userRepository  = new EfDeletableEntityRepository <ApplicationUser>(context);
            var topicsService   = new TopicsService(topicRepository, userRepository);

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

            await topicsService.CreateAsync(inputModel);

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

            topic.Dislikes = 15;
            topicRepository.Update(topic);
            await topicRepository.SaveChangesAsync();

            // Act
            var expectedTotalTopicDislikes = 15;
            var actualTotalTopicDislikes   = topicsService.GetTopicTotalDislikes(topic.Id);

            // Assert
            Assert.Equal(expectedTotalTopicDislikes, actualTotalTopicDislikes);
        }
Пример #2
0
        public async Task CheckGettingAppointmentsHistoryUserAsync()
        {
            ApplicationDbContext db = GetDb();

            var repository = new EfDeletableEntityRepository <Appointment>(db);

            var usersService = new Mock <IUsersService>();
            var cardsService = new Mock <ICardsService>();

            var categoriesRepository = new EfDeletableEntityRepository <Category>(db);

            var categoryService = new CategoriesService(categoriesRepository);

            var proceduresRepository           = new EfDeletableEntityRepository <Procedure>(db);
            var procedureReviewsRepository     = new EfDeletableEntityRepository <Review>(db);
            var procedureProductsRepository    = new EfRepository <ProcedureProduct>(db);
            var procedureStylistsRepository    = new EfRepository <ProcedureStylist>(db);
            var skinProblemProcedureRepository = new EfRepository <SkinProblemProcedure>(db);

            var proceduresService = new ProceduresService(
                proceduresRepository,
                procedureReviewsRepository,
                procedureProductsRepository,
                procedureStylistsRepository,
                skinProblemProcedureRepository,
                repository,
                categoryService);

            var service = new AppointmentsService(
                repository,
                usersService.Object,
                cardsService.Object,
                proceduresService,
                categoryService);

            await db.Procedures.AddAsync(this.procedure);

            await db.Categories.AddAsync(this.category);

            await db.SaveChangesAsync();

            string appId = await this.GetAppointmentIdAsync(service);

            await service.DoneAsync(appId);

            var firstApp = await GetAppointmentAsync(repository, appId);

            firstApp.IsReview = true;

            repository.Update(firstApp);
            await repository.SaveChangesAsync();

            var resultAppointments = await
                                     service.GetHistoryUserAsync <TestAppointmentModel>(this.client.Id);

            Assert.Single(resultAppointments);
        }
Пример #3
0
        public async Task GetAdditionalInfoByUserIdAsync_WithExistentUserId_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "UserService GetAdditionalInfoByUserIdAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context        = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userRepository = new EfDeletableEntityRepository <ApplicationUser>(context);
            var userService    = this.GetUserService(userRepository, context);

            await this.SeedDataAsync(context);

            var user = userRepository.All().First();

            user.FullName     = "FullName";
            user.Biography    = "Biography";
            user.ProfilePhoto = "ProfilePhoto";
            user.Lifestyle    = context.Lifestyles.First();
            user.Allergies.Add(new UserAllergen()
            {
                Allergen = context.Allergens.First(),
            });
            userRepository.Update(user);
            await userRepository.SaveChangesAsync();

            // Act
            var actualResult = await userService.GetAdditionalInfoByUserIdAsync(user.Id);

            var expectedResult = userRepository
                                 .All()
                                 .First()
                                 .To <UserAdditionalInfoServiceModel>();

            // Assert
            Assert.True(expectedResult.FullName == actualResult.FullName, errorMessagePrefix + " " + "FullName is not returned properly.");
            Assert.True(expectedResult.Biography == actualResult.Biography, errorMessagePrefix + " " + "Biography is not returned properly.");
            Assert.True(expectedResult.ProfilePhoto == actualResult.ProfilePhoto, errorMessagePrefix + " " + "ProfilePhoto is not returned properly.");
            Assert.True(expectedResult.Lifestyle.Id == actualResult.Lifestyle.Id, errorMessagePrefix + " " + "Lifestyle is not returned properly.");
            Assert.True(expectedResult.Allergies.First().Allergen.Id == actualResult.Allergies.First().Allergen.Id, errorMessagePrefix + " " + "Allergen is not returned properly.");
        }
        public async Task CheckDeletingArticleAsync()
        {
            ApplicationDbContext db = GetDb();

            var repository = new EfDeletableEntityRepository <Article>(db);
            var clientArticleLikesRepository = new EfRepository <ClientArticleLike>(db);
            var commentsRepository           = new EfDeletableEntityRepository <Comment>(db);

            var service = new ArticlesService(
                repository,
                commentsRepository,
                clientArticleLikesRepository,
                this.cloudinaryService.Object);

            string articleId = await this.GetArticleAsync(service);

            var article = await repository.All().FirstOrDefaultAsync(a => a.Id == articleId);

            article.Comments.Add(this.comment);

            var articleLike = new ClientArticleLike()
            {
                ClientId  = this.client.Id,
                ArticleId = articleId,
            };

            await clientArticleLikesRepository.AddAsync(articleLike);

            await clientArticleLikesRepository.SaveChangesAsync();

            repository.Update(article);
            await repository.SaveChangesAsync();

            await service.DeleteAsync(articleId);

            Assert.True(article.IsDeleted);
        }
Пример #5
0
        private async Task <AppointmentsService> PrepareAppointmentReviewAsync()
        {
            ApplicationDbContext db = GetDb();

            var repository = new EfDeletableEntityRepository <Appointment>(db);

            var usersService = new Mock <IUsersService>();
            var cardsService = new Mock <ICardsService>();

            var categoriesRepository = new EfDeletableEntityRepository <Category>(db);

            var categoryService = new CategoriesService(categoriesRepository);

            var proceduresRepository           = new EfDeletableEntityRepository <Procedure>(db);
            var procedureReviewsRepository     = new EfDeletableEntityRepository <Review>(db);
            var procedureProductsRepository    = new EfRepository <ProcedureProduct>(db);
            var procedureStylistsRepository    = new EfRepository <ProcedureStylist>(db);
            var skinProblemProcedureRepository = new EfRepository <SkinProblemProcedure>(db);

            var proceduresService = new ProceduresService(
                proceduresRepository,
                procedureReviewsRepository,
                procedureProductsRepository,
                procedureStylistsRepository,
                skinProblemProcedureRepository,
                repository,
                categoryService);

            var service = new AppointmentsService(
                repository,
                usersService.Object,
                cardsService.Object,
                proceduresService,
                categoryService);

            await db.Procedures.AddAsync(this.procedure);

            await db.Categories.AddAsync(this.category);

            await db.SaveChangesAsync();

            var pastDate = DateTime.ParseExact("12/10/2020", "dd/MM/yyyy", CultureInfo.InvariantCulture);

            string firstAppId = await service.CreateAsync(this.client.Id, this.stylist.Id, this.procedure.Id, pastDate, "11:00", "test comment");

            string secondAppId = await service.CreateAsync(this.client.Id, this.stylist.Id, this.procedure.Id, pastDate, "12:00", "test comment");

            string thirdAppId = await service.CreateAsync(this.client.Id, this.stylist.Id, this.procedure.Id, DateTime.UtcNow, "13:00", "test comment");

            await service.DoneAsync(firstAppId);

            await service.DoneAsync(secondAppId);

            await service.DoneAsync(thirdAppId);

            var firstApp = await GetAppointmentAsync(repository, firstAppId);

            firstApp.IsReview = true;

            repository.Update(firstApp);
            await repository.SaveChangesAsync();

            return(service);
        }