Пример #1
0
        public void AddExistingAddressToDifferentUserTest()
        {
            Address a = new Address();

            a.Street       = "Cartagena";
            a.StreetNumber = "1582";
            a.PhoneNumber  = "26003564";

            Address a2 = new Address();

            a2.Street       = "Cartagena";
            a2.StreetNumber = "1582";
            a2.PhoneNumber  = "26003564";
            AddressService service = getService();
            User           u       = getUser();
            User           u2      = getOtherUser();

            service.AddAddress(a, u);
            service.AddAddress(a2, u2);

            GenericRepository <User> ur = getUserRepo();
            User savedUserOne           = ur.Get(u.Id);
            User savedUserTwo           = ur.Get(u2.Id);


            List <Address> userOneAddresses = savedUserOne.Addresses.ToList();
            List <Address> userTwoAddresses = savedUserTwo.Addresses.ToList();


            bool userOneHasAddress = userOneAddresses.Exists(address => address.Id == a.Id);
            bool userTwoHasAddress = userTwoAddresses.Exists(address => address.Id == a.Id);

            Assert.IsTrue(userOneHasAddress);
            Assert.IsTrue(userTwoHasAddress);
        }
Пример #2
0
        public void Not_Add_IfAddress_Exists()
        {
            var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "Not_Add_IfAddress_Exists")
                                 .Options;
            var validationMock = new Mock <CommonValidations>();

            string streetAddress1 = "str test 1";
            string streetAddress2 = "str test 1";

            // Act
            using (var actContext = new LibrarySystemContext(contextOptions))
            {
                var unit = new UnitOfWork(actContext);
                var repo = unit.GetRepo <Address>();

                var service = new AddressService(unit, validationMock.Object);

                service.AddAddress(streetAddress1, 1);
                service.AddAddress(streetAddress2, 1);
            }

            // Assert
            using (var assertContext = new LibrarySystemContext(contextOptions))
            {
                var unit = new UnitOfWork(assertContext);
                var repo = unit.GetRepo <Address>();

                var service = new AddressService(unit, validationMock.Object);

                int count = assertContext.Addresses.Count();
                Assert.AreEqual(1, count);
                Assert.AreEqual(streetAddress1, assertContext.Addresses.First().StreetAddress);
            }
        }
Пример #3
0
        public void AddressDeleteListAddressOkTest()
        {
            Address a = new Address();

            a.Street       = "Cartagena";
            a.StreetNumber = "1582";
            a.PhoneNumber  = "26003564";

            Address a2 = new Address();

            a2.Street       = "Maximo Tajes";
            a2.StreetNumber = "2221";
            a2.PhoneNumber  = "26000000";

            AddressService service = getService();
            User           u       = getUser();

            service.AddAddress(a, u);
            service.AddAddress(a2, u);

            service.RemoveAddress(a2.Id, u);
            List <Address> allAddresses = service.GetAllAddresses(u);
            Address        deleted      = allAddresses.Find(address => address.Id == a2.Id);

            Assert.IsNull(deleted);
        }
Пример #4
0
 private void AddSession()
 {
     if (MessageBox.Show("Are you sure", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         var sessions = SessionService.GetAllSessions().Where(d => d.CourseId == SelectedCourse.Id);
         if (ScheduleConflict(sessions))
         {
             //if Session Start is within Start and End of existing session for the same course - there is a schedule conflict and the operation must not be allowed
             MessageBox.Show("Schedule Conflict");
             return;
         }
         //create location from strings
         var address = AddressService.AddAddress(new Address()
         {
             ZipCode = VenueAddress,
         });
         var location = LocationService.AddLocation(new Location()
         {
             Address  = address,
             Capacity = VenueCapacity
         });
         Session = SessionService.AddSession(Session);
         var sessionLocation = SessionLocationService.Add(new Session_Location()
         {
             Session  = Session,
             Location = location
         });
         BackProc();
     }
 }
Пример #5
0
        public void Throw_Exeption_IfUser_IsDeleted()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "Change_User_Address")
                                 .Options;
            string firstName        = "Ivan1",
                   middleName       = "Ivanov1",
                   lastName         = "Ivanov1",
                   phoneNumber      = "1234567899";
            DateTime addOnDate      = DateTime.Now;
            bool     isDeleted      = false;
            var      validationMock = new Mock <CommonValidations>();

            using (var actContext = new LibrarySystemContext(contextOptions))
            {
                var unit           = new UnitOfWork(actContext);
                var townService    = new TownService(unit, validationMock.Object);
                var addressService = new AddressService(unit, validationMock.Object);
                var userService    = new UsersServices(unit, validationMock.Object);
                var town           = townService.AddTown("test");
                var address        = addressService.AddAddress("test address", town);

                //Act & Assert
                userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address);
                userService.RemoveUser(firstName, middleName, lastName);
                userService.UpdateUserAddress(firstName, middleName, lastName, 3);
            }
        }
