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

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

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

                await repository.SaveChangesAsync();
            }

            var service = new CandidateFavoriteJobPostingsService(repository);

            await service.DeleteJobPostingFromFavorites("1", "2");

            var favoritesCount = repository.All().ToList().Count;

            Assert.Equal(2, favoritesCount);
        }
        public async Task CreateNewCandidateForJobPostingAsyncTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

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

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

                await repository.SaveChangesAsync();
            }

            var service = new CandidatesService(repository);

            await service.CreateNewCandidateForJobPostingAsync("8", "9");

            var candidatesCount = repository.All().ToList().Count;

            Assert.Equal(4, candidatesCount);
        }
        public async Task EditAsync_WithCorrectData_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "CategoryService EditAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(context);

            var categoryRepository   = new EfDeletableEntityRepository <Category>(context);
            var categoryService      = new CategoryService(categoryRepository);
            var categoryServiceModel = categoryRepository.All().First().To <CategoryServiceModel>();

            categoryServiceModel.Title = "New Title";

            // Act
            var result = await categoryService.EditAsync(categoryServiceModel);

            // Assert
            Assert.True(result, errorMessagePrefix + " " + "Returns false.");
        }
        public async Task SendAsync_ShouldSuccessfullyCreateTopicReport()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var userReportRepository = new EfDeletableEntityRepository <UserReport>(context);
            var userReportsService   = new UserReportsService(userReportRepository);

            var inputModel = new CreateUserReportInputModel()
            {
                Title       = "TestTitle",
                Description = "TestDescription",
            };

            // Act
            var expectedUserReportsCount = 1;
            await userReportsService.SendAsync(inputModel);

            var actualUserReportsCount = userReportRepository.All().Count();

            // Assert
            Assert.Equal(expectedUserReportsCount, actualUserReportsCount);
        }
예제 #5
0
        public async Task UpdateNewsFeedPostShouldWorkCorrectlyAsync()
        {
            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();

            var postUpdate = new NewsFeedPost
            {
                Id      = 1,
                Content = "testtttt",
                UserId  = "1",
            };

            await service.UpdateNewsFeedPostAsync(postUpdate);

            var postAfterUpdate = await repositoryNewsFeedPost.All().FirstOrDefaultAsync(a => a.Id == postUpdate.Id);

            Assert.Equal(postUpdate.Content, postAfterUpdate.Content);
        }
예제 #6
0
        public async void GetFeedbackByIdCorrectly()
        {
            var dbContext = new DbContextOptionsBuilder <ApplicationDbContext>()
                            .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var feedbackRepository = new EfDeletableEntityRepository <Feedback>(new ApplicationDbContext(dbContext.Options));

            feedbackRepository.SaveChangesAsync().GetAwaiter().GetResult();

            var service = new FeedbacksService(feedbackRepository);

            var user = new ApplicationUser
            {
                Id = Guid.NewGuid().ToString(),
            };

            var meeting = new Meeting
            {
                Id    = Guid.NewGuid().ToString(),
                Title = "Test 1",
            };

            var secondMeeting = new Meeting
            {
                Id    = Guid.NewGuid().ToString(),
                Title = "Test 2",
            };

            await service.AddAsync(user.Id, user, 6, "Awesome", meeting.Id, meeting);

            await service.AddAsync("Not user id", new ApplicationUser { }, 1, "Poor", secondMeeting.Id, secondMeeting);

            var id       = feedbackRepository.All().Where(f => f.MeetingId == secondMeeting.Id).First().Id;
            var feedback = service.GetFeedbackById(id);

            Assert.Equal(1, feedback.Rating);
            Assert.Equal("Poor", feedback.Description);
        }
