public ActionResult GetPeopleViaJsonDotNetActionResult()
        {
            var peopleRepository = new PeopleRepository();
            var people = peopleRepository.GetPeople();

            return new JsonNetResult { Data = people };
        }
Esempio n. 2
0
        private void AddRigManagerToChecklist(RigOapChecklist rigOapChecklist)
        {
            var rigManager = AdminCustomRepository.GetByName(VerifierRole.RigManager.ToString());

            if (rigManager != null && !string.IsNullOrEmpty(rigManager.Value))
            {
                var rmPassportId = rigManager.Value;
                var rmUser       = PeopleRepository.GetByLogin(rmPassportId);
                var rmOrder      = rigOapChecklist.VerifiedBy?.Count() + 100 ?? 100;

                if ((rigOapChecklist.VerifiedBy != null) && rigOapChecklist.VerifiedBy.Any())
                {
                    //Check if the Rig Manager User Exists
                    if (!rigOapChecklist.VerifiedBy.Any(v => v.UserId == rmUser.Id && v.Role.Equals(rigManager.Name, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        rigOapChecklist.VerifiedBy.Add(new RigOapChecklistVerifier()
                        {
                            Id = Guid.NewGuid(), RigOapChecklistId = rigOapChecklist.Id, Role = VerifierRole.RigManager.ToString(), isReviewer = true, UserId = rmUser.Id, Order = rmOrder
                        });
                    }
                }
                else
                {
                    rigOapChecklist.VerifiedBy = new List <RigOapChecklistVerifier>()
                    {
                        new RigOapChecklistVerifier()
                        {
                            Id = Guid.NewGuid(), RigOapChecklistId = rigOapChecklist.Id, Role = VerifierRole.RigManager.ToString(), isReviewer = true, UserId = rmUser.Id, Order = rmOrder
                        }
                    };
                }
            }
        }
        public ActionResult GetPeopleViaJson()
        {
            var peopleRepository = new PeopleRepository();
            var people = peopleRepository.GetPeople();

            return Json(people);
        }
        public ActionResult GetPeopleViaJsonDotNet()
        {
            var peopleRepository = new PeopleRepository();
            var people = peopleRepository.GetPeople();

            return Content(JsonConvert.SerializeObject(people), "application/json");
        }
        public ActionResult GetPeopleViaJsonDotNet()
        {
            var peopleRepository = new PeopleRepository();
            var people           = peopleRepository.GetPeople();

            return(Content(JsonConvert.SerializeObject(people), "application/json"));
        }
Esempio n. 6
0
        private IGrid <PersonModel> CreateExportableGrid()
        {
            IGrid <PersonModel> grid = new Grid <PersonModel>(PeopleRepository.GetPeople());

            grid.ViewContext = new ViewContext {
                HttpContext = HttpContext
            };
            grid.Query = Request.Query;

            grid.Columns.Add(model => model.Name).Titled("Name");
            grid.Columns.Add(model => model.Surname).Titled("Surname");

            grid.Columns.Add(model => model.Age).Titled("Age");
            grid.Columns.Add(model => model.Birthday).Titled("Birth date");
            grid.Columns.Add(model => model.IsWorking).Titled("Employed");

            grid.Pager = new GridPager <PersonModel>(grid);
            grid.Processors.Add(grid.Pager);
            grid.Pager.RowsPerPage = 6;

            foreach (IGridColumn column in grid.Columns)
            {
                column.IsFilterable = true;
                column.IsSortable   = true;
            }

            return(grid);
        }
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            nameTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            birthdayDatePicker.GetBindingExpression(DatePicker.SelectedDateProperty).UpdateSource();

            if (Validation.GetHasError(nameTextBox) || Validation.GetHasError(birthdayDatePicker))
            {
                MessageBox.Show("Please provide correct data");
            }
            else
            {
                if (IsEdited)
                {
                    CurrentPerson.Image    = TemporaryPerson.Image;
                    CurrentPerson.Name     = TemporaryPerson.Name;
                    CurrentPerson.Birthday = TemporaryPerson.Birthday;
                    PeopleRepository.Save();
                }
                else
                {
                    var defaultOccasions = new ObservableCollection <Occasion>()
                    {
                        OccasionsRepository.GetAll().SingleOrDefault(x => x.Name == "New Year"),
                        new Occasion {
                            Date  = TemporaryPerson.Birthday,
                            Image = ImageHelper.BitmapSourceToByteArray(@"..\..\Images\DefaultOccasionImages\gift.png"),
                            Name  = TemporaryPerson.Name + "'s Birthday",
                        }
                    };
                    TemporaryPerson.Occasions = defaultOccasions;
                    PeopleRepository.Add(TemporaryPerson);
                }
                this.Close();
            }
        }
        public ActionResult GetPeopleViaJson()
        {
            var peopleRepository = new PeopleRepository();
            var people           = peopleRepository.GetPeople();

            return(Json(people));
        }
 private async void UpdatePeople(object obj)
 {
     if (SelectedPeople.DateOfBirth == null)
     {
         EmptyFieldMessage(obj as Window, "EditDateOfBirth");
     }
     else if (SelectedPeople.Name == null || SelectedPeople.Name.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "EditName");
     }
     else if (SelectedPeople.LastName == null || SelectedPeople.LastName.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "EditLastName");
     }
     else if (SelectedPeople.SurName == null || SelectedPeople.SurName.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "EditSurName");
     }
     else if (SelectedPeople.City == null || SelectedPeople.City.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "EditCity");
     }
     else if (SelectedPeople.Country == null || SelectedPeople.Country.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "EditCoutry");
     }
     else
     {
         using (IRepository <People> Repository = new PeopleRepository())
             PeopleCollection = await Repository.UpdateObject(SelectedPeople);
         SelectedPeople = null;
     }
 }
        public object GetPeopleDictionary()
        {
            var peopleRepository = new PeopleRepository();
            var people = peopleRepository.GetPeopleDictionary();

            return people;
        }
        public void CreateFindUpdateTest()
        {
            Person createdPerson = new Person();
            createdPerson.Name = "gandamu strike freedom";
            createdPerson.Document = "ZGMFX20A";
            createdPerson.Email = "*****@*****.**";

            PeopleRepository repository = new PeopleRepository();

            repository.Save(createdPerson);

            Assert.AreNotEqual(0, createdPerson.Id);

            Person retrievedPerson = repository.FindSingle(p => p.Id == createdPerson.Id);

            Assert.AreEqual(createdPerson, retrievedPerson);

            retrievedPerson.Email = "*****@*****.**";

            repository.Save(retrievedPerson);

            retrievedPerson = repository.FindSingle(p => p.Id == createdPerson.Id);

            Assert.AreEqual("*****@*****.**", retrievedPerson.Email);
        }