Пример #6
0
        public IActionResult AddAddress(AddressInputModel address)
        {
            var currentUser = _userManager.GetUserId(HttpContext.User);

            _addressService.AddAddress(address, currentUser);

            return(RedirectToAction("Address"));
        }
Пример #7
0
        public JsonResult AddAddress(Address address)
        {
            int cmd = -1;

            cmd = _addressService.AddAddress(address);

            string result = (cmd > 0) ? "Added" : "Add Failed";

            return(new JsonResult(result));
        }
Пример #8
0
 private void AddAddress()
 {
     AddressService.AddAddress(new Address()
     {
         ZipCode  = $"{random.Next()}",
         City     = "City",
         Province = "Province",
         Street   = "Street"
     });
 }
Пример #9
0
        public void AddressAddSameToUserTest()
        {
            Address a = new Address();

            a.Street       = "Cartagena";
            a.StreetNumber = "1582";
            a.PhoneNumber  = "26003564";

            Address a2 = new Address();

            a2.Street       = "Cartagena";
            a2.StreetNumber = "1582";
            a2.PhoneNumber  = "26003564";

            AddressService service = getService();
            User           u       = getUser();

            service.AddAddress(a, u);
            service.AddAddress(a2, u);
        }
Пример #10
0
        public void AddressCreateNoPhoneNumberTest()
        {
            Address a = new Address();

            a.Street       = "Cartagena";
            a.StreetNumber = "1582";
            AddressService service = getService();
            User           u       = getUser();

            service.AddAddress(a, u);
        }
Пример #11
0
        public void AddressCreateNoStreetTest()
        {
            Address a = new Address();

            a.StreetNumber = "1582";
            a.PhoneNumber  = "26003564";
            AddressService service = getService();
            User           u       = getUser();

            service.AddAddress(a, u);
        }
Пример #12
0
        public void AddressAddMultipleToOneUserTest()
        {
            Address a = new Address();

            a.Street       = "Cartagena";
            a.StreetNumber = "1582";
            a.PhoneNumber  = "26003564";

            Address a2 = new Address();

            a2.Street       = "Miami";
            a2.StreetNumber = "2222";
            a2.PhoneNumber  = "26203564";

            Address a3 = new Address();

            a3.Street       = "Cooper";
            a3.StreetNumber = "1111";
            a3.PhoneNumber  = "26204564";


            AddressService service = getService();
            User           u       = getUser();

            service.AddAddress(a, u);
            service.AddAddress(a2, u);
            service.AddAddress(a3, u);

            GenericRepository <User> ur = getUserRepo();
            User savedUser = ur.Get(u.Id);

            List <Address> userOneAddresses    = savedUser.Addresses.ToList();
            bool           userHasAddressOne   = userOneAddresses.Exists(address => address.Id == a.Id);
            bool           userHasAddressTwo   = userOneAddresses.Exists(address => address.Id == a2.Id);
            bool           userHasAddressThree = userOneAddresses.Exists(address => address.Id == a3.Id);


            Assert.IsTrue(userHasAddressOne);
            Assert.IsTrue(userHasAddressTwo);
            Assert.IsTrue(userHasAddressThree);
        }
Пример #13
0
        public void GetAllFromUser()
        {
            AddressService service = getService();
            User           u       = getUser();
            Address        a       = new Address();

            a.Street       = "Cartagena";
            a.StreetNumber = "1582";
            a.PhoneNumber  = "26003564";

            Address a2 = new Address();

            a2.Street       = "Maximo Tajes";
            a2.StreetNumber = "2221";
            a2.PhoneNumber  = "26000000";
            service.AddAddress(a, u);
            service.AddAddress(a2, u);
            List <Address> allAddresses = service.GetAllAddresses(u);

            Assert.AreEqual(3, allAddresses.Count);
        }