예제 #7
0
        public async Task AddAdditionalInfoAsync_WithCorrectData_ShouldSuccessfullyAdd()
        {
            var errorMessagePrefix = "UserService AddAdditionalInfoAsync() 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 userId = context.Users.First().Id;
            var userAdditionalInfoServiceModel = new UserAdditionalInfoServiceModel()
            {
                Biography    = "Biography",
                ProfilePhoto = "ProfilePhoto",
                Lifestyle    = context.Lifestyles.First().To <LifestyleServiceModel>(),
            };

            userAdditionalInfoServiceModel.Allergies.Add(new UserAllergenServiceModel()
            {
                Allergen = context.Allergens.First().To <AllergenServiceModel>(),
            });

            // Act
            await userService.AddAdditionalInfoAsync(userId, userAdditionalInfoServiceModel);

            var actualResult   = userRepository.All().First(x => x.Id == userId);
            var expectedResult = userAdditionalInfoServiceModel;

            // Assert
            Assert.True(actualResult.HasAdditionalInfo, errorMessagePrefix + " " + "HasAdditionalInfo 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 DeleteAsyncShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var userRepo = new EfDeletableEntityRepository <ApplicationUser>(dbContext);

            var service = new EmployeesService(userRepo);

            await userRepo.AddAsync(new ApplicationUser
            {
                FirstName  = "ivan",
                LastName   = "ivanov",
                MiddleName = "ivanov",
                EGN        = "1234567890",
            });

            await userRepo.AddAsync(new ApplicationUser
            {
                FirstName  = "ivan2",
                LastName   = "ivanov2",
                MiddleName = "ivanov2",
                EGN        = "1234567892",
            });

            await userRepo.SaveChangesAsync();

            var customerId = (await userRepo.AllAsNoTracking()
                              .FirstOrDefaultAsync()).Id;

            await service.DeleteAsync(customerId);

            var customers = await userRepo.All().ToListAsync();

            Assert.Single(customers);
            Assert.DoesNotContain(customers, x => x.Id == customerId);
        }
        public async Task AddRequestForRecipientCorrectlyTest()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();

            var recipientRepository             = new EfDeletableEntityRepository <Recipient>(dbContext);
            var hospitalDataRepository          = new EfDeletableEntityRepository <HospitalData>(dbContext);
            var recipientReques                 = new EfDeletableEntityRepository <RecipientRequest>(dbContext);
            var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext);

            var service = new RecipientsService(
                recipientRepository,
                hospitalDataRepository,
                recipientReques,
                recipientHospitalDataRepository);

            await service.AddRequestForRecipient("123", "456");

            var result = recipientReques.All().Count();

            Assert.Equal(1, result);
        }
        public async Task DeleteAsyncRecipientsThrowsExceptionTest()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();

            var recipientRepository             = new EfDeletableEntityRepository <Recipient>(dbContext);
            var hospitalDataRepository          = new EfDeletableEntityRepository <HospitalData>(dbContext);
            var recipientReques                 = new EfDeletableEntityRepository <RecipientRequest>(dbContext);
            var recipientHospitalDataRepository = new EfDeletableEntityRepository <RecipientHospitalData>(dbContext);

            var service = new RecipientsService(
                recipientRepository,
                hospitalDataRepository,
                recipientReques,
                recipientHospitalDataRepository);

            await SeedDataAsync(dbContext);

            var hospital = hospitalDataRepository.All().FirstOrDefault();

            await Assert.ThrowsAsync <ArgumentException>(() => service.DeleteAsync(hospital.ApplicationUserId, "1"));
        }
        public async Task CreateRequestNotNullTest()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            var requestRepository             = new EfDeletableEntityRepository <Request>(dbContext);
            var hospitalDataRequestRepository = new EfDeletableEntityRepository <HospitalDataRequest>(dbContext);
            var hospitalDataRepository        = new EfDeletableEntityRepository <HospitalData>(dbContext);
            var recipientReques    = new EfDeletableEntityRepository <RecipientRequest>(dbContext);
            var locationRepository = new EfDeletableEntityRepository <Location>(dbContext);

            var service = new RequestsService(
                requestRepository,
                hospitalDataRequestRepository,
                hospitalDataRepository,
                recipientReques,
                locationRepository);

            await SeedDataAsync(dbContext);

            var result = requestRepository.All().FirstOrDefault();

            Assert.NotNull(result);
        }