Esempio n. 12
0
        public Person GetPersonById(int id)
        {
            var    pr = new PeopleRepository(_connectionString);
            Person p  = pr.PersonById(id);

            return(p);
        }
 private async void AddPeople(object obj)
 {
     if (AddDateOfBirth == null || AddDateOfBirth.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddDateOfBirth");
     }
     else if (AddName == null || AddName.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddName");
     }
     else if (AddLastName == null || AddLastName.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddLastName");
     }
     else if (AddSurName == null || AddSurName.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddSurName");
     }
     else if (AddCity == null || AddCity.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddCity");
     }
     else if (AddCountry == null || AddCountry.Replace(" ", "").Length == 0)
     {
         EmptyFieldMessage(obj as Window, "AddCoutry");
     }
     else
     {
         using (IRepository <People> Repository = new PeopleRepository())
             PeopleCollection = await Repository.CreateObject(new People(DateTime.Parse(AddDateOfBirth).Date, AddName, AddLastName, AddSurName, AddCity, AddCountry));
         ClearAddedPeople();
     }
 }
        public void CreateFindUpdateTest()
        {
            Person createdPerson = new Person();
            createdPerson.Name = "gandamu strike freedom";
            createdPerson.Document = "ZGMFX20A";
            createdPerson.Email = "*****@*****.**";

            PeopleRepository peopleRepository = new PeopleRepository();

            peopleRepository.Save(createdPerson);

            Account createdAccount = new Account();
            createdAccount.Agency = 435;
            createdAccount.Number = 123123123;
            createdAccount.OwnerId = createdPerson.Id;

            AccountsRepository repository = new AccountsRepository();

            repository.Save(createdAccount);

            Assert.AreNotEqual(0, createdAccount.Id);

            Account retrievedAccount = repository.FindSingle(a => a.Id == createdAccount.Id);

            Assert.AreEqual(createdAccount, retrievedAccount);

            retrievedAccount.Agency = 666;

            repository.Save(retrievedAccount);

            retrievedAccount = repository.FindSingle(a => a.Id == createdAccount.Id);

            Assert.AreEqual(666, retrievedAccount.Agency);
        }