Пример #14
0
        public void AddressDeleteUserDoesntHaveTest()
        {
            AddressService service = getService();
            User           u       = getUser();
            User           u2      = getOtherUser();
            Address        a       = new Address();

            a.Street       = "Cartagena";
            a.StreetNumber = "1582";
            a.PhoneNumber  = "26003564";
            service.AddAddress(a, u);
            service.RemoveAddress(a.Id, u2);
        }
Пример #15
0
        public async Task <ActionResult <DTOAddress> > AddAddress(DTOAddress address)
        {
            bool success = await _service.AddAddress(address);

            if (success)
            {
                return(CreatedAtAction("GetAddress", new { id = address.AddressID }, address));
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #16
0
        public void AddTest()
        {
            var random = new Random();

            var randomAddress       = AddressService.AddAddress(new Address());
            var randomCandidate     = CandidateService.AddCandidate(new Candidate());
            var newAddressCandidate = new Address_Candidate()
            {
                Candidate = randomCandidate,
                Address   = randomAddress
            };

            AddressCandidate = AddressCandidateService.AddAddressToCandidate(newAddressCandidate);
            Address          = AddressCandidate.Address;
            Candidate        = AddressCandidate.Candidate;
        }
Пример #17
0
        public void AddressDeleteDefaultOk()
        {
            AddressService service = getService();
            User           u       = getUser();

            Address a = new Address();

            a.Street       = "Cartagena";
            a.StreetNumber = "1582";
            a.PhoneNumber  = "26003564";

            service.AddAddress(a, u);
            service.RemoveAddress(u.Address.Id, u);

            Assert.AreEqual(u.Address.Id, a.Id);
        }
Пример #18
0
        public void Get_User_FromDatabase_IfUser_Exists()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "Get_User_FromDatabase")
                                 .Options;

            string firstName   = "Ivan",
                   middleName  = "Ivanov",
                   lastName    = "Ivanov",
                   phoneNumber = "1234567899";
            DateTime addOnDate = DateTime.Now;
            bool     isDeleted = false;

            string fullName = firstName + " " + middleName + " " + lastName;

            var validationMock = new Mock <CommonValidations>();

            using (var actContext = new LibrarySystemContext(contextOptions))
            {
                var unit = new UnitOfWork(actContext);

                var townService    = new TownService(unit, validationMock.Object);
                var addressService = new AddressService(unit, validationMock.Object);
                var userService    = new UsersServices(unit, validationMock.Object);

                var town    = townService.AddTown("test");
                var address = addressService.AddAddress("test address", town);

                userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address);
            }
            using (var assertContext = new LibrarySystemContext(contextOptions))
            {
                var unit        = new UnitOfWork(assertContext);
                var userService = new UsersServices(unit, validationMock.Object);

                //Act
                var getUser = userService.GetUser(firstName, middleName, lastName);
                //Assert
                Assert.AreEqual(fullName, getUser.FullName);
            }
        }
Пример #19
0
        public void AddressCreateOkTest()
        {
            AddressService service = getService();
            User           u       = getUser();
            Address        a1      = new Address();

            a1.Street       = "Copacabana";
            a1.StreetNumber = "3345";
            a1.PhoneNumber  = "26001564";

            service.AddAddress(a1, u);
            Assert.AreNotEqual(Guid.Empty, a1.Id);

            GenericRepository <User> ur  = getUserRepo();
            User           savedUser     = ur.Get(u.Id);
            List <Address> userAddresses = savedUser.Addresses.ToList();
            bool           hasAddress    = userAddresses.Exists(address => address.Id == a1.Id);

            Assert.IsTrue(hasAddress);
        }
Пример #20
0
        public void AddAddress_Success_Test()
        {
            // Arrange
            AddressDTO dto = SampleAddressDTO(1);

            // create mock for repository
            var mock = new Mock <IAddressRepository>();

            mock.Setup(s => s.AddAddress(Moq.It.IsAny <R_Address>())).Returns(1);

            // service
            AddressService addressService = new AddressService();

            AddressService.Repository = mock.Object;

            // Act
            int id = addressService.AddAddress(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.AddressId);
        }