예제 #12
0
        public async Task AddPaymentTypeAsync_WithCorrectData_ShouldSuccessfullyCreate()
        {
            var errorMessagePrefix = "PaymentTypesService AddPaymentTypeAsync() method does not work properly.";

            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var paymentTypeRepository = new EfDeletableEntityRepository <PaymentType>(context);
            var paymentTypesService   = this.GetPaymentTypesService(paymentTypeRepository);

            var paymentTypeModel = new PaymentType
            {
                Name = "Test",
            };

            // Act
            await paymentTypesService.AddPaymentTypeAsync(paymentTypeModel);

            var actualResult   = paymentTypeRepository.All().First();
            var expectedResult = paymentTypeModel;

            // Assert
            Assert.True(expectedResult.Name == actualResult.Name, errorMessagePrefix + " " + "Name is not returned properly.");
        }
        public async Task CreateAllAsync_ShouldReturnCorrectResult()
        {
            var errorMessage = "ReservationStatusesService CreateAllAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var reservationStatusRepository = new EfDeletableEntityRepository <ReservationStatus>(context);
            var reservationStatusesService  = this.GetReservationStatusesService(reservationStatusRepository, context);
            var seeder = new ReservationStatusesServiceTestsSeeder();
            await seeder.SeedReservationStatusAsync(context);

            // Act
            await reservationStatusesService.CreateAllAsync(new string[] { "Test-1" });

            var actualResult = new ReservationStatus {
                Name = "Test-1"
            };
            var expectedResult = reservationStatusRepository.All().First();

            // Assert
            Assert.True(expectedResult.Name == actualResult.Name, errorMessage + " " + "Name is not returned properly.");
        }
        public async Task AddReservationStatusAsync_WithCorrectData_ShouldSuccessfullyCreate()
        {
            var errorMessagePrefix = "ReservationService AddReservationStatusAsync() method does not work properly.";

            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var reservationStatusRepository = new EfDeletableEntityRepository <ReservationStatus>(context);
            var reservationStatusesService  = this.GetReservationStatusesService(reservationStatusRepository, context);

            var reservationStatusModel = new ReservationStatus
            {
                Name = "Test",
            };

            // Act
            await reservationStatusesService.AddReservationStatusAsync(reservationStatusModel);

            var actualResult   = reservationStatusRepository.All().First();
            var expectedResult = reservationStatusModel;

            // Assert
            Assert.True(expectedResult.Name == actualResult.Name, errorMessagePrefix + " " + "Name is not returned properly.");
        }
예제 #15
0
        public async Task GetProfilePostsAsync_WithValidData_ShouldReturnProfilePosts()
        {
            // Arrange
            this.InitilaizeMapper();
            var context        = InMemoryDbContext.Initiliaze();
            var postRepository = new EfDeletableEntityRepository <Post>(context);
            var postService    = new PostsService(postRepository);

            await this.SeedUserFollower(context);

            await postRepository.AddAsync(new Post { Id = 52, Creator = context.Users.FirstOrDefault() });

            await postRepository.SaveChangesAsync();

            // Act
            var posts = await postService.GetProfilePostsAsync("testUser"); // "testUser" is seeded with SeedUserFollower.

            var expectedPostId = postRepository.All().FirstOrDefault().Id;
            var actualPostId   = posts.FirstOrDefault().Id;

            // Assert
            Assert.Equal(expectedPostId, actualPostId);
        }
예제 #16
0
        public async Task GetFeedAsync_WithValidData_ShouldReturnFeedPosts()
        {
            // Arrange
            this.InitilaizeMapper();
            var context        = InMemoryDbContext.Initiliaze();
            var postRepository = new EfDeletableEntityRepository <Post>(context);
            var postService    = new PostsService(postRepository);

            await this.SeedUserFollower(context);

            await postRepository.AddAsync(new Post { Creator = context.Users.FirstOrDefault(), Description = "feedDescription" });

            await postRepository.SaveChangesAsync();

            // Act
            var feedPosts = await postService.GetFeedAsync("followerId", 0, 2);

            var expectedPostDescription = postRepository.All().FirstOrDefault().Description;
            var actualPostDescription   = feedPosts.FirstOrDefault().Description;

            // Assert
            Assert.Equal(expectedPostDescription, actualPostDescription);
        }