Esempio n. 15
0
        public void GetPeopleData()
        {
            var peopleRepository = new PeopleRepository(IrmaContext, Log.GetLogger(this.GetType()));
            var val = peopleRepository.GetAll().ToList().FirstOrDefault();

            Assert.IsNotNull(val);
        }
        public void TransactionRollbackTest()
        {
            PeopleRepository peopleRepository = new PeopleRepository();
            AccountsRepository accountsRepository = new AccountsRepository();
            BankDataContextFactory contextFactory = new BankDataContextFactory();

            Person createdPerson = new Person();
            createdPerson.Name = "transaction test";
            createdPerson.Document = "ZGMFX20A";
            createdPerson.Email = "*****@*****.**";

            Account createdAccount = new Account();
            createdAccount.Number = 2354235;
            createdAccount.Agency = 34;

            UnitOfWork unitOfWork = contextFactory.CreateUnitOfWork();

            peopleRepository.Save(createdPerson, unitOfWork);

            createdAccount.OwnerId = createdPerson.Id;

            accountsRepository.Save(createdAccount, unitOfWork);

            unitOfWork.Rollback();

            Assert.IsNull(peopleRepository.FindSingle(p => p.Name == createdPerson.Name));
            Assert.IsNull(accountsRepository.FindSingle(a => a.Number == createdAccount.Number));
        }
Esempio n. 17
0
        public void AddCar(Car car, int personId)
        {
            PeopleRepository repo = new PeopleRepository(Properties.Settings.Default.ConStr);

            car.PersonId = personId;
            repo.AddCar(car);
        }
Esempio n. 18
0
        public Appointment Read(uint id)
        {
            List <string[]> data = Persistence.ReadEntryByPrimaryKey(path, id.ToString());

            if (data.Count == 1)
            {
                uint     appID     = uint.Parse(data[0][0]);
                DateTime startTime = new DateTime(long.Parse(data[0][1]));
                DateTime endTime   = new DateTime(long.Parse(data[0][2]));
                uint     mrID      = uint.Parse(data[0][3]);
                uint     docID     = uint.Parse(data[0][4]);
                Doctor   d         = (Doctor)PeopleRepository.GetInstance().Read(docID);
                uint     roomID    = uint.Parse(data[0][5]);
                //TODO: room read
                Room           r    = RoomRepository.GetInstance().Read(roomID);
                ServiceComment comm = null;
                if (!data[0][6].Equals(""))
                {
                    uint commID = uint.Parse(data[0][6]);
                    //TODO: comment read
                    comm = ServiceCommentRepository.GetInstance().Read(commID);
                }

                Appointment ret = new Appointment(startTime, endTime, mrID, d, r, comm);
                ret.SetId(appID);
                return(ret);
            }
            return(null);
        }
Esempio n. 19
0
        public ActionResult Delete(int id)
        {
            var repo = new PeopleRepository(Properties.Settings.Default.ConStr);

            repo.Delete(id);
            return(RedirectToAction("Index"));
        }
Esempio n. 20
0
        public List <People> GetAllPeople()
        {
            PeopleRepository peopleRepository = new PeopleRepository();
            var people = peopleRepository.GetAll();

            return(people);
        }