Пример #21
0
 public ActionResult AddAddress(AddressVM vm)
 {
     if (ModelState.IsValid)
     {
         Mapper.Initialize(cfg => cfg.CreateMap <AddressVM, AddressDTO>());
         var addressDto = Mapper.Map <AddressVM, AddressDTO>(vm);
         var res        = _addressService.AddAddress(User.Identity.GetUserId(), addressDto);
         if (res.Succedeed)
         {
             return(RedirectToAction("AddressBook"));
         }
         else
         {
             ModelState.AddModelError(res.Property, res.Message);
             return(View(vm));
         }
     }
     else
     {
         return(View(vm));
     }
 }
Пример #22
0
        private void AddAddresses()
        {
            ////if string changed - add new, remove old
            ////if string empty - remove old
            if (!(string.IsNullOrEmpty(Address1.City) && string.IsNullOrEmpty(Address1.ZipCode) && string.IsNullOrEmpty(Address1.Street) && string.IsNullOrEmpty(Address1.Province)))
            {
                Address1 = AddressService.AddAddress(Address1);

                AddressCandidateService.AddAddressToCandidate(new Address_Candidate()
                {
                    Address   = Address1,
                    Candidate = Candidate
                });
            }
            //remove old address
            if (!(string.IsNullOrEmpty(Address2.City) && string.IsNullOrEmpty(Address2.ZipCode) && string.IsNullOrEmpty(Address2.Street) && string.IsNullOrEmpty(Address2.Province)))
            {
                Address2 = AddressService.AddAddress(Address2);

                AddressCandidateService.AddAddressToCandidate(new Address_Candidate()
                {
                    Address   = Address2,
                    Candidate = Candidate
                });
            }

            //remove old address
            if (!(string.IsNullOrEmpty(Address3.City) && string.IsNullOrEmpty(Address3.ZipCode) && string.IsNullOrEmpty(Address3.Street) && string.IsNullOrEmpty(Address3.Province)))
            {
                Address3 = AddressService.AddAddress(Address3);

                AddressCandidateService.AddAddressToCandidate(new Address_Candidate()
                {
                    Address   = Address3,
                    Candidate = Candidate
                });
            }
        }
Пример #23
0
        public void Add_User_ToDatabase()
        {
            //Arrange
            var contextOptions = new DbContextOptionsBuilder <LibrarySystemContext>()
                                 .UseInMemoryDatabase(databaseName: "Add_User_ToDatabase")
                                 .Options;

            string firstName        = "Ivan",
                   middleName       = "Ivanov",
                   lastName         = "Ivanov",
                   phoneNumber      = "1234567899";
            DateTime addOnDate      = DateTime.Now;
            bool     isDeleted      = false;
            var      validationMock = new Mock <CommonValidations>();

            using (var actContext = new LibrarySystemContext(contextOptions))
            {
                var unit = new UnitOfWork(actContext);

                var townService    = new TownService(unit, validationMock.Object);
                var addressService = new AddressService(unit, validationMock.Object);
                var userService    = new UsersServices(unit, validationMock.Object);

                var town    = townService.AddTown("test");
                var address = addressService.AddAddress("test address", town);

                //Act
                userService.AddUser(firstName, middleName, lastName, phoneNumber, addOnDate, isDeleted, address);
            }
            // Assert
            using (var assertContext = new LibrarySystemContext(contextOptions))
            {
                int count = assertContext.Users.Count();
                Assert.AreEqual(1, count);
                Assert.AreEqual(firstName, assertContext.Users.First().FirstName);
            }
        }
