예제 #1
0
 static void Main(string[] args)
 {
     var repo = new PersonRepository("Data Source=.;Initial Catalog=Salutem.Database;Integrated Security=True;Pooling=False");
     repo.Add(new Entities.Person { Name = "test", LastName="fdf" });
     var data = repo.GetAllWithDeleted();
     foreach (var item in data)
     {
         Console.WriteLine(item.Name);
     }
     var upd = data.FirstOrDefault();
     upd.Name = "Changed";
     repo.Update(upd);
     Console.WriteLine();
     data = repo.GetAll();
     foreach (var item in data)
     {
         Console.WriteLine(item.Name);
     }
     Console.WriteLine();
     Console.WriteLine(repo.GetById(data.FirstOrDefault().ID).Name);
     Console.WriteLine();
     repo.Delete(data.Where(w => w.Name == "test").FirstOrDefault());
     Console.WriteLine();
     data = repo.GetAll();
     foreach (var item in data)
     {
         Console.WriteLine(item.Name);
     }
     Console.ReadKey();
 }
        public void CustomRepo_Added_TestPersons_Get_Ordered_Descending()
        {
            List<TestPerson> testPersons;

            using (IPersonRepository personRepository = new PersonRepository(new TestDatabaseContext()))
            {
                personRepository.Add(new TestPerson { Age = 28, Name = "Zebra" });
                personRepository.Add(new TestPerson { Age = 28, Name = "Adam" });
                personRepository.Add(new TestPerson { Age = 28, Name = "Fabian" });
                personRepository.Save();

                testPersons = personRepository.GetAll(orderBy: q => q.OrderByDescending(x => x.Name)).ToList();
            }

            Assert.IsNotNull(testPersons);
            Assert.IsTrue(testPersons[2].Name == "Adam");
            Assert.IsTrue(testPersons[1].Name == "Fabian");
            Assert.IsTrue(testPersons[0].Name == "Zebra");
        }
        public void Create_Contact_Not_Called_When_Existing_Contact_Found()
        {
            var xdbContactRepository = SetupXdbContactMock(LockAttemptStatus.Success);

            var personRepository = new PersonRepository(xdbContactRepository.Object, null);

            personRepository.Add(new Person() { Surname = "Mr Existing", FirstName = "Bob" });

            xdbContactRepository.Verify(t => t.CreateContact(It.IsAny<Person>()), Times.Never);
        }
예제 #4
0
        public void CanDeletePerson()
        {
            // Arrange
            var repository = new PersonRepository();
            var person1 = new Person { Age = 1, FirstName = "Zebra", Surname = "Zebra" };
            var person2 = new Person { Age = 1, FirstName = "Alpha", Surname = "Beta" };
            var person3 = new Person { Age = 1, FirstName = "MandM", Surname = "MandM" };

            //Act
            repository.Add(person1);
            repository.Add(person2);
            repository.Add(person3);
            repository.Delete(person2);

            // Assert
            Assert.AreEqual(repository.Count(), 2);
            Assert.IsTrue(repository.Contains(person3));
            Assert.IsTrue(repository.Contains(person1));
            Assert.IsFalse(repository.Contains(person2));
        }
        public void AddPerson()
        {
            var person = Person.CreatePerson(-1, "Test First", "Test Last", 21);

            // Act
            PersonRepository target = new PersonRepository(context);
            var result = target.Add(person);

            // Assert
            Assert.AreEqual(person, result);
        }
예제 #6
0
        public void CanAddAPerson()
        {
            // Arrange
            var repository = new PersonRepository();
            var person1 = new Person { Age = 1, FirstName = "Alpha", Surname = "Beta" };

            //Act
            repository.Add(person1);

            // Assert
            Assert.AreEqual(repository.ToList().First(), person1);
        }
예제 #7
0
 public ActionResult Register(Person person)
 {
     if (ModelState.IsValid)
     {
         PersonRepository personRepository = new PersonRepository();//получить доступ к репозиторию ОRM
         Jigoku.Core.Entities.Person dbPerson = new Jigoku.Core.Entities.Person{NickName = person.NickName, Password = person.Password, PrimaryMail = person.PrimaryMail, Projects = null, UserPhoto = null}; //создать объект "Пользователь"
         personRepository.Add(dbPerson); //добавить его в БД
         return View("UserInfo", person); //вернуть страницу с информацией о пользователе
     }
     else
     {
         return View("Register");
     }
 }
        private async void PerformDatabaseOperations()
        {
            DatabaseContext databaseContext = new DatabaseContext();
            IPersonRepository personRepository = new PersonRepository(databaseContext);
            IThingRepository thingRepository = new ThingRepository(databaseContext);

            personRepository.Add(new Person());
            thingRepository.Add(new Thing());

            personRepository.Save();

            List<Person> persons = await personRepository.GetAllASync().Result.ToListAsync();

            Console.WriteLine(persons.Count);
            personRepository.MyNewFunction(6);
            await personRepository.SaveASync();
            List<Person> allASync = await personRepository.GetAllASync().Result.ToListAsync();

            thingRepository.Dispose();
            personRepository.Dispose();
        }
        public void CustomRepo_Add_Without_Save_Entry_Does_Not_Exists()
        {
            List<TestPerson> testPersons;
            using (IPersonRepository personRepository = new PersonRepository(new TestDatabaseContext()))
            {
                personRepository.Add(new TestPerson());

                testPersons = personRepository.GetAll().ToList();
            }

            Assert.IsTrue(testPersons.Count == 0);
        }
