Esempio n. 1
0
        public async void GetOwnerApplicationUserShouldReturnCorrectUser()
        {
            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 owner = new Owner
            {
                User   = user,
                UserId = user.Id,
            };

            user.Owner = owner;
            await userRepository.AddAsync(user);

            await userRepository.SaveChangesAsync();

            var appUser = ownersService.GetOwnerApplicationUser(owner.Id);

            Assert.Equal(user.Id, appUser.Id);
        }
Esempio n. 2
0
        public async void GetDogsittersAsyncShouldReturnAllDogsitters()
        {
            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();

            var role = new ApplicationRole {
                Name = "Dogsitter", NormalizedName = "DOGSITTER",
            };

            user.Roles.Add(new IdentityUserRole <string> {
                UserId = user.Id, RoleId = role.Id
            });
            user2.Roles.Add(new IdentityUserRole <string> {
                UserId = user.Id, RoleId = role.Id
            });

            var dogsitters = ownersService.GetDogsittersAsync(new List <ApplicationUser> {
                user, user2
            });

            Assert.Equal(2, dogsitters.Count);
        }
Esempio n. 3
0
        private void ConnectToDatabase()
        {
            cs.LoadConnectionConfig();

            if (con != null && con.State == System.Data.ConnectionState.Open)
            {
                foreach (Form form in this.MdiChildren)
                {
                    form.Close();
                    form.Dispose();
                }

                con.Close();
            }

            if (!cs.IsEmpty())
            {
                con = new NpgsqlConnection(cs.GetConnectionString());

                try
                {
                    con.Open();
                    ownersService = new OwnersService(con);

                    SetCurrentOwner(ownersService.GetDefaultOwner());
                } catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                }
            }

            SetMenuChoices();
        }
Esempio n. 4
0
        public void OwnersRepositoryShouldBeEmptyUponInitialization()
        {
            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);

            Assert.Empty(ownerRepository.All());
        }
Esempio n. 5
0
        public static void TestFixtureSetup(TestContext context)
        {
            con = new NpgsqlConnection(cs);
            con.Open();

            ownersRepository = new OwnersRepository(con);
            ownersService    = new OwnersService(con);

            ownersRepository.Save(Owner1);
            ownersRepository.Save(Owner2);
            ownersRepository.Save(Owner3);
            ownersRepository.Flush();
        }
Esempio n. 6
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. 7
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. 8
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. 9
0
        public async void SendNotificationShouldSaveNotificationAccordingly()
        {
            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 dogsitter = new Dogsitter();
            var owner     = new Owner();

            await dogsitterRepository.AddAsync(dogsitter);

            await dogsitterRepository.SaveChangesAsync();

            await ownersService.SendNotification(dogsitter.Id, owner, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow);

            Assert.Equal(1, dogsitter.Notifications.Count);
        }
Esempio n. 10
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. 11
0
        public async void DogsitterDetailsByIdTemplateShouldReturnProperType()
        {
            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));

            AutoMapperConfig.RegisterMappings(typeof(ErrorViewModel).GetTypeInfo().Assembly);

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

            var dogsitter = new Dogsitter();

            await dogsitterRepository.AddAsync(dogsitter);

            await dogsitterRepository.SaveChangesAsync();

            var dogsitterDb = ownersService.DogsitterDetailsById <DogsitterInfoViewModel>(dogsitter.Id);

            Assert.IsType <DogsitterInfoViewModel>(dogsitterDb);
        }
Esempio n. 12
0
        public async void SendNotificationShouldHaveCorrectOwnerAndDogsitter()
        {
            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 dogsitter = new Dogsitter();
            var owner     = new Owner();

            await dogsitterRepository.AddAsync(dogsitter);

            await dogsitterRepository.SaveChangesAsync();

            await ownersService.SendNotification(dogsitter.Id, owner, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow);

            var trueOwnerDogsitter = dogsitter.Notifications.FirstOrDefault().OwnerId == owner.Id;

            Assert.True(trueOwnerDogsitter);
        }
 public OwnersController(OwnersService inspectorService, ILogger <OwnersController> logger)
 {
     _ownerService = inspectorService;
     _logger       = logger;
 }
 public OwnersControllerManager()
 {
     OwnersService = new OwnersService();
 }
Esempio n. 15
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);
        }