Esempio n. 21
0
        public void AddressTypeRoundtipsToDatabase()
        {
            int    newPersonId = 0;
            var    address     = CreateAddress(ContactType.Personal);
            Person person      = SimplePeopleTests.CreatePerson();

            person.HomeAddress = address;
            address            = CreateAddress(ContactType.Business);
            person.WorkAddress = address;

            using (new EFUnitOfWorkFactory().Create())
            {
                PeopleRepository peopleRepository = new PeopleRepository();
                peopleRepository.Add(person);
            }
            newPersonId = person.Id;

            newPersonId.Should().BeGreaterThan(0);

            ContactManagerContext context = new ContactManagerContext();
            var check = context.People.First(x => x.Id == newPersonId);

            check.Id.Should().Be(newPersonId);
            check.HomeAddress.ContactType.Should().Be(ContactType.Personal);
            check.WorkAddress.ContactType.Should().Be(ContactType.Business);
        }
        public ActionResult DeletePerson(int Id)
        {
            PeopleRepository repository = new PeopleRepository(Properties.Settings.Default.ConStr);

            repository.DeletePerson(Id);
            return(Redirect("/home/index"));
        }
Esempio n. 23
0
        public IActionResult Delete(int id)
        {
            var repo = new PeopleRepository(_connectionString);

            repo.Delete(id);
            return(Redirect("/"));
        }
        public static PersonAdded AddNewPerson(string firstName, string lastName, string birthday)
        {
            string[] formats = { "MM/dd/yyyy" };
            try
            {
                if (firstName == "" | lastName == "")
                {
                    throw new Exception("Preencha todos os campos!");
                }

                DateTime birthdayConverted;

                DateTime.TryParseExact(birthday, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime result);

                birthdayConverted = DateTime.ParseExact(birthday, formats, CultureInfo.InvariantCulture);

                Person person = new Person(firstName, lastName, birthdayConverted);

                bool AddNewPersonResult = PeopleRepository.New(person);

                return(new PersonAdded {
                    Status = AddNewPersonResult,
                    Message = AddNewPersonResult ? "Pessoa adicionada com sucesso!": "Pessoa não adicionada!"
                });
            } catch (Exception exception)
            {
                Console.Clear();
                return(new PersonAdded {
                    Status = false, Message = exception.Message
                });
            }
        }
        public ActionResult EditPerson(Person person)
        {
            PeopleRepository repository = new PeopleRepository(Properties.Settings.Default.ConStr);

            repository.EditPerson(person);
            return(Redirect("/home/index"));
        }
Esempio n. 26
0
        public void ShouldCreateRecordInDb()
        {
            int    id            = 4;
            string firstName     = "Rosie";
            string surname       = "Butterworth";
            int    age           = 12;
            Person newPersonData = new Person {
                FirstName = firstName, Surname = surname, Age = age
            };
            Person expectedNewPerson = new Person {
                ID = id, FirstName = firstName, Surname = surname, Age = age
            };

            using (var repo = new PeopleRepository(_options))
            {
                repo.CreatePerson(newPersonData);
            }

            using (var repo = new PeopleRepository(_options))
            {
                repo.People.Count().ShouldBe(4);
                var createdPerson = repo.People.Single(q => q.ID == id);
                createdPerson.Equals(expectedNewPerson).ShouldBeTrue();
            }
        }
        private void RefreshButton_Click(object sender, RoutedEventArgs e)
        {
            // selectedPerson is a method level variable,
            // it means that if get } of RefreshButton_Click method, this variable should be Garbage Collected

            // BUT this variable was in scope when we created a lambda expression
            // So we can grab the reference to that viariable and we can use it in the body of our lambda,
            // even though it would normally be out of scope
            // Thus, selectedPerson can also be called a CAPTURED variable
            // This is how we form a CLOSURE
            Person selectedPerson = PersonListBox.SelectedItem as Person;

            var repository = new PeopleRepository();

            repository.GetPeopleCompleted +=
                // types don't need to be included inside lambda expressions
                (repoSender, repoArgs) =>
            {
                PersonListBox.ItemsSource = AddSort(AddFilters(repoArgs.Result));
                if (selectedPerson != null)
                {
                    PersonListBox.SelectedItem =
                        PersonListBox.Items.OfType <Person>().SingleOrDefault(
                            p => p.FirstName == selectedPerson.FirstName &&
                            p.LastName == selectedPerson.LastName
                            );
                }
            };
            repository.GetPeopleAsync();
            //selectedPerson = null;
        }