예제 #17
0
        public async Task EditAsync_WithIncorrectProperty_ShouldThrowArgumentNullException()
        {
            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedReviewAsync(context);

            var reviewRepository   = new EfDeletableEntityRepository <Review>(context);
            var reviewService      = this.GetReviewService(reviewRepository);
            var reviewServiceModel = reviewRepository.All().First().To <ReviewServiceModel>();

            reviewServiceModel.Rating  = 0;
            reviewServiceModel.Comment = "New Comment";

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await reviewService.EditAsync(reviewServiceModel.Id, reviewServiceModel);
            });
        }
예제 #18
0
        public async Task EditAsync_WithCorrectData_ShouldReturnCorrectResult()
        {
            var errorMessagePrefix = "ReviewService EditAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedReviewAsync(context);

            var reviewRepository   = new EfDeletableEntityRepository <Review>(context);
            var reviewService      = this.GetReviewService(reviewRepository);
            var reviewServiceModel = reviewRepository.All().First().To <ReviewServiceModel>();

            reviewServiceModel.Rating  = 1;
            reviewServiceModel.Comment = "New Comment";

            // Act
            var result = await reviewService.EditAsync(reviewServiceModel.Id, reviewServiceModel);

            // Assert
            Assert.True(result, errorMessagePrefix + " " + "Returns false.");
        }
        public void CreateDonationShouldReturnNullTest()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            var donationEventRepository = new EfDeletableEntityRepository <DonationEvent>(dbContext);
            var bloodBankRepository     = new EfDeletableEntityRepository <BloodBank>(dbContext);
            var bagRepository           = new EfDeletableEntityRepository <BloodBag>(dbContext);
            var hospitalDataRepository  = new EfDeletableEntityRepository <HospitalData>(dbContext);
            var donorDataRepository     = new EfDeletableEntityRepository <DonorData>(dbContext);
            var requestRepository       = new EfDeletableEntityRepository <Request>(dbContext);

            var service = new DonationEventsService(
                donationEventRepository,
                bloodBankRepository,
                bagRepository,
                hospitalDataRepository,
                donorDataRepository,
                requestRepository);

            var donationEvent = donationEventRepository.All().FirstOrDefault(de => de.RequestId == "123");

            Assert.Null(donationEvent);
        }
예제 #20
0
        public async Task DeleteUserShouldReturnUserNotFoundMessage()
        {
            AutoMapperConfig.RegisterMappings(typeof(UserTestModel).Assembly);

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var repository = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options));

            await repository.AddAsync(new ApplicationUser { Id = "test1", UserName = "******" });

            await repository.AddAsync(new ApplicationUser { Id = "test2", UserName = "******" });

            await repository.AddAsync(new ApplicationUser { Id = "test3", UserName = "******" });

            await repository.SaveChangesAsync();

            var mockedUserManager = MockUserManager <ApplicationUser>(repository.All().ToList());
            var service           = new UsersService(repository, null, null, null, mockedUserManager.Object);

            var outputMessage = await service.DeleteUserAsync("TestUser4");

            Assert.Equal("User not found.", outputMessage);
        }
예제 #21
0
        public async Task GetIdByTitle_WithCorrectData_ShouldReturnCorrectResult()
        {
            // 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);

            // Act
            var expectedId = topicRepository.All().FirstOrDefault(t => t.Title == "TestTitle").Id;
            var actualId   = topicsService.GetIdByTitle(inputModel.Title);

            // Assert
            Assert.Equal(expectedId, actualId);
        }