예제 #10
0
        public void DataIsSortedUsingDefaultSortKey()
        {
            // Arrange
            var repository = new PersonRepository();
            var person1 = new Person {Age = 1, FirstName = "Alpha", Surname = "Beta"};
            var person2 = new Person { Age = 2, FirstName = "Aleph", Surname = "Bate" };
            var person3 = new Person { Age = 0, FirstName = "Aleph", Surname = "Bates" };

            //Act
            repository.Add(person1);
            repository.Add(person3);
            repository.Add(person2);

            // Assert
            Assert.AreEqual(repository.First(), person2);
            Assert.AreEqual(repository.Last(), person1);
        }
예제 #11
0
 public void Add(Person person)
 {
     _personRepository.Add(person);
 }
 public ActionResult Index(Person person)
 {
     PersonRepository.Add(person);
     return(RedirectToAction("DisplayPersonInfo", "Home", person));
 }
        public void CustomRepo_Update_Entry_Is_Updated()
        {
            TestPerson findByUpdated;

            using (IPersonRepository personRepository = new PersonRepository(new TestDatabaseContext()))
            {
                personRepository.Add(new TestPerson { Age = 28, Name = "Fabian" });
                personRepository.Save();

                TestPerson findBy = personRepository.GetSingle(x => x.Name == "Fabian");
                findBy.Name = "Claudio";

                personRepository.Update(findBy);
                personRepository.Save();

                findByUpdated = personRepository.GetSingle(x => x.Name == "Claudio");
            }

            Assert.IsNotNull(findByUpdated);
            Assert.IsTrue(findByUpdated.Name == "Claudio");
        }
예제 #14
0
 public void Post([FromBody] Person person) => _people.Add(person);
        public void CustomRepo_Delete_Entry_With_Id_Is_Deleted()
        {
            List<TestPerson> testPersons;

            using (IPersonRepository personRepository = new PersonRepository(new TestDatabaseContext()))
            {
                personRepository.Add(new TestPerson { Age = 28, Name = "Fabian" });
                personRepository.Save();

                TestPerson findBy = personRepository.GetSingle(x => x.Name == "Fabian");

                personRepository.Delete(findBy.Id);
                personRepository.Save();

                testPersons = personRepository.GetAll().ToList();
            }

            Assert.IsTrue(testPersons.Count == 0);
        }
예제 #16
0
 public void AddDefaultPerson()
 {
     PersonsVM.Add(new PersonViewModel(personRepo.Add("Specify FirstName", "Specify LastName", 0, "Specify Phone")));
     SelectedPersonViewModel = PersonsVM[PersonsVM.Count - 1];
 }
예제 #17
0
 public ActionResult Create(Person model)
 {
     model.RowGuid = Guid.NewGuid().ToString();
     db.Add(model);
     return(Redirect("Index"));
 }
예제 #18
0
 /// <summary>
 /// person region
 /// </summary>
 /// <param name="personDto"></param>
 public string AddPerson(PersonDto personDto)
 {
     try
     {
         string nationalIdentity = personDto.NationalIdentity;
         PersonRepository repository = new PersonRepository();
         if (repository.ActiveContext.Persons.Where(p => p.NationalIdentity == nationalIdentity).Count() != 0) return "person with this natinal identity is there ";
         personDto.CustomerId =
             repository.ActiveContext.Persons.Select(o => o.CustomerId).DefaultIfEmpty(0).Max() + 1;
         personDto.Id = Guid.NewGuid();
         Person person = new Person();
         person.InjectFrom<UnflatLoopValueInjection>(personDto);
         person.ContactInfo.InjectFrom<UnflatLoopValueInjection>(personDto);
         repository.Add(person);
         return "person is added successfully by customerId :" + personDto.CustomerId.ToString();
     }
     catch (Exception exception)
     {
         return exception.Message;
     }
 }
예제 #19
0
 public void AddPerson(Person person)
 {
     personRepository.Add(person);
 }
예제 #20
0
 public void Create_Complex_Account2()
 {
     PersonRepository context = new PersonRepository();
     Person person = PersonTest.CreatePerson();
     Customer customer = PersonTest.CreateCustomer(person);
     Lawyer lawyer = PersonTest.CreateLawyer(person);
     if (person != null)
     {
         context.Add(person);
     }
     /*            GeneralAccount generalAccount = CreateGeneralAccount();
     IndexAccount indexAccount = CreateIndexAccount();
     Account account = CreateAccount();
     indexAccount.Accounts.Add(account);
     generalAccount.IndexAccounts.Add(indexAccount);
     context.Add(generalAccount);
     CustomerRepository customerRepository = new CustomerRepository();
     customer.Accounts.Add(account);
     customerRepository.Add(customer);
     LawyerRepository lawyerRepository = new LawyerRepository();
     lawyer.Accounts.Add(account);
     lawyerRepository.Add(lawyer);*/
 }
예제 #21
0
 public int AddPerson(Person person)
 {
     return(_personRepository.Add(person));
 }