Esempio n. 28
0
        private IGrid <Person> CreateExportableGrid()
        {
            IGrid <Person> grid = new Grid <Person>(PeopleRepository.GetPeople());

            grid.ViewContext = new ViewContext {
                HttpContext = HttpContext
            };
            grid.Query = new NameValueCollection(Request.QueryString);

            grid.Columns.Add(model => model.Name);
            grid.Columns.Add(model => model.Surname);

            grid.Columns.Add(model => model.Age);
            grid.Columns.Add(model => model.Birthday).Formatted("{0:d}");
            grid.Columns.Add(model => model.IsWorking);

            grid.Pager = new GridPager <Person>(grid);
            grid.Processors.Add(grid.Pager);
            grid.Pager.RowsPerPage = 6;

            foreach (IGridColumn column in grid.Columns)
            {
                column.Filter.IsEnabled = true;
                column.Sort.IsEnabled   = true;
            }

            return(grid);
        }
Esempio n. 29
0
        public IActionResult Edit(int id)
        {
            var repo   = new PeopleRepository(_connectionString);
            var person = repo.GetById(id);

            return(View(person));
        }
Esempio n. 30
0
        public Person Add(Person person)
        {
            var repo = new PeopleRepository(_connectionString);

            repo.Add(person);
            return(person);
        }
Esempio n. 31
0
        public IActionResult Update(Person person)
        {
            var repo = new PeopleRepository(_connectionString);

            repo.Update(person);
            return(Redirect("/"));
        }
Esempio n. 32
0
        public List <People> GetAllPersons()
        {
            PeopleRepository repository = new PeopleRepository();
            var People = repository.GetAll();

            return(People);
        }
Esempio n. 33
0
        private async Task TryRegister()
        {
            PeopleRepository rep = new PeopleRepository();

            if (rep.canRegister(new Person(tbxusr.Text, tbxPass.Text)) &&
                !string.IsNullOrEmpty(tbxusr.Text) &&
                !string.IsNullOrEmpty(tbxPass.Text) &&
                !string.IsNullOrEmpty(tbxconPass.Text))
            {
                if (tbxconPass.Text == tbxPass.Text)
                {
                    //rep.Register(new Person(tbxusr.Text, tbxPass.Text));
                    await new MessageDialog("User has Registered").ShowAsync();
                    this.Frame.Navigate(typeof(Pages.LoginPage));
                }
                else
                {
                    await new MessageDialog("Passwords do not match").ShowAsync();
                    return;
                }
            }
            else
            {
                await new MessageDialog("Username or password is invalid").ShowAsync();
                return;
            }
        }
Esempio n. 34
0
        public ActionResult Update(Person person)
        {
            var repo = new PeopleRepository(Properties.Settings.Default.ConStr);

            repo.Update(person);
            return(RedirectToAction("Index"));
        }
Esempio n. 35
0
        public void DeletePeople(int id)
        {
            PeopleRepository peopleRepository = new PeopleRepository();
            People           obj = peopleRepository.GetByID(id);

            peopleRepository.Delete(obj);
        }