예제 #22
0
        public async Task EditShouldExecuteSuccessfully()
        {
            this.SetupSqlite();
            await this.SeedDatabase();

            using var context = new ApplicationDbContext(this.ContextOptions);

            var repository     = new EfDeletableEntityRepository <Article>(context);
            var articleService = new ArticleService(repository);

            var newArticleObj = new ArticleServiceModel {
                Id = 1, Content = "Test", ImageUrl = "Test", Title = "Test"
            };

            var result = await articleService.Edit(newArticleObj);

            var updatedArticle = repository.All().FirstOrDefault(a => a.Id == 1);

            Assert.Equal(1, result);
            Assert.Equal("Test", updatedArticle.Title);
            Assert.Equal("Test", updatedArticle.Content);
            Assert.Equal("Test", updatedArticle.ImageUrl);
        }
예제 #23
0
        public async Task CreateAsyncShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var serviceRepo = new EfDeletableEntityRepository <Service>(dbContext);

            var service = new ServiceService(serviceRepo);

            var model = new ServiceModel
            {
                ServiceType = 1,
                Name        = "ASD",
            };

            await service.CreateAsync <ServiceModel>(model);

            var serviceInDB = await serviceRepo.All()
                              .FirstOrDefaultAsync(x => x.Name == "ASD");

            Assert.Equal("ASD", serviceInDB.Name);
        }
예제 #24
0
        public async void CurrentUserAddInfoShouldAddDetailsAccordingly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var dogsitterRepository = new EfDeletableEntityRepository <Dogsitter>(new ApplicationDbContext(options.Options));
            var dogsittersService   = new DogsittersService(dogsitterRepository);

            var dogsitterBase = new Dogsitter
            {
                UserId = Guid.NewGuid().ToString(),
            };

            await dogsitterRepository.AddAsync(dogsitterBase);

            await dogsitterRepository.SaveChangesAsync();

            await dogsittersService.CurrentUserAddInfo(dogsitterBase.UserId, FillInfo, FillInfo, FillInfo, FillInfo, FillInfo, FillInfo, 5);

            var dogsitter = await dogsitterRepository.All().FirstOrDefaultAsync();

            Assert.Equal(FillInfo, dogsitter.FirstName);
        }
        public async Task TestAddUserToFollower()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfDeletableEntityRepository <Follower>(new ApplicationDbContext(options.Options));
            var service    = new UserServices(repository);

            var model = new UserFollowerViewModel
            {
                GameId = 5,
                UserId = "4",
            };

            for (int i = 0; i < 2; i++)
            {
                await service.AddUserToFollower(model);
            }

            var counter = await repository.All().CountAsync();

            Assert.Equal(1, counter);
        }
예제 #26
0
        public async Task ChangeUserStringValuesWithNullUser_ShouldReturnStatusInvalidUser()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

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

            var service = new ModelService.ModelService(repository, null, null, null);

            var user1 = await this.CreateUserAsync("*****@*****.**", "Pesho", "Peshev", repository);

            var user2 = await this.CreateUserAsync("*****@*****.**", "Vank", "Vanko", repository);

            var getUser = await repository.All().Where(x => x.Id == user1).FirstOrDefaultAsync();

            var valueInput    = "country";
            var valueExample  = "Norway";
            var statusInvalid = "Invalid user";

            var changeUserAge = await service.ChangeUserStringValues(null, valueExample, valueInput);

            Assert.Equal(statusInvalid, changeUserAge);
        }
