Exemple #1
0
 /// <summary>
 /// Get an existing gender, not mocked up in CreateMockData
 /// </summary>
 /// <returns></returns>
 public GenderType ExistingFemale()
 {
     using (PersonEntities Entity = new PersonEntities())
     {
         return(Entity.GenderTypes.FirstOrDefault(item => item.Gender == "Female"));
     }
 }
        public void TestMethod1()
        {
            using (var context = new PersonEntities())
            {
                var person = context.People.Add(
                    new Person()
                {
                    FirstName = "Mary", LastName = "Moore"
                });

                person.Phones = new List <Phone>()
                {
                    new Phone()
                    {
                        PhoneType = "Cell 1", PhoneNumber = "888-888-8888"
                    },
                    new Phone()
                    {
                        PhoneType = "Cell 2", PhoneNumber = "666-666-6666"
                    },
                    new Phone()
                    {
                        PhoneType = "Cell 3", PhoneNumber = "444-444-444"
                    }
                };

                context.SaveChanges();
            }
        }
Exemple #3
0
        /// <summary>
        /// Removes test data from database, called from all tests that create data
        /// </summary>
        /// <remarks>
        /// If you have issues with data not disposing then set break-points
        /// in the emppty try/catch statements to figure out the issue. More likely
        /// than not the interface, in this case IBaseEntity was not implemented on
        /// one of the classes.
        ///
        /// The try-catches allow us to continue and throw an exception message in
        /// the tear down event TeardownTestBase for any test.
        ///
        /// Empty try/catches are okay here as you should be using this only for
        /// unit testing and hopefully on a non production database.
        ///
        /// </remarks>
        public bool AnnihilateData(List <object> mAnnihilateList)
        {
            bool mAnnihilateDataSuccessful = false;

            using (var destroyContext = new PersonEntities())
            {
                for (int i = mAnnihilateList.Count - 1; i >= 0; i--)
                {
                    try
                    {
                        var currentObject = mAnnihilateList[i];

                        var existingItem = destroyContext
                                           .Set(currentObject.GetType())
                                           .Find(((IBaseEntity)currentObject).Identifier);

                        if (existingItem != null)
                        {
                            try
                            {
                                var attachedEntry = destroyContext.Entry(existingItem);
                                attachedEntry.CurrentValues.SetValues(currentObject);
                                destroyContext.Set(existingItem.GetType()).Attach(existingItem);

                                destroyContext.Set(existingItem.GetType()).Remove(existingItem);
                            }
                            catch (Exception)
                            {
                                // ignore nothing do to as the object was not added in properly.
                            }
                        }
                        else
                        {
                            var item = currentObject.GetType();
                        }
                    }
                    catch (Exception)
                    {
                        //catch and continue save what we can
                    }
                }
                try
                {
                    var resultCount      = destroyContext.SaveChanges();
                    var annihlationCount = mAnnihilateList.Count;

                    mAnnihilateDataSuccessful = (resultCount == annihlationCount);
                }
                catch (Exception)
                {
                    // keep on going
                }
                finally
                {
                    destroyContext.Dispose();
                }
            }

            return(mAnnihilateDataSuccessful);
        }
Exemple #4
0
 public void Delete(decimal id)
 {
     using (var context = new PersonEntities())
     {
         var record = (from d in context.Person select d).Where(d => d.Id.Equals(id)).FirstOrDefault();
         context.Person.Remove(record);
         context.SaveChanges();
     }
 }
Exemple #5
0
 public void Update(PersonModel p)
 {
     using (var context = new PersonEntities())
     {
         var query = (from d in context.Person select d).Where(d => d.Id.Equals(p.Id)).FirstOrDefault();
         query.Name   = p.Name;
         query.Gender = p.Gender;
         query.Phone  = p.Phone;
         context.SaveChanges();
     }
 }
 /// <summary>
 /// Loads all tables into the context.
 /// </summary>
 public void LoadTablesIntoContext()
 {
     ProjectEntities.Load();
     PersonEntities.Load();
     ExpertEntities.Load();
     EventTreeEntities.Load();
     TreeEventEntities.Load();
     ExpertClassEstimationEntities.Load();
     FragilityCurveElementEntities.Load();
     TreeEventFragilityCurveElementEntities.Load();
     HydraulicConditionElementEntities.Load();
 }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
      {
     // free managed resources
     if (_dbContext != null)
     {
        _dbContext.Dispose();
        _dbContext = null;
     }
      }
 }
Exemple #8
0
 public PersonModel ConsultOne(decimal id)
 {
     using (var context = new PersonEntities())
     {
         PersonModel person = new PersonModel();
         var         record = (from d in context.Person select d).Where(d => d.Id.Equals(id)).FirstOrDefault();
         person.Id     = record.Id;
         person.Name   = record.Name;
         person.Gender = record.Gender;
         person.Phone  = record.Phone;
         return(person);
     }
 }
Exemple #9
0
        public Form1()
        {
            InitializeComponent();

            PersonEntities ente        = new PersonEntities();
            master_file    master_file = (new master_file()
            {
                firstname = "My", lastname = "Lastname", function = EFunction.Interessent, aktiv = true, deleted_inaktiv = false, newsletter_flag = true
            });

            ente.master_file.Add(master_file);
            ente.SaveChanges();
        }
Exemple #10
0
        public void Create(PersonModel p)
        {
            using (var context = new PersonEntities())
            {
                Person pe = new Person();
                pe.Name   = p.Name;
                pe.Gender = p.Gender;
                pe.Phone  = p.Phone;

                context.Person.Add(pe);
                context.SaveChanges();
            }
        }
        public void ReadNames()
        {
            var buffer = new StringBuilder();

            using (var entities = new PersonEntities())
            {
                foreach (var person in entities.People)
                {
                    buffer.Append(person.Name + ' ');
                }
            }

            Assert.AreEqual(LoremIpsum, buffer.ToString().Trim(' '));
        }
Exemple #12
0
        public List <PersonModel> Consult()
        {
            List <PersonModel> peoplelist = new List <PersonModel>();

            using (var context = new PersonEntities())
            {
                var query = (from d in context.Person select d).ToList();
                foreach (var item in query)
                {
                    PersonModel p = new PersonModel();
                    p.Id     = item.Id;
                    p.Name   = item.Name;
                    p.Gender = item.Gender;
                    p.Phone  = item.Phone;

                    peoplelist.Add(p);
                }
            }
            return(peoplelist);
        }
        public void TestInitialize()
        {
            using (var entities = new PersonEntities())
            {
                entities.People.RemoveRange(entities.People);
                entities.SaveChanges();

                var tokens = LoremIpsum.Split(' ');

                foreach (var token in tokens)
                {
                    entities.People.Add(new Person
                    {
                        Name     = token,
                        PersonId = Guid.NewGuid()
                    });
                }

                entities.SaveChanges();
            }
        }
Exemple #14
0
        public Form1()
        {
            InitializeComponent();

            var entities = new PersonEntities();
            CommunicationRepository repository = new CommunicationRepository(entities);
            var c = repository.GetCommunications <Person>(1);
            var d = repository.GetCommunications <Course>(1);

            try
            {
                var svNr = 07866987;
                var num  = svNr.ToString().Select(x => Convert.ToInt32(x)).ToList();
                var s    = ConverChar(num[3]);
                num.Remove(num[3]);

                var x = 0;
                //3
                var calc = new int[] { 3, 7, 9, 5, 8, 4, 2, 1, 6 }; //11
                for (int i = 0; i < calc.Length; i++)
                {
                    var carNum = ConverChar(num[i]);
                    x += carNum * calc[i];
                }
                var  result     = x % 11;
                bool resultBool = s == result;
                if (resultBool)
                {
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemple #15
0
 public AddressPersonRepository(PersonEntities entities) : base(entities)
 {
     this.entities = entities;
 }
Exemple #16
0
 public UserRepository(PersonEntities Entities) : base(Entities)
 {
 }
Exemple #17
0
 public ContactRepository(PersonEntities entities) : base(entities)
 {
 }
Exemple #18
0
 public AddressRepository(PersonEntities entities) : base(entities)
 {
 }
Exemple #19
0
 public CommunicationRepository(PersonEntities personEntities)
 {
     entities = personEntities;
     docRepo  = new DocumentRepository(personEntities);
 }
Exemple #20
0
 public PersonRepository(PersonEntities entities) : base(entities)
 {
 }
Exemple #21
0
 public DocumentRepository(PersonEntities entities)
 {
     this.entities = entities;
 }
Exemple #22
0
 public BaseRepository(PersonEntities Entities)
 {
     this.entities = Entities;
 }
Exemple #23
0
 public CourseRepository(PersonEntities entities)
 {
     this.entities = entities;
 }
Exemple #24
0
 public void SetupTestBase()
 {
     AnnihilationList = new List <object>();
     DbContext        = new PersonEntities();
 }