Esempio n. 1
0
        public async void GetOwnerByIdShouldReturnCorrectOwner()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var userRepository      = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options));
            var dogsitterRepository = new EfDeletableEntityRepository <Dogsitter>(new ApplicationDbContext(options.Options));
            var ownerRepository     = new EfDeletableEntityRepository <Owner>(new ApplicationDbContext(options.Options));

            var ownersService = new OwnersService(userRepository, ownerRepository, dogsitterRepository);

            var user  = new ApplicationUser();
            var user2 = new ApplicationUser();

            await ownersService.CreateOwnerAsync(user, Info, Info, Info, Info, Gender.Male, Info, Info, user.Id, Info);

            await ownersService.CreateOwnerAsync(user2, Info, Info, Info, Info, Gender.Male, Info, Info, user2.Id, Info);

            var owner = ownersService.GetOwnerById(user.Id);

            Assert.Equal(user.Id, owner.UserId);
        }
Esempio n. 2
0
        public async void CreateOwnerAsyncShouldCreateTheOwner()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var userRepository      = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options));
            var dogsitterRepository = new EfDeletableEntityRepository <Dogsitter>(new ApplicationDbContext(options.Options));
            var ownerRepository     = new EfDeletableEntityRepository <Owner>(new ApplicationDbContext(options.Options));

            var ownersService = new OwnersService(userRepository, ownerRepository, dogsitterRepository);

            var user = new ApplicationUser();

            await ownersService.CreateOwnerAsync(user, Info, Info, Info, Info, Gender.Male, Info, Info, user.Id, Info);

            Assert.Single(ownerRepository.All());
        }
Esempio n. 3
0
        public async void GetOwnerByIdShouldThrowNullReferenceExceptionWhenWrongId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var userRepository      = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options));
            var dogsitterRepository = new EfDeletableEntityRepository <Dogsitter>(new ApplicationDbContext(options.Options));
            var ownerRepository     = new EfDeletableEntityRepository <Owner>(new ApplicationDbContext(options.Options));

            var ownersService = new OwnersService(userRepository, ownerRepository, dogsitterRepository);

            var user = new ApplicationUser();

            await ownersService.CreateOwnerAsync(user, Info, Info, Info, Info, Gender.Male, Info, Info, user.Id, Info);

            var owner = ownersService.GetOwnerById("");

            Assert.Throws <NullReferenceException>(() => owner.Id);
        }
Esempio n. 4
0
        public async void UpdateCurrentLoggedInUserInfoAsyncShouldUpdateValuesAccordingly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var userRepository      = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options));
            var dogsitterRepository = new EfDeletableEntityRepository <Dogsitter>(new ApplicationDbContext(options.Options));
            var ownerRepository     = new EfDeletableEntityRepository <Owner>(new ApplicationDbContext(options.Options));

            var ownersService = new OwnersService(userRepository, ownerRepository, dogsitterRepository);

            var user = new ApplicationUser();

            await ownersService.CreateOwnerAsync(user, Info, Info, Info, Info, Gender.Male, Info, Info, user.Id, Info);

            await ownersService.UpdateCurrentLoggedInUserInfoAsync(user.Id, "NewName", Info, Info, Info, Info, Info);

            var owner = ownersService.GetOwnerById(user.Id);

            Assert.Equal("NewName", owner.FirstName);
        }
Esempio n. 5
0
        public async void OwnerCommentsShouldReturnProperCount()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var commentsRepository   = new EfDeletableEntityRepository <Comment>(new ApplicationDbContext(options.Options));
            var ratingsRepository    = new EfDeletableEntityRepository <Rating>(new ApplicationDbContext(options.Options));
            var ownersRepository     = new EfDeletableEntityRepository <Owner>(new ApplicationDbContext(options.Options));
            var dogsittersRepository = new EfDeletableEntityRepository <Dogsitter>(new ApplicationDbContext(options.Options));
            var usersRepository      = new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options));

            var commentsService = new CommentsService(commentsRepository, ratingsRepository, ownersRepository);
            var ownersService   = new OwnersService(usersRepository, ownersRepository, dogsittersRepository);

            var dogsitter = new Dogsitter();

            var user = new ApplicationUser
            {
                Dogsitter = dogsitter,
                UserName  = User,
                Email     = User,
            };

            var user2 = new ApplicationUser
            {
                UserName = User2,
                Email    = User2,
            };

            dogsitter.UserId = user.Id;

            var rating = new Rating
            {
                Score       = 5,
                Dogsitter   = dogsitter,
                DogsitterId = dogsitter.Id,
                SentBy      = SentByDogsitter,
            };

            var comment = new Comment
            {
                Content     = CommentContent,
                RatingScore = rating.Score,
                Dogsitter   = dogsitter,
                DogsitterId = dogsitter.Id,
                SentBy      = SentByDogsitter,
            };

            await ownersService.CreateOwnerAsync(user2, FillInfo, FillInfo, FillInfo, FillInfo, Gender.Female, FillInfo, FillInfo, user2.Id, FillInfo);

            var owner = ownersRepository.All().FirstOrDefault();

            rating.Owner    = owner;
            rating.OwnerId  = owner.Id;
            comment.Owner   = owner;
            comment.OwnerId = owner.Id;
            user2.Owner     = owner;

            await commentsService.SubmitFeedback(comment, rating);

            var ownerComments = commentsService.OwnerComments(user2.Id);

            Assert.Single(ownerComments);
        }