Пример #24
0
        private void UpdateCandidateAddresses()
        {
            ////if string changed - add new, remove old
            ////if string empty - remove old
            if (NewAddress1.FullAddress != OldAddress1.FullAddress)
            {
                if (!(string.IsNullOrEmpty(NewAddress1.City) && string.IsNullOrEmpty(NewAddress1.ZipCode) && string.IsNullOrEmpty(NewAddress1.Street) && string.IsNullOrEmpty(NewAddress1.Province)))
                {
                    NewAddress1 = AddressService.AddAddress(NewAddress1);

                    AddressCandidateService.AddAddressToCandidate(new Address_Candidate()
                    {
                        Address   = NewAddress1,
                        Candidate = NewCandidate
                    });
                }
                //remove old address
                AddressCandidateService.RemoveAddressFromCandidate(OldAddress1.Id, NewCandidate.Id);
            }

            if (NewAddress2.FullAddress != OldAddress2.FullAddress)
            {
                if (!(string.IsNullOrEmpty(NewAddress2.City) && string.IsNullOrEmpty(NewAddress2.ZipCode) && string.IsNullOrEmpty(NewAddress2.Street) && string.IsNullOrEmpty(NewAddress2.Province)))
                {
                    NewAddress2 = AddressService.AddAddress(NewAddress2);

                    AddressCandidateService.AddAddressToCandidate(new Address_Candidate()
                    {
                        Address   = NewAddress2,
                        Candidate = NewCandidate
                    });
                }

                //remove old address
                AddressCandidateService.RemoveAddressFromCandidate(OldAddress2.Id, NewCandidate.Id);
            }
            if (NewAddress3.FullAddress != OldAddress3.FullAddress)
            {
                if (!(string.IsNullOrEmpty(NewAddress3.City) && string.IsNullOrEmpty(NewAddress3.ZipCode) && string.IsNullOrEmpty(NewAddress3.Street) && string.IsNullOrEmpty(NewAddress3.Province)))
                {
                    NewAddress3 = AddressService.AddAddress(NewAddress3);

                    AddressCandidateService.AddAddressToCandidate(new Address_Candidate()
                    {
                        Address   = NewAddress3,
                        Candidate = NewCandidate
                    });
                }

                //remove old address
                AddressCandidateService.RemoveAddressFromCandidate(OldAddress3.Id, NewCandidate.Id);
            }
            //if (Address2 != OldAddress2)
            //{
            //    var newAddress = AddressService.AddAddress(new Address()
            //    {
            //        ZipCode = Address2
            //        //TODO make way to parse Address object from strings
            //    });

            //    AddressCandidateService.AddAddressToCandidate(new Address_Candidate()
            //    {
            //        Address = newAddress,
            //        Candidate = NewCandidate
            //    });
            //    //remove old address
            //    AddressCandidateService.RemoveAddressFromCandidate(OldCandidate.Addresses.Where(d => d.CandidateId == OldCandidate.Id).ToList()[1].AddressId, OldCandidate.Id);
            //}

            //if (Address3 != OldAddress3)
            //{
            //    var newAddress = AddressService.AddAddress(new Address()
            //    {
            //        ZipCode = Address3
            //        //TODO make way to parse Address object from strings
            //    });

            //    AddressCandidateService.AddAddressToCandidate(new Address_Candidate()
            //    {
            //        Address = newAddress,
            //        Candidate = NewCandidate
            //    });

            //    //remove old address
            //    AddressCandidateService.RemoveAddressFromCandidate(OldCandidate.Addresses.Where(d => d.CandidateId == OldCandidate.Id).ToList()[2].AddressId, OldCandidate.Id);
            //}



            //if (string.IsNullOrEmpty(Address1))
            //{
            //    //remove old address
            //    AddressCandidateService.RemoveAddressFromCandidate(OldCandidate.Addresses.Where(d => d.CandidateId == OldCandidate.Id).ToList()[0].AddressId, OldCandidate.Id);
            //}

            //if (string.IsNullOrEmpty(Address2))
            //{
            //    //remove old address
            //    AddressCandidateService.RemoveAddressFromCandidate(OldCandidate.Addresses.Where(d => d.CandidateId == OldCandidate.Id).ToList()[1].AddressId, OldCandidate.Id);
            //}

            //if (string.IsNullOrEmpty(Address3))
            //{
            //    //remove old address
            //    AddressCandidateService.RemoveAddressFromCandidate(OldCandidate.Addresses.Where(d => d.CandidateId == OldCandidate.Id).ToList()[2].AddressId, OldCandidate.Id);
            //}
        }
Пример #25
0
 public Task <HttpResponseMessage> OnAddAddress([FromBody] Addresses json)
 {
     return(addressService.AddAddress(json));
 }