예제 #27
0
        public async Task AddAsync_WithCorrectData_ShouldSuccessfullyCreate()
        {
            var errorMessage = "PaymentsService AddPaymentAsync() method does not work properly.";

            // Arrange
            MapperInitializer.InitializeMapper();
            var context = HotelDbContextInMemoryFactory.InitializeContext();
            var seeder  = new PaymentsServiceTestsSeeder();
            await seeder.SeedPaymentAsync(context);

            var paymentRepository = new EfDeletableEntityRepository <Payment>(context);
            var paymentsService   = this.GetPaymentsService(paymentRepository);

            var paymentModel = new Payment
            {
                DateOfPayment       = DateTime.Now.Date,
                Amount              = 300,
                PaymentTypeId       = context.PaymentTypes.First().Id,
                ReservationPayments = new List <ReservationPayment>
                {
                    new ReservationPayment {
                        ReservationId = context.Reservations.First().Id
                    }
                },
            };

            // Act
            await paymentsService.AddPaymentAsync(paymentModel);

            var actualResult   = paymentRepository.All().First();
            var expectedResult = paymentModel;

            // Assert
            Assert.True(expectedResult.DateOfPayment == actualResult.DateOfPayment, errorMessage + " " + "Date of payment is not returned properly.");
            Assert.True(expectedResult.Amount == actualResult.Amount, errorMessage + " " + "Amount is not returned properly.");
            Assert.True(expectedResult.PaymentTypeId == actualResult.PaymentTypeId, errorMessage + " " + "payment type id is not returned properly.");
        }
        public async Task GetHospitalByUserIdShouldReturnNullTest()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();

            var hospitalDataRepository      = new EfDeletableEntityRepository <HospitalData>(dbContext);
            var usersRepository             = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var rolesRepository             = new EfDeletableEntityRepository <ApplicationRole>(dbContext);
            var appUsersHospitalRepository  = new EfDeletableEntityRepository <ApplicationUserHospitalData>(dbContext);
            var recipientRepository         = new EfDeletableEntityRepository <Recipient>(dbContext);
            var bloodBankRepository         = new EfDeletableEntityRepository <BloodBank>(dbContext);
            var hospitalBloodBankRepository = new EfDeletableEntityRepository <HospitalDataBloodBank>(dbContext);
            var bagRepository = new EfDeletableEntityRepository <BloodBag>(dbContext);

            var userManager = this.GetUserManagerMock();

            var service = new HospitalsService(
                usersRepository,
                hospitalDataRepository,
                rolesRepository,
                appUsersHospitalRepository,
                recipientRepository,
                bloodBankRepository,
                hospitalBloodBankRepository,
                bagRepository);

            await SeedDataAsync(dbContext);

            var user = usersRepository.All().FirstOrDefault();

            await service.CreateHospitalProfileAsync(this.SeedInputs(), user.Id);

            var result = service.GetHospitalDataById <HospitalProfileInputModel>("111", "111");

            Assert.Null(result);
        }
        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);
        }
        public async Task CreateHospitalUserIsInCorrectRoleTest()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            MapperInitializer.InitializeMapper();

            var hospitalDataRepository      = new EfDeletableEntityRepository <HospitalData>(dbContext);
            var usersRepository             = new EfDeletableEntityRepository <ApplicationUser>(dbContext);
            var rolesRepository             = new EfDeletableEntityRepository <ApplicationRole>(dbContext);
            var appUsersHospitalRepository  = new EfDeletableEntityRepository <ApplicationUserHospitalData>(dbContext);
            var recipientRepository         = new EfDeletableEntityRepository <Recipient>(dbContext);
            var bloodBankRepository         = new EfDeletableEntityRepository <BloodBank>(dbContext);
            var hospitalBloodBankRepository = new EfDeletableEntityRepository <HospitalDataBloodBank>(dbContext);
            var bagRepository = new EfDeletableEntityRepository <BloodBag>(dbContext);

            var userManager = this.GetUserManagerMock();

            var service = new HospitalsService(
                usersRepository,
                hospitalDataRepository,
                rolesRepository,
                appUsersHospitalRepository,
                recipientRepository,
                bloodBankRepository,
                hospitalBloodBankRepository,
                bagRepository);

            await SeedDataAsync(dbContext);

            await service.CreateHospitalProfileAsync(this.SeedInputs(), this.SeedInputs().Id);

            var user = usersRepository.All().Where(u => u.UserName == "User1").FirstOrDefault();

            var isInRole = await userManager.Object.IsInRoleAsync(user, GlobalConstants.HospitaltRoleName);

            Assert.True(isInRole);
        }