public void QueryEntityInstanceBatchAsync()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                contextWrapper.Context.IgnoreMissingProperties = true;

                contextWrapper.Configurations.ResponsePipeline
                .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading)
                .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized)
                .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized);

                DataServiceRequest[] requests = new DataServiceRequest[] {
                    contextWrapper.CreateQuery <Person>("Person(-10)"),
                    contextWrapper.CreateQuery <Customer>("Customer"),
                };

                DataServiceResponse responses = null;
                IAsyncResult r = contextWrapper.BeginExecuteBatch(
                    result =>
                {
                    responses = contextWrapper.EndExecuteBatch(result);
                },
                    null,
                    requests);

                while (!r.IsCompleted)
                {
                    Thread.Sleep(1000);
                }

                bool personVerified   = false;
                bool customerVerified = false;
                foreach (QueryOperationResponse response in responses)
                {
                    foreach (object p in response)
                    {
                        SpecialEmployee se1 = p as SpecialEmployee;
                        Customer c          = p as Customer;
                        if (se1 != null)
                        {
                            Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", se1.CarsLicensePlate, "Unexpected CarsLicensePlate");
                            Assert.AreEqual(1, se1.BonusLevel, "Unexpected BonusLevel");
                            personVerified = true;
                        }

                        if (c != null)
                        {
                            Assert.IsTrue(c.Name.EndsWith("ModifyPropertyValueCustomerEntity_Materialized"), "Unexpected primitive property");
                            Assert.IsTrue(c.Auditing.ModifiedBy.Equals("ModifyPropertyValueCustomerEntity_Materialized"), "Unexpected complex property");
                            Assert.IsTrue(c.PrimaryContactInfo.EmailBag.Contains("ModifyPropertyValueCustomerEntity_Materialized"), "Unexpected collection property");
                            customerVerified = true;
                        }
                    }
                }

                Assert.IsTrue(personVerified && customerVerified, "Some inner request does not completed correctly");
            });
        }
Exemplo n.º 2
0
        private static void QueryEntityInstanceExecuteAsync(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            // contextWrapper.Context.UndeclaredPropertyBehavior = UndeclaredPropertyBehavior.Support;
            contextWrapper.Configurations.ResponsePipeline
            .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading)
            .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized)
            .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized);

            IEnumerable <SpecialEmployee> specialEmployees = null;
            IAsyncResult r = contextWrapper.BeginExecute <SpecialEmployee>(
                new Uri("Person(-10)", UriKind.Relative),
                result => { specialEmployees = contextWrapper.EndExecute <SpecialEmployee>(result); },
                null);

            while (!r.IsCompleted)
            {
                Thread.Sleep(1000);
            }

            SpecialEmployee specialEmployee = specialEmployees.Single();

            Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee.CarsLicensePlate,
                            "Unexpected CarsLicensePlate");
            Assert.AreEqual(1, specialEmployee.BonusLevel, "Unexpected BonusLevel");
        }
        public void QueryEntityInstanceExecuteAsync()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                contextWrapper.Context.IgnoreMissingProperties = true;

                contextWrapper.Configurations.ResponsePipeline
                .OnEntryEnded(PipelineEventsTestsHelper.AddRemovePropertySpecialEmployeeEntry_Reading)
                .OnEntityMaterialized(PipelineEventsTestsHelper.AddEnumPropertySpecialEmployeeEntity_Materialized)
                .OnEntityMaterialized(PipelineEventsTestsHelper.ModifyPropertyValueCustomerEntity_Materialized);

                IEnumerable <SpecialEmployee> specialEmployees = null;
                IAsyncResult r = contextWrapper.BeginExecute <SpecialEmployee>(
                    new Uri("Person(-10)", UriKind.Relative),
                    result =>
                {
                    specialEmployees = contextWrapper.EndExecute <SpecialEmployee>(result);
                },
                    null);

                while (!r.IsCompleted)
                {
                    Thread.Sleep(1000);
                }

                SpecialEmployee specialEmployee = specialEmployees.Single();
                Assert.AreEqual("AddRemovePropertySpecialEmployeeEntry_Reading", specialEmployee.CarsLicensePlate, "Unexpected CarsLicensePlate");
                Assert.AreEqual(1, specialEmployee.BonusLevel, "Unexpected BonusLevel");
            });
        }
        public void ExecuteOverloadedActionsWithDifferentParameter()
        {
            string actionName  = "IncreaseEmployeeSalary";
            string actionTitle = "Microsoft.Test.OData.Services.AstoriaDefaultService." + actionName;

            var contextWrapper = this.CreateWrappedContext();

            // action bound with special employee instance
            Employee employee = contextWrapper.Execute <Employee>(new Uri(this.ServiceUri + "Person(0)", UriKind.Absolute)).Single();
            IEnumerable <OperationDescriptor> employeeDescriptors = contextWrapper.GetEntityDescriptor(employee).OperationDescriptors.Where(od => od.Title.Equals(actionTitle));
            Dictionary <string, string>       expectedLinkValues  = new Dictionary <string, string>()
            {
                { ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(0)/" + ActionOverloadingQueryTests.EmployeeTypeName + "/" + actionTitle },
            };

            this.VerifyLinks(expectedLinkValues, employeeDescriptors);
            contextWrapper.Execute <bool>(employeeDescriptors.Single().Target, "POST", true, new BodyOperationParameter("n", 123)).Single();

            // action bound with special special employee instance
            SpecialEmployee specialEmployee = contextWrapper.Execute <SpecialEmployee>(new Uri(this.ServiceUri + "Person(-7)", UriKind.Absolute)).Single();
            IEnumerable <OperationDescriptor> specialEmployeeDescriptors = contextWrapper.GetEntityDescriptor(specialEmployee).OperationDescriptors.Where(od => od.Title.Equals(actionName));
            List <Tuple <string, string> >    expectedLinkValuesList     = new List <Tuple <string, string> >()
            {
                new Tuple <string, string>(ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(-7)/" + ActionOverloadingQueryTests.EmployeeTypeName + "/" + actionTitle),
                new Tuple <string, string>(ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(-7)/" + ActionOverloadingQueryTests.SpecialEmployeeTypeName + "/" + actionTitle),
            };

            this.VerifyLinks(expectedLinkValuesList, specialEmployeeDescriptors);

            contextWrapper.Execute <bool>(specialEmployeeDescriptors.Where(d => d.Target.AbsoluteUri.Contains(".Employee")).Single().Target, "POST", true, new BodyOperationParameter("n", 123)).Single();
            contextWrapper.Execute <int>(specialEmployeeDescriptors.Where(d => d.Target.AbsoluteUri.Contains(".SpecialEmployee")).Single().Target, "POST", true).Single();
        }
        // [Ignore] // Issue: #623: Support DI in OData Client
        // [TestMethod] // github issuse: #896
        public void ContextReferencesTest()
        {
            var contextWrapper = this.CreateWrappedContext();

            Assert.AreEqual(0, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 0");

            var entityFromAttachTo = new SpecialEmployee {
                PersonId = IdOfPerson
            };

            contextWrapper.AttachTo("Person", entityFromAttachTo);
            Assert.AreEqual(1, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 1");

            var personMetadata = contextWrapper.Context.PersonMetadata.Where(m => m.Person.PersonId == IdOfPerson).FirstOrDefault();

            Assert.AreEqual(2, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 2");

            contextWrapper.LoadProperty(personMetadata, "Person");
            var entityFromLoadProperty = personMetadata.Person;

            contextWrapper.Detach(personMetadata);
            Assert.AreEqual(1, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 1");
            Assert.IsTrue(entityFromAttachTo == entityFromLoadProperty, "Both variables should reference the same object.");

            var entityFromQuery = contextWrapper.Context.Person.Where(p => p.PersonId == IdOfPerson).SingleOrDefault();

            Assert.AreEqual(1, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 1");
            Assert.IsTrue(entityFromAttachTo == entityFromQuery, "Both variables should reference the same object.");

            var entityFromQueryWithOfType = contextWrapper.Context.Person.OfType <Employee>().Where(p => p.PersonId == IdOfPerson).SingleOrDefault();

            Assert.AreEqual(1, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 1");
            Assert.IsTrue(entityFromAttachTo == entityFromQueryWithOfType, "Both variables should reference the same object.");
        }
Exemplo n.º 6
0
        public void AddObjectSave()
        {
            var contextWrapper = this.CreateWrappedContext();

            var specialEmployee = new SpecialEmployee { PersonId = 1234 };
            contextWrapper.AddObject("Person", specialEmployee);
            contextWrapper.SaveChanges();

            contextWrapper.DeleteObject(specialEmployee);
            contextWrapper.SaveChanges();
        }
        public void ExecuteOverloadedActionsOnBaseAndDerivedTypes()
        {
            string actionName  = "UpdatePersonInfo";
            string actionTitle = "Microsoft.Test.OData.Services.AstoriaDefaultService." + actionName;

            var contextWrapper = this.CreateWrappedContext();

            // action bound with person instance
            Person people = contextWrapper.Execute <Person>(new Uri(this.ServiceUri + "Person(-1)", UriKind.Absolute)).Single();
            IEnumerable <OperationDescriptor> peopleDescriptors  = contextWrapper.GetEntityDescriptor(people).OperationDescriptors.Where(od => od.Metadata.AbsoluteUri.EndsWith(actionName));
            Dictionary <string, string>       expectedLinkValues = new Dictionary <string, string>()
            {
                { ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(-1)/" + actionTitle },
            };

            this.VerifyLinks(expectedLinkValues, peopleDescriptors);
            this.ExecuteActions(contextWrapper, peopleDescriptors);

            // action bound with employee instance
            Employee employee = contextWrapper.Execute <Employee>(new Uri(this.ServiceUri + "Person(0)", UriKind.Absolute)).Single();
            IEnumerable <OperationDescriptor> employeeDescriptors    = contextWrapper.GetEntityDescriptor(employee).OperationDescriptors.Where(od => od.Title.Equals(actionName));
            List <Tuple <string, string> >    expectedLinkValuesList = new List <Tuple <string, string> >
            {
                new Tuple <string, string>(ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(0)/" + ActionOverloadingQueryTests.PersonTypeName + "/" + actionTitle),
                new Tuple <string, string>(ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(0)/" + ActionOverloadingQueryTests.EmployeeTypeName + "/" + actionTitle),
            };

            this.VerifyLinks(expectedLinkValuesList, employeeDescriptors);
            this.ExecuteActions(contextWrapper, employeeDescriptors);

            // action bound with special employee instance
            SpecialEmployee specialEmployee = contextWrapper.Execute <SpecialEmployee>(new Uri(this.ServiceUri + "Person(-7)", UriKind.Absolute)).Single();
            IEnumerable <OperationDescriptor> specialEmployeeDescriptors = contextWrapper.GetEntityDescriptor(specialEmployee).OperationDescriptors.Where(od => od.Title.Equals(actionName));

            expectedLinkValuesList = new List <Tuple <string, string> >
            {
                new Tuple <string, string>(ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(-7)/" + ActionOverloadingQueryTests.PersonTypeName + "/" + actionTitle),
                new Tuple <string, string>(ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(-7)/" + ActionOverloadingQueryTests.EmployeeTypeName + "/" + actionTitle),
                new Tuple <string, string>(ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(-7)/" + ActionOverloadingQueryTests.SpecialEmployeeTypeName + "/" + actionTitle),
            };
            this.VerifyLinks(expectedLinkValuesList, specialEmployeeDescriptors);
            this.ExecuteActions(contextWrapper, specialEmployeeDescriptors);

            // action bound with contractor instance
            Contractor contractor = contextWrapper.Execute <Contractor>(new Uri(this.ServiceUri + "Person(1)", UriKind.Absolute)).Single();
            IEnumerable <OperationDescriptor> contractorDescriptors = contextWrapper.GetEntityDescriptor(contractor).OperationDescriptors.Where(od => od.Title.Equals(actionName));

            expectedLinkValuesList = new List <Tuple <string, string> >
            {
                new Tuple <string, string>(ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(1)/" + ActionOverloadingQueryTests.PersonTypeName + "/" + actionTitle),
            };
            this.VerifyLinks(expectedLinkValuesList, contractorDescriptors);
            this.ExecuteActions(contextWrapper, contractorDescriptors);
        }
        // Inconsistent behavior when selecting namespace.* and action name
        // [TestMethod] // github issuse: #896
        public void BaseDerivedTypeOverloadedActionsProjection()
        {
            string actionName = "UpdatePersonInfo";

            for (int i = 0; i < 2; i++)
            {
                var contextWrapper = this.CreateWrappedContext();
                if (i == 1)
                {
                    contextWrapper.Format.UseJson();
                }

                // base type instance, $select=ActionNmae
                Person person = contextWrapper.Execute <Person>(new Uri(this.ServiceUri + "Person(-1)?$select=PersonId," + actionName, UriKind.Absolute)).Single();
                OperationDescriptor personOperationDescriptor = contextWrapper.GetEntityDescriptor(person).OperationDescriptors.Single();
                Assert.AreEqual(this.ServiceUri + ActionOverloadingQueryTests.MetadataPrefix + actionName, personOperationDescriptor.Metadata.AbsoluteUri, true);
                Assert.AreEqual(this.ServiceUri + "Person(-1)/UpdatePersonInfo", personOperationDescriptor.Target.AbsoluteUri, true);

                // base type instance, $select=DerivedType/ActionName
                contextWrapper.Detach(person);
                person = contextWrapper.Execute <Person>(new Uri(this.ServiceUri + "Person(-1)?$select=PersonId," + ActionOverloadingQueryTests.EmployeeTypeName + "/" + actionName, UriKind.Absolute)).Single();
                Assert.AreEqual(0, contextWrapper.GetEntityDescriptor(person).OperationDescriptors.Count);

                // derived type instance, $select=ActionName
                Employee employee = contextWrapper.Execute <Employee>(new Uri(this.ServiceUri + "Person(0)?$select=PersonId," + actionName, UriKind.Absolute)).Single();
                Dictionary <string, string> expectedLinkValues = new Dictionary <string, string>()
                {
                    { ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(0)/" + ActionOverloadingQueryTests.EmployeeTypeName + "/" + actionName },
                };
                IEnumerable <OperationDescriptor> employeeDescriptors = contextWrapper.GetEntityDescriptor(employee).OperationDescriptors;
                this.VerifyLinks(expectedLinkValues, employeeDescriptors);

                // derived type instance, $select=DerivedType/ActionName
                contextWrapper.Detach(employee);
                employee            = contextWrapper.Execute <Employee>(new Uri(this.ServiceUri + "Person(0)?$select=PersonId," + ActionOverloadingQueryTests.EmployeeTypeName + "/" + actionName, UriKind.Absolute)).Single();
                employeeDescriptors = contextWrapper.GetEntityDescriptor(employee).OperationDescriptors;
                this.VerifyLinks(expectedLinkValues, employeeDescriptors);

                // derived type instance, $select=Microsoft.Test.OData.Services.AstoriaDefaultService.*
                SpecialEmployee specialEmployee = contextWrapper.Execute <SpecialEmployee>(new Uri(this.ServiceUri + "Person(-7)?$select=PersonId," + "Microsoft.Test.OData.Services.AstoriaDefaultService.*", UriKind.Absolute)).Single();
                expectedLinkValues = new Dictionary <string, string>()
                {
                    { ActionOverloadingQueryTests.MetadataPrefix + actionName, "Person(-7)/" + ActionOverloadingQueryTests.SpecialEmployeeTypeName + "/" + actionName }
                };
                IEnumerable <OperationDescriptor> specialEmployeeDescriptors = contextWrapper.GetEntityDescriptor(specialEmployee).OperationDescriptors;
                this.VerifyLinks(expectedLinkValues, specialEmployeeDescriptors);

                // derived type instance, $select=BaseType/ActionName
                contextWrapper.Detach(specialEmployee);
                specialEmployee            = contextWrapper.Execute <SpecialEmployee>(new Uri(this.ServiceUri + "Person(-7)?$select=PersonId," + ActionOverloadingQueryTests.EmployeeTypeName + "/" + actionName, UriKind.Absolute)).Single();
                specialEmployeeDescriptors = contextWrapper.GetEntityDescriptor(specialEmployee).OperationDescriptors;
                this.VerifyLinks(expectedLinkValues, specialEmployeeDescriptors);
            }
        }
Exemplo n.º 9
0
        public bool RemoveSpecialEmployee(int Id)
        {
            SpecialEmployee specEmployee = GetSpecialEmployeeById(Id);

            if (specEmployee == null)
            {
                return(false);
            }
            _context.Remove(specEmployee);
            _context.SaveChanges();
            return(true);
        }
Exemplo n.º 10
0
        public void AttachUpdateObjectSave()
        {
            var contextWrapper = this.CreateWrappedContext();
            var specialEmployee = new SpecialEmployee { PersonId = IdOfPerson };
            contextWrapper.AttachTo("Person", specialEmployee);

            specialEmployee.Bonus = Int32.MaxValue;
            contextWrapper.UpdateObject(specialEmployee);
            contextWrapper.SaveChanges();

            var retrievedBonus = contextWrapper.Context.Person.OfType<SpecialEmployee>().Where(p => p.PersonId == specialEmployee.PersonId).Select(p => p.Bonus);
            Assert.AreEqual(Int32.MaxValue, retrievedBonus.Single());
        }
Exemplo n.º 11
0
        public void AddObjectSave()
        {
            var contextWrapper = this.CreateWrappedContext();

            var specialEmployee = new SpecialEmployee {
                PersonId = 1234
            };

            contextWrapper.AddObject("Person", specialEmployee);
            contextWrapper.SaveChanges();

            contextWrapper.DeleteObject(specialEmployee);
            contextWrapper.SaveChanges();
        }
Exemplo n.º 12
0
        private static void LoadPropertyTest(DataServiceContextWrapper <DefaultContainer> contextWrapper)
        {
            // contextWrapper.Context.UndeclaredPropertyBehavior = UndeclaredPropertyBehavior.Support;
            SpecialEmployee specialEmployee =
                contextWrapper.Execute <SpecialEmployee>(new Uri("Person(-10)", UriKind.Relative)).Single();

            contextWrapper.Configurations.ResponsePipeline.OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryId_Reading);
            QueryOperationResponse <Car> cars =
                contextWrapper.LoadProperty(specialEmployee, "Car") as QueryOperationResponse <Car>;

            foreach (Car car in cars)
            {
                EntityDescriptor descriptor = contextWrapper.GetEntityDescriptor(car);
                Assert.IsTrue(descriptor.Identity.OriginalString.Contains("ModifyEntryId"), "Wrong Id");
            }
        }
Exemplo n.º 13
0
        public void AttachUpdateObjectSave()
        {
            var contextWrapper  = this.CreateWrappedContext();
            var specialEmployee = new SpecialEmployee {
                PersonId = IdOfPerson
            };

            contextWrapper.AttachTo("Person", specialEmployee);

            specialEmployee.Bonus = Int32.MaxValue;
            contextWrapper.UpdateObject(specialEmployee);
            contextWrapper.SaveChanges();

            var retrievedBonus = contextWrapper.Context.Person.OfType <SpecialEmployee>().Where(p => p.PersonId == specialEmployee.PersonId).Select(p => p.Bonus);

            Assert.AreEqual(Int32.MaxValue, retrievedBonus.Single());
        }
Exemplo n.º 14
0
        public bool UpdateSpecialEmployee(int Id, SpecialEmployee specEmp)
        {
            SpecialEmployee existSpecialEmployee = GetSpecialEmployeeById(Id);

            if (existSpecialEmployee == null)
            {
                return(false);
            }
            existSpecialEmployee.Name          = specEmp.Name;
            existSpecialEmployee.NationalityId = specEmp.NationalityId;
            existSpecialEmployee.PassportNo    = specEmp.PassportNo;

            _context.Update(existSpecialEmployee);
            _context.SaveChanges();

            return(true);
        }
Exemplo n.º 15
0
        public void LoadPropertyTest()
        {
            this.RunOnAtomAndJsonFormats(
                this.CreateContext,
                (contextWrapper) =>
            {
                contextWrapper.Context.IgnoreMissingProperties = true;
                SpecialEmployee specialEmployee = contextWrapper.Execute <SpecialEmployee>(new Uri("Person(-10)", UriKind.Relative)).Single();

                contextWrapper.Configurations.ResponsePipeline.OnEntryEnded(PipelineEventsTestsHelper.ModifyEntryId_Reading);
                QueryOperationResponse <Car> cars = contextWrapper.LoadProperty(specialEmployee, "Car") as QueryOperationResponse <Car>;
                foreach (Car car in cars)
                {
                    EntityDescriptor descriptor = contextWrapper.GetEntityDescriptor(car);
                    Assert.IsTrue(descriptor.Identity.OriginalString.Contains("ModifyEntryId"), "Wrong Id");
                }
            });
        }
        public void ExcuteBoundAction()
        {
            var contextWrapper = this.CreateWrappedContext();

            contextWrapper.Context.MergeOption = MergeOption.OverwriteChanges;

            Employee employee = (Employee)contextWrapper.Context.Person.Where(p => p.PersonId == 0).Single();

            Assert.AreEqual(85, employee.Salary);

            employee.UpdatePersonInfo();

            SpecialEmployee specialEmployee = (SpecialEmployee)contextWrapper.Context.Person.Where(p => p.PersonId == -7).Single();
            int             salary          = specialEmployee.IncreaseEmployeeSalary().GetValue();

            Assert.AreEqual(2016141257, salary);

            specialEmployee.IncreaseEmployeeSalary().GetValue();
            specialEmployee = (SpecialEmployee)contextWrapper.Context.Person.Where(p => p.PersonId == -7).Single();
            Assert.AreEqual(2016141258, specialEmployee.Salary);
        }
Exemplo n.º 17
0
        public void ContextReferencesTest()
        {
            var contextWrapper = this.CreateWrappedContext();
            Assert.AreEqual(0, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 0");

            var entityFromAttachTo = new SpecialEmployee { PersonId = IdOfPerson };
            contextWrapper.AttachTo("Person", entityFromAttachTo);
            Assert.AreEqual(1, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 1");

            var personMetadata = contextWrapper.Context.PersonMetadata.Where(m => m.Person.PersonId == IdOfPerson).FirstOrDefault();
            Assert.AreEqual(2, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 2");

            contextWrapper.LoadProperty(personMetadata, "Person");
            var entityFromLoadProperty = personMetadata.Person;
            contextWrapper.Detach(personMetadata);
            Assert.AreEqual(1, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 1");
            Assert.IsTrue(entityFromAttachTo == entityFromLoadProperty, "Both variables should reference the same object.");

            var entityFromQuery = contextWrapper.Context.Person.Where(p => p.PersonId == IdOfPerson).SingleOrDefault();
            Assert.AreEqual(1, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 1");
            Assert.IsTrue(entityFromAttachTo == entityFromQuery, "Both variables should reference the same object.");

            var entityFromQueryWithOfType = contextWrapper.Context.Person.OfType<Employee>().Where(p => p.PersonId == IdOfPerson).SingleOrDefault();
            Assert.AreEqual(1, contextWrapper.Context.Entities.Count(), "contextWrapper.Entities.Count() == 1");
            Assert.IsTrue(entityFromAttachTo == entityFromQueryWithOfType, "Both variables should reference the same object.");
        }
 public void UpdatePersonInfo(SpecialEmployee specialEmployee)
 {
     specialEmployee.Title += "[UpdateSpecialEmployeeTitle]";
 }
 public int IncreaseEmployeeSalary(SpecialEmployee specialEmployee)
 {
     specialEmployee.Salary += 1;
     return(specialEmployee.Salary);
 }
Exemplo n.º 20
0
 public int AddSpecialEmployee(SpecialEmployee specEmp)
 {
     _context.SpecialEmployees.Add(specEmp);
     _context.SaveChanges();
     return(specEmp.Id);
 }
Exemplo n.º 21
0
 public static SpecialEmployee CreateSpecialEmployee(int personId,
             int managersPersonId,
             int salary,
             string carsLicensePlate,
             int bonus,
             int bonusLevel, 
             bool isFullyVested)
 {
     SpecialEmployee specialEmployee = new SpecialEmployee();
     specialEmployee.PersonId = personId;
     specialEmployee.ManagersPersonId = managersPersonId;
     specialEmployee.Salary = salary;
     specialEmployee.CarsLicensePlate = carsLicensePlate;
     specialEmployee.Bonus = bonus;
     specialEmployee.BonusLevel = bonusLevel;
     specialEmployee.IsFullyVested = isFullyVested;
     return specialEmployee;
 }
Exemplo n.º 22
0
 public static SpecialEmployee CreateSpecialEmployee(int personId,
             int managersPersonId,
             int salary,
             int carsVIN,
             int bonus,
             bool isFullyVested)
 {
     SpecialEmployee specialEmployee = new SpecialEmployee();
     specialEmployee.PersonId = personId;
     specialEmployee.ManagersPersonId = managersPersonId;
     specialEmployee.Salary = salary;
     specialEmployee.CarsVIN = carsVIN;
     specialEmployee.Bonus = bonus;
     specialEmployee.IsFullyVested = isFullyVested;
     return specialEmployee;
 }