Esempio n. 36
0
        private void PopulateUser(RigOapChecklist rigOapChecklist)
        {
            if (rigOapChecklist == null)
            {
                return;
            }

            rigOapChecklist.Owner = PeopleRepository.Get(rigOapChecklist.OwnerId);


            if ((rigOapChecklist.Assessors != null) && rigOapChecklist.Assessors.Any())
            {
                foreach (var a in rigOapChecklist.Assessors)
                {
                    a.TourId = PobPersonnelRepository.GetTourId(a.UserId);
                    a.User   = PeopleRepository.Get(a.UserId);
                }
            }

            if ((rigOapChecklist.VerifiedBy != null) && rigOapChecklist.VerifiedBy.Any())
            {
                foreach (var v in rigOapChecklist.VerifiedBy)
                {
                    v.User = PeopleRepository.Get(v.UserId);
                }
            }
        }
        public void FindByPersonNameTest()
        {
            Person createdPerson = new Person();
            createdPerson.Name = "person name test";
            createdPerson.Document = "ZGMFX20A";
            createdPerson.Email = "*****@*****.**";

            PeopleRepository peopleRepository = new PeopleRepository();

            peopleRepository.Save(createdPerson);

            Account createdAccount = new Account();
            createdAccount.Agency = 435;
            createdAccount.Number = 123123123;
            createdAccount.OwnerId = createdPerson.Id;

            AccountsRepository repository = new AccountsRepository();

            repository.Save(createdAccount);

            Assert.AreNotEqual(0, createdAccount.Id);

            Account retrievedAccount = repository.FindSingle(a => a.PERSON.Name == createdPerson.Name);

            Assert.AreEqual(createdAccount, retrievedAccount);
        }
        public IEnumerable<Person> People()
        {
            var peopleRepository = new PeopleRepository();
            var people = peopleRepository.GetPeople();

            return people;
        }
        public void ProcessRequest(HttpContext context)
        {
            var peopleRepository = new PeopleRepository();
            var people = peopleRepository.GetPeople();

            context.Response.ContentType = "application/json";
            context.Response.Write(JsonConvert.SerializeObject(people));
        }
 public void Verify_SaveChanges_WithBadData_Should_ThrowAnException()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(false, out mockSetPeople);
     mockContext.Setup(m => m.SaveChanges()).Returns(() => { throw new Exception("TEST"); });
     var repository = new PeopleRepository(mockContext.Object);
     // Act/Assert
     Assert.Throws(typeof(Exception), () => { repository.SaveChanges(); });
 }
 public void Verify_Deactivate_Should_SetTheActivePropertyToFalseOnTheEntity()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(true, out mockSetPeople);
     var repository = new PeopleRepository(mockContext.Object);
     var people = repository.Get(1);
     // Act
     repository.Deactivate(people);
     // Assert
     Assert.Equal(false, people.Active);
 }
 public void Verify_Add_Should_AddTheEntityToTheContext()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(false, out mockSetPeople);
     var repository = new PeopleRepository(mockContext.Object);
     var people = new Person { Active = true, CustomKey = "SALVATORE-RAA", };
     // Act
     repository.Add(people);
     // Assert
     mockSetPeople.Verify(x => x.Add(people), Times.Once);
 }
 public void Verify_SaveChanges_Should_RunOnceAndReturnSuccessfully()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(false, out mockSetPeople);
     var repository = new PeopleRepository(mockContext.Object);
     var person = new Person { Active = true, CustomKey = "SALVATORE-RAA", Name = "R.A.A Salvatore" };
     repository.Add(person);
     // Act
     var result = repository.SaveChanges();
     // Assert
     mockContext.Verify(x => x.SaveChanges(), Times.Once);
     Assert.Equal(true, result);
 }
 public void Verify_Update_Should_SetTheEntityStateToModified()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(true, out mockSetPeople);
     var repository = new PeopleRepository(mockContext.Object);
     var people = repository.Get(1);
     people.ApiDetailUrl = "/TEST";
     // Act
     repository.Update(people);
     // Assert
     mockContext.Verify(x => x.SetModified(It.IsAny<object>()), Times.Once);
 }
 public void Verify_Get_ByID_Should_ReturnTheCorrectPerson()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(true, out mockSetPeople);
     var repository = new PeopleRepository(mockContext.Object);
     // Act
     var people = repository.Get(1);
     // Assert
                 Assert.Equal("/TEST/KING-STEPHEN", people.ApiDetailUrl);
 }
 public Person()
 {
     AccountsRepository = new AccountsRepository();
     PeopleRepository = new PeopleRepository();
 }
Esempio n. 47
0
 public void Init()
 {
     ctx = EFContext.CreateContext();
     repo = new PeopleRepository(ctx);
 }
Esempio n. 48
0
 public AdditionalRepositories(ManahostManagerDAL ctx)
 {
     PeopleRepo = new PeopleRepository(ctx);
     HomeRepo = new HomeRepository(ctx);
     DocumentRepo = new DocumentRepository(ctx);
 }
Esempio n. 49
0
 public void CreatePerson(Person person)
 {
     var peopleRepository = new PeopleRepository(_db);
     peopleRepository.Add(person);
     _db.SaveChanges();
 }
 public void Verify_Search_WithPaging_Should_ReturnAListOfPeopleWithDataMatchingSearchParameters()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(true, out mockSetPeople);
     var repository = new PeopleRepository(mockContext.Object);
     var searchModel = new PersonSearchModel { Paging = new Paging { Skip = 1, Take = 1 } };
     // Act
     var people = repository.Search(searchModel/*.Object*/).ToArray();
     // Assert
     Assert.Equal(1, people.Length);
     Assert.Equal(2, people[0].Id);
     Assert.Equal("/TEST/NIVEN-LARRY", people[0].ApiDetailUrl);
     // Stephen King was filtered out because he was Skipped
 }
 public void Verify_Search_WithSelectStatement_Should_ReturnAListOfDynamicObjects()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(true, out mockSetPeople, true);
     var repository = new PeopleRepository(mockContext.Object);
     var searchModel = new Mock<IPersonSearchModel>();
     // Act
     var people = repository.Search(searchModel.Object, i => new { i.Id, MyApiDetailUrl = i.ApiDetailUrl }).ToArray();
     // Assert
     Assert.Equal(1, people.Length);
     Assert.Equal(2, people[0].Id);
     Assert.Equal("/TEST/NIVEN-LARRY", people[0].MyApiDetailUrl);
     // Stephen King was filtered out because he was Inactive
 }
 public void Verify_Remove_Should_RemoveTheEntityFromTheContext()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(true, out mockSetPeople);
     var repository = new PeopleRepository(mockContext.Object);
     var people = repository.Get(1);
     // Act
     repository.Remove(people);
     // Assert
     mockSetPeople.Verify(x => x.Remove((Person)people), Times.Once);
 }
 public void Verify_Search_WithModifiedSince_Should_ReturnAListOfPeopleWithDataMatchingSearchParameters()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(true, out mockSetPeople, true);
     var repository = new PeopleRepository(mockContext.Object);
     var createDate = new System.DateTime(2015, 05, 28, 10, 45, 00).AddDays(1).AddMinutes(-1);
     //var searchModel = new Mock<IPersonSearchModel>();
     //searchModel.Setup(m => m.ModifiedSince).Returns(() => createDate);
     var searchModel = new PersonSearchModel { ModifiedSince = createDate };
     // Act
     var people = repository.Search(searchModel/*.Object*/).ToArray();
     // Assert
     Assert.Equal(1, people.Length);
     Assert.Equal(2, people[0].Id);
     Assert.Equal("/TEST/NIVEN-LARRY", people[0].ApiDetailUrl);
     // Stephen King was filtered out because he was created before the modified since date
 }
Esempio n. 54
0
        static void Main(string[] args)
        {
            PeopleRepository repPeople = new PeopleRepository();
            ProductsRepository repProduct = new ProductsRepository();

            Console.WriteLine("People");
            Console.WriteLine("================================================================================");

            Console.WriteLine(repPeople.GetItem("Hunt").ToString());
            Console.WriteLine();

            foreach (Person p in repPeople.GetItems().OrderBy(p => p.LastName)) Console.WriteLine(p.LastName);
            Console.WriteLine();

            repPeople.AddItem(new Person() { FirstName = "Zbigniew", LastName = "Koziel", Rating = 2, StartDate = DateTime.Now});
            foreach (Person p in repPeople.GetItems().OrderBy(p => p.LastName)) Console.WriteLine(p.LastName);
            Console.WriteLine();

            repPeople.DeleteItem("Hunt");
            //repPeople.DeleteItem("Koziel"); //
            repPeople.DeleteItem("Koenig");
            foreach (Person p in repPeople.GetItems().OrderBy(p => p.LastName)) Console.WriteLine(p.LastName);
            Console.WriteLine();

            Console.WriteLine(Convert.ToString(repPeople.GetItem("Koziel")));
            repPeople.UpdateItem("Koziel", new Person() { FirstName = "Zbigman", LastName = "Koziel", Rating = 9, StartDate = DateTime.Now });
            // Convert.ToString() doesn't throw exception if GetItem() returns null reference, in oppose to repPeople.GetItem().ToString()
            Console.WriteLine(Convert.ToString(repPeople.GetItem("Koziel")));
            Console.WriteLine();

            repPeople.UpdateItems(new List<Person>() {
                new Person(){ FirstName = "AAA", LastName = "aaa", StartDate = DateTime.Now, Rating = 1 },
                new Person(){ FirstName = "BBB", LastName = "bbb", StartDate = DateTime.Now, Rating = 1 },
                new Person(){ FirstName = "CCC", LastName = "ccc", StartDate = DateTime.Now, Rating = 1 },
                new Person(){ FirstName = "DDD", LastName = "ddd", StartDate = DateTime.Now, Rating = 1 },
            });
            foreach (Person p in repPeople.GetItems().OrderBy(p => p.LastName)) Console.WriteLine(p.LastName);
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Products");
            Console.WriteLine("================================================================================");

            Console.WriteLine(repProduct.GetItem(3).ToString());
            Console.WriteLine();

            foreach (Product p in repProduct.GetItems().OrderBy(p => p.ProductName)) Console.WriteLine(p.ProductName);
            Console.WriteLine();

            repProduct.AddItem(new Product() { ProductId = repProduct.GetItems().Max(p => p.ID) + 1, Category = "Instruments", ProductName = "Piano" });
            repProduct.AddItem(new Product() { ProductId = repProduct.GetItems().Max(p => p.ID) + 1, Category = "Instruments", ProductName = "Guitar" });
            repProduct.AddItem(new Product() { ProductId = repProduct.GetItems().Max(p => p.ID) + 1, Category = "Instruments", ProductName = "Fluet" });
            foreach (Product p in repProduct.GetItems().OrderBy(p => p.ProductName)) Console.WriteLine(p.ProductName);
            Console.WriteLine();

            repProduct.DeleteItem(5);
            repProduct.DeleteItem(6);
            repProduct.DeleteItem(7);
            repProduct.DeleteItem(8);
            foreach (Product p in repProduct.GetItems().OrderBy(p => p.ProductName)) Console.WriteLine(p.ProductName);
            Console.WriteLine();

            Console.WriteLine(Convert.ToString(repProduct.GetItem(1)));
            repProduct.UpdateItem(1, new Product() { ProductId = 1, Category = "Instruments", ProductName = "Clarinet" });
            Console.WriteLine(Convert.ToString(repProduct.GetItem(1)));
            Console.WriteLine();

            repProduct.UpdateItems(new List<Product>() {
                new Product(){ ProductId = 1, ProductName = "Lozko", Category = "Meble" },
                new Product(){ ProductId = 2, ProductName = "Suszarka", Category = "AGD" },
                new Product(){ ProductId = 3, ProductName = "Konfitury", Category = "Jedzenie" },
            });
            foreach (Product p in repProduct.GetItems().OrderBy(p => p.ProductName)) Console.WriteLine(p.ProductName);
            Console.WriteLine();

            //Console.ReadKey();
        }
 public void Verify_List_Should_ReturnAListOfPeopleWithData()
 {
     // Arrange
     Mock<IDbSet<Person>> mockSetPeople;
     var mockContext = PeopleMockingSetup.DoMockingSetupForContext(true, out mockSetPeople);
     var repository = new PeopleRepository(mockContext.Object);
     // Act
     var people = repository.List.ToArray();
     // Assert
     Assert.Equal(2, people.Length);
     Assert.Equal(1, people[0].Id);
     Assert.Equal("/TEST/KING-STEPHEN", people[0].ApiDetailUrl);
     Assert.Equal(2, people[1].Id);
     Assert.Equal("/TEST/NIVEN-LARRY", people[1].ApiDetailUrl);
 }
Esempio n. 56
0
 public Person GetPerson(string personTRN)
 {
     var peopleRepository = new PeopleRepository(_db);
     var person = peopleRepository.FindBy(c => c.TRN == personTRN).SingleOrDefault();
     return person;
 }
 public Account()
 {
     AccountsRepository = new AccountsRepository();
     PeopleRepository = new PeopleRepository();
 }