public void SignUpAndLogin()
        {
            AdressDTO address = new AdressDTO();

            address.latitude  = 50;
            address.longitude = 30;
            address.address   = "Beautiful city";

            SignUpAccountDTO account = new SignUpAccountDTO();

            account.FirstName = "Ion";
            account.LastName  = "Popescu";
            account.UserName  = "******";
            account.Email     = "*****@*****.**";
            account.Adress    = address;
            account.Password  = "******";


            SignUpAccountService signUpAccountService = new SignUpAccountService();

            signUpAccountService.addAccount(account);

            AccountService accountService = new AccountService();

            AccountSimpleDTO login = accountService.Login("Popescu", "123456");

            accountService.deleteAccount(login.Id);

            Assert.IsNotNull(login);
            Assert.AreEqual(login.FullName, account.LastName + " " + account.FirstName);
        }
Beispiel #2
0
        public IHttpActionResult Post(SignUpAccountDTO account)
        {
            var accountService         = new SignUpAccountService();
            AccountSimpleDTO accountVM = accountService.addAccount(account);

            if (accountVM == null)
            {
                return(NotFound());
            }

            return(Ok(accountVM));
        }
        public void AddRemoveFriend()
        {
            SignUpAccountService signUpAccountService = new SignUpAccountService();
            AccountService       accountService       = new AccountService();
            FriendshipService    frService            = new FriendshipService();

            AdressDTO address = new AdressDTO();

            address.latitude  = 50;
            address.longitude = 30;
            address.address   = "Beautiful city";

            SignUpAccountDTO account = new SignUpAccountDTO();

            account.FirstName = "Ion";
            account.LastName  = "Popescu";
            account.UserName  = "******";
            account.Email     = "*****@*****.**";
            account.Adress    = address;
            account.Password  = "******";

            SignUpAccountDTO account1 = new SignUpAccountDTO();

            account1.FirstName = "Dfsadsa";
            account1.LastName  = "Ddsadsad";
            account1.UserName  = "******";
            account1.Email     = "*****@*****.**";
            account1.Adress    = address;
            account1.Password  = "******";



            AccountSimpleDTO acc  = signUpAccountService.addAccount(account);
            AccountSimpleDTO acc1 = signUpAccountService.addAccount(account1);

            frService.AddFriend(acc.Id, acc1.Id);

            var friends = frService.GetAllFriendships(acc.Id);

            FriendshipDTO friendship = friends.Where(fr => (fr.UserOne.Id == acc1.Id | fr.UserTwo.Id == acc1.Id)).FirstOrDefault();

            frService.RemoveFriendship(friendship.Id);

            var friends1 = frService.GetAllFriendships(acc.Id);

            FriendshipDTO friendship1 = friends1.Where(fr => (fr.UserOne.Id == acc1.Id | fr.UserTwo.Id == acc1.Id)).FirstOrDefault();

            accountService.deleteAccount(acc.Id);
            accountService.deleteAccount(acc1.Id);

            Assert.IsNotNull(friendship);
            Assert.IsNull(friendship1);
        }
Beispiel #4
0
        public IHttpActionResult Get(int id)
        {
            var accountSignUpService = new SignUpAccountService();

            SignUpAccountDTO accountVM = accountSignUpService.getAccountById(id);

            if (accountVM == null)
            {
                return(NotFound());
            }

            return(Ok(accountVM));
        }
        public SignUpAccountDTO MapToDTO(Account source)
        {
            SignUpAccountDTO target = new SignUpAccountDTO();

            target.Id        = source.Id;
            target.FirstName = source.FirstName;
            target.LastName  = source.LastName;
            target.UserName  = source.UserName;
            target.Email     = source.Email;
            target.Password  = source.UserPassword;
            AdressMapper adressMapper = new AdressMapper();

            target.Adress = adressMapper.MapToDTO(source.Adress);
            return(target);
        }
        public Account MapFromDTO(SignUpAccountDTO source)
        {
            Account target = new Account();

            target.Id           = source.Id;
            target.FirstName    = source.FirstName;
            target.LastName     = source.LastName;
            target.UserName     = source.UserName;
            target.Email        = source.Email;
            target.UserPassword = source.Password;
            AdressMapper adressMapper = new AdressMapper();

            target.Adress = adressMapper.MapFromDTO(source.Adress);
            return(target);
        }
        public SignUpAccountDTO getAccountById(int id)
        {
            using (var uow = new UnitOfWork())
            {
                var     accountRepository = uow.GetRepository <Account>();
                var     adressRepository  = uow.GetRepository <Adress>();
                Account account           = accountRepository.GetById(id);

                if (account == null)
                {
                    return(null);
                }

                Adress adress = adressRepository.GetById(account.AdressId);
                SignUpAccountMapper accountMapper = new SignUpAccountMapper();
                SignUpAccountDTO    accountVM     = accountMapper.MapToDTO(account);
                return(accountVM);
            }
        }
        public SignUpAccountDTO editAccount(SignUpAccountDTO accountVM)
        {
            using (var uow = new UnitOfWork())
            {
                var accountRepository = uow.GetRepository <Account>();
                var addressRepository = uow.GetRepository <Adress>();

                var accUser  = accountRepository.FindBy(ac => ac.UserName == accountVM.UserName);
                var accEmail = accountRepository.FindBy(ac => ac.Email == accountVM.Email);

                if ((accUser.Count() == 1 && accUser.FirstOrDefault().Id != accountVM.Id) | (accEmail.Count() == 1 && accEmail.FirstOrDefault().Id != accountVM.Id))
                {
                    return(null);
                }


                AdressMapper addressMapper = new AdressMapper();
                var          queryaddress  = addressRepository.FindBy(ad => ad.latitude == accountVM.Adress.latitude & ad.longitude == accountVM.Adress.longitude);
                Adress       address       = queryaddress.FirstOrDefault();



                Account account = accountRepository.GetById(accountVM.Id);
                if (address == null)
                {
                    addressRepository.Add(addressMapper.MapFromDTO(accountVM.Adress));
                    uow.SaveChanges();
                }

                address              = addressRepository.FindBy(ad => ad.latitude == accountVM.Adress.latitude & ad.longitude == accountVM.Adress.longitude).FirstOrDefault();
                account.AdressId     = address.Id;
                account.Adress       = address;
                account.LastName     = accountVM.LastName;
                account.FirstName    = accountVM.FirstName;
                account.Email        = accountVM.Email;
                account.UserName     = accountVM.UserName;
                account.UserPassword = accountVM.Password;
                accountRepository.Edit(account);
                uow.SaveChanges();
                return(accountVM);
            }
        }
Beispiel #9
0
        public IHttpActionResult Put(SignUpAccountDTO suaccountVM)
        {
            if (ModelState.IsValid)
            {
                var accountSignUpService = new SignUpAccountService();

                SignUpAccountDTO accountVM = accountSignUpService.editAccount(suaccountVM);

                if (accountVM == null)
                {
                    return(NotFound());
                }

                return(Ok(accountVM));
            }
            else
            {
                return(BadRequest("The model is not valid"));
            }
        }
        public void AddAccountWithTheSameUserName()
        {
            AdressDTO address = new AdressDTO();

            address.latitude  = 50;
            address.longitude = 30;
            address.address   = "Beautiful city";

            SignUpAccountDTO account = new SignUpAccountDTO();

            account.FirstName = "Ion";
            account.LastName  = "Popescu";
            account.UserName  = "******";
            account.Email     = "*****@*****.**";
            account.Adress    = address;
            account.Password  = "******";


            SignUpAccountService signUpAccountService = new SignUpAccountService();
            AccountSimpleDTO     account1             = signUpAccountService.addAccount(account);

            SignUpAccountDTO account2 = new SignUpAccountDTO();

            account2.FirstName = "Ion";
            account2.LastName  = "Rotari";
            account2.UserName  = "******";
            account2.Email     = "*****@*****.**";
            account2.Adress    = address;
            account2.Password  = "******";

            AccountSimpleDTO account3 = signUpAccountService.addAccount(account2);

            AccountService accountService = new AccountService();

            accountService.deleteAccount(account1.Id);

            Assert.IsNotNull(account1);
            Assert.IsNull(account3);
        }
        public AccountSimpleDTO addAccount(SignUpAccountDTO accountVM)
        {
            using (var uow = new UnitOfWork())
            {
                var           accountRepository = uow.GetRepository <Account>();
                var           adressRepository  = uow.GetRepository <Adress>();
                AdressService addressService    = new AdressService();

                SignUpAccountMapper accountMaper = new SignUpAccountMapper();
                Account             account      = accountMaper.MapFromDTO(accountVM);

                var queryAccounts = accountRepository.FindBy(ac => ac.UserName == accountVM.UserName | ac.Email == accountVM.Email);
                var existAc       = queryAccounts.FirstOrDefault();

                if (existAc == null)
                {
                    var queryAddress = adressRepository.FindBy(ad => ad.latitude == accountVM.Adress.latitude &
                                                               ad.longitude == accountVM.Adress.longitude);
                    var existAd = queryAddress.FirstOrDefault();

                    if (existAd != null)
                    {
                        account.Adress = existAd;
                    }
                }
                else
                {
                    return(null);
                }

                accountRepository.Add(account);
                uow.SaveChanges();

                AccountSimpleMapper simpleAccountMapper = new AccountSimpleMapper();
                return(simpleAccountMapper.MapToDTO(account));
            }
        }
        public void EditAccount()
        {
            AdressDTO address = new AdressDTO();

            address.latitude  = 50;
            address.longitude = 30;
            address.address   = "Beautiful city";

            SignUpAccountDTO account = new SignUpAccountDTO();

            account.FirstName = "Ion";
            account.LastName  = "Popescu";
            account.UserName  = "******";
            account.Email     = "*****@*****.**";
            account.Adress    = address;
            account.Password  = "******";


            SignUpAccountService signUpAccountService = new SignUpAccountService();
            AccountSimpleDTO     ac = signUpAccountService.addAccount(account);

            AccountService accountService = new AccountService();

            SignUpAccountDTO acc = signUpAccountService.getAccountById(ac.Id);

            acc.LastName       = "Casap";
            acc.Adress.address = "Cluj";

            acc = signUpAccountService.editAccount(acc);

            accountService.deleteAccount(ac.Id);

            Assert.IsNotNull(acc);
            Assert.AreEqual(acc.LastName, "Casap");
            Assert.AreEqual(acc.Adress.address, "Cluj");
        }
            public void AddMessageTest()
            {
                SignUpAccountService signUpAccountService = new SignUpAccountService();
                AccountService       accountService       = new AccountService();
                MessengerService     mesService           = new MessengerService();

                AdressDTO address = new AdressDTO();

                address.latitude  = 50;
                address.longitude = 30;
                address.address   = "Beautiful city";

                SignUpAccountDTO account = new SignUpAccountDTO();

                account.FirstName = "Ion";
                account.LastName  = "Popescu";
                account.UserName  = "******";
                account.Email     = "*****@*****.**";
                account.Adress    = address;
                account.Password  = "******";

                SignUpAccountDTO account1 = new SignUpAccountDTO();

                account1.FirstName = "Dfsadsa";
                account1.LastName  = "Ddsadsad";
                account1.UserName  = "******";
                account1.Email     = "*****@*****.**";
                account1.Adress    = address;
                account1.Password  = "******";



                AccountSimpleDTO acc  = signUpAccountService.addAccount(account);
                AccountSimpleDTO acc1 = signUpAccountService.addAccount(account1);


                ConversationDTO conv = new ConversationDTO();

                conv.UserOne = acc;
                conv.UserTwo = acc1;

                conv = mesService.CreateConversation(conv);

                MessageDTO message = new MessageDTO();

                message.User           = acc;
                message.ConversationId = conv.Id;
                message.Text           = "Salut";
                message.Date           = DateTime.Now;

                message = mesService.addMessage(message);

                var messages = mesService.GetMessages(5, 1, acc.Id, acc1.Id);

                MessageDTO myMes = messages.FirstOrDefault();

                mesService.deleteMessage(message.Id);
                mesService.RemoveConversation(conv.Id);
                accountService.deleteAccount(acc.Id);
                accountService.deleteAccount(acc1.Id);


                Assert.IsNotNull(message);
                Assert.IsNotNull(conv);
                Assert.IsNotNull(messages);
                Assert.AreEqual(myMes.Text, "Salut");
            }