示例#1
0
        public ActionResult Create([Bind(Exclude = "Id")] Account account)
        {
            string userName = this.User.Identity.Name;
            int    sectorId = Int32.Parse(Request.Form["Account.SectorId"]);/*we prefix, as the sector is inside the Account editor*/
            /*and isn't directly bound as field of the Account*/

            //we get the owner the account
            User owner = _userService.GetUser(userName);

            //we get the industrial sector from the db
            IndustrialSector sector = _sectorService.GetIndustrialSector(sectorId);

            account.Owner            = owner;
            account.IndustrialSector = sector;

            if (!_accountService.CreateAccount(account))
            {
                var sectors   = _sectorService.ListIndustrialSectors();
                var viewModel = new AccountViewModel(account)
                {
                    Sectors = new SelectList(sectors, "Id", "Sector")
                };

                return(View(viewModel));
            }

            return(RedirectToAction("Index"));
        }
        public void Delete(IndustrialSector sectorToDelete)
        {
            var originalIndustrialSector = Get(sectorToDelete.Id);

            _entities.DeleteObject(originalIndustrialSector);
            _entities.SaveChanges();
        }
示例#3
0
        public void SetValue_WithObjectList_NewCollectionAlreadyAssociated()
        {
            var sector1 = IndustrialSector.NewObject();
            var sector2 = IndustrialSector.NewObject();

            CreateAccessor(sector1, "Companies").SetValue(sector2.Companies);
        }
示例#4
0
        private void sectorBindingNavigatorEditItem_Click(object sender, System.EventArgs e)
        {
            IndustrialSector sectorToEdit = (IndustrialSector)sectorsBindingSource.Current;

            CreateEditSectorForm form = new CreateEditSectorForm(sectorToEdit, true /*editMode*/);

            form.ShowDialog(this);
        }
示例#5
0
 public ActionResult Delete(IndustrialSector industrialSector)
 {
     if (!_sectorService.DeleteIndustrialSector(industrialSector))
     {
         return(View(industrialSector));
     }
     return(RedirectToAction("Index"));
 }
        public IndustrialSector Update(IndustrialSector sectorToUpdate)
        {
            var originalIndustrialSector = Get(sectorToUpdate.Id);

            _entities.ApplyCurrentValues(originalIndustrialSector.EntityKey.EntitySetName, sectorToUpdate);
            _entities.SaveChanges();
            return(sectorToUpdate);
        }
        public override void SetUp()
        {
            base.SetUp();

            _newIndustrialSector = IndustrialSector.NewObject();
            _newCompany1         = Company.NewObject();
            _newCompany2         = Company.NewObject();
        }
示例#8
0
        public override void SetUp()
        {
            base.SetUp();

            _transaction      = ClientTransaction.CreateRootTransaction();
            _industrialSector = _transaction.ExecuteInScope(() => IndustrialSector.NewObject());
            _order            = _transaction.ExecuteInScope(() => Order.NewObject());
        }
示例#9
0
        public ActionResult Create([Bind(Exclude = "Id")] IndustrialSector industrialSector)
        {
            if (!_sectorService.CreateIndustrialSector(industrialSector))
            {
                return(View(industrialSector));
            }

            return(RedirectToAction("Index"));
        }
示例#10
0
        public void HasBeenTouchedSimple()
        {
            IndustrialSector sector   = DomainObjectIDs.IndustrialSector1.GetObject <IndustrialSector> ();
            PropertyAccessor property = CreateAccessor(sector, "Name");

            Assert.That(property.HasBeenTouched, Is.False);
            property.SetValueWithoutTypeCheck(property.GetValueWithoutTypeCheck());
            Assert.That(property.HasBeenTouched, Is.True);
        }
示例#11
0
        public void HasBeenTouchedRelatedCollection()
        {
            IndustrialSector sector   = DomainObjectIDs.IndustrialSector1.GetObject <IndustrialSector> ();
            PropertyAccessor property = CreateAccessor(sector, "Companies");

            Assert.That(property.HasBeenTouched, Is.False);
            ((DomainObjectCollection)property.GetValueWithoutTypeCheck())[0] = ((DomainObjectCollection)property.GetValueWithoutTypeCheck())[0];
            Assert.That(property.HasBeenTouched, Is.True);
        }
示例#12
0
        public bool ValidateIndustrialSector(IndustrialSector sectorToValidate)
        {
            //convert null values to empty strings
            sectorToValidate.Sector = sectorToValidate.Sector ?? "";

            if (sectorToValidate.Sector.Trim().Length == 0)
            {
                _validationDictionary.AddError("Sector", "Sector is required.");
            }
            return(_validationDictionary.IsValid);
        }
        public void CommitWithMandatoryOneToManyRelationNotSet()
        {
            IndustrialSector industrialSector = DomainObjectIDs.IndustrialSector2.GetObject<IndustrialSector> ();
              industrialSector.Companies.Clear();

              Assert.That (
              () => TestableClientTransaction.Commit(),
              Throws.TypeOf<MandatoryRelationNotSetException>().With.Message.EqualTo (
              "Mandatory relation property 'Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Companies' of domain object"
              + " 'IndustrialSector|8565a077-ea01-4b5d-beaa-293dc484bddc|System.Guid' contains no items."));
        }
        public void VirtualEndPointQuery_OneMany_ObjectIncluded_ThatLocallyPointsToSomewhereElse()
        {
            SetDatabaseModifyable();

            var company = CreateCompanyInDatabaseAndLoad();

            Assert.That(company.IndustrialSector, Is.Null);

            var industrialSector = DomainObjectIDs.IndustrialSector1.GetObject <IndustrialSector> (); // virtual end point not yet resolved

            SetIndustrialSectorInOtherTransaction(company.ID, industrialSector.ID);

            // Resolve virtual end point - the database says that company points to industrialSector, but the transaction says it points to null!
            var companiesOfIndustrialSector = industrialSector.Companies;

            companiesOfIndustrialSector.EnsureDataComplete();

            Assert.That(company.IndustrialSector, Is.Null);
            Assert.That(companiesOfIndustrialSector, Has.Member(company));

            CheckSyncState(company, c => c.IndustrialSector, true);
            CheckSyncState(industrialSector, s => s.Companies, false);

            var otherCompany = companiesOfIndustrialSector.FirstOrDefault(c => c != company);

            CheckSyncState(otherCompany, c => c.IndustrialSector, true);

            CheckActionWorks(company.Delete);
            TestableClientTransaction.Rollback(); // required so that the remaining actions can be tried below

            // sync states not changed by Rollback
            CheckSyncState(company, c => c.IndustrialSector, true);
            CheckSyncState(industrialSector, s => s.Companies, false);

            CheckActionWorks(() => industrialSector.Companies.Remove(otherCompany));
            CheckActionWorks(() => industrialSector.Companies.Add(Company.NewObject()));

            var companyIndex = industrialSector.Companies.IndexOf(company);

            CheckActionThrows <InvalidOperationException> (industrialSector.Delete, "out of sync with the opposite object property");
            CheckActionThrows <InvalidOperationException> (() => industrialSector.Companies.Remove(company), "out of sync with the opposite object property");
            CheckActionThrows <InvalidOperationException> (() => industrialSector.Companies[companyIndex] = Company.NewObject(), "out of sync with the opposite object property");
            CheckActionThrows <InvalidOperationException> (() => industrialSector.Companies = new ObjectList <Company> (), "out of sync with the opposite object property");
            CheckActionThrows <InvalidOperationException> (industrialSector.Delete, "out of sync with the opposite object property");

            CheckActionWorks(() => company.IndustrialSector = IndustrialSector.NewObject());

            BidirectionalRelationSyncService.Synchronize(ClientTransaction.Current, RelationEndPointID.Resolve(industrialSector, s => s.Companies));

            CheckSyncState(industrialSector, s => s.Companies, true);
            Assert.That(companiesOfIndustrialSector, Has.No.Member(company));

            CheckActionWorks(() => industrialSector.Companies.Add(company));
        }
示例#15
0
 public bool DeleteIndustrialSector(IndustrialSector sectorToDelete)
 {
     try
     {
         _repository.Delete(sectorToDelete);
     }
     catch
     {
         return(false);
     }
     return(true);
 }
示例#16
0
        public void SetValue_WithObjectList()
        {
            IndustrialSector sector = IndustrialSector.NewObject();
            var newCompanies        = new ObjectList <Company> ();
            var oldCompanies        = sector.Companies;

            CreateAccessor(sector, "Companies").SetValue(newCompanies);

            Assert.That(sector.Companies, Is.SameAs(newCompanies));
            Assert.That(sector.Companies.AssociatedEndPointID, Is.Not.Null);
            Assert.That(oldCompanies.AssociatedEndPointID, Is.Null);
        }
示例#17
0
        public void ModifyOtherObjects()
        {
            _customer.Name = "New name";

            Ceo ceo = _customer.Ceo;

            ceo.Name = "New CEO name";

            Order            order            = _customer.Orders[DomainObjectIDs.Order1];
            IndustrialSector industrialSector = _customer.IndustrialSector;

            var ceoEventReceiver               = new DomainObjectEventReceiver(ceo);
            var customerEventReceiver          = new DomainObjectEventReceiver(_customer);
            var orderEventReceiver             = new DomainObjectEventReceiver(order);
            var industrialSectorEventReceiver  = new DomainObjectEventReceiver(industrialSector);
            var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction);

            _customer.Committing += (sender, e) => order.OrderNumber = 1000;
            TestableClientTransaction.Committing += (sender1, args) =>
            {
                var customer = (Customer)args.DomainObjects.SingleOrDefault(obj => obj.ID == DomainObjectIDs.Customer1);
                if (customer != null)
                {
                    customer.IndustrialSector.Name = "New industrial sector name";
                }
            };

            TestableClientTransaction.Commit();

            Assert.That(ceoEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(ceoEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(customerEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(customerEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(orderEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(orderEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(industrialSectorEventReceiver.HasCommittingEventBeenCalled, Is.True);
            Assert.That(industrialSectorEventReceiver.HasCommittedEventBeenCalled, Is.True);

            Assert.That(clientTransactionEventReceiver.CommittingDomainObjectLists.Count, Is.EqualTo(2));
            Assert.That(clientTransactionEventReceiver.CommittedDomainObjectLists.Count, Is.EqualTo(1));

            var committingDomainObjectsForFirstCommitEvent  = clientTransactionEventReceiver.CommittingDomainObjectLists[0];
            var committingDomainObjectsForSecondCommitEvent = clientTransactionEventReceiver.CommittingDomainObjectLists[1];
            var committedDomainObjects = clientTransactionEventReceiver.CommittedDomainObjectLists[0];

            Assert.That(committingDomainObjectsForFirstCommitEvent, Is.EquivalentTo(new DomainObject[] { _customer, ceo }));
            Assert.That(committingDomainObjectsForSecondCommitEvent, Is.EquivalentTo(new DomainObject[] { order, industrialSector }));
            Assert.That(committedDomainObjects, Is.EquivalentTo(new DomainObject[] { _customer, ceo, order, industrialSector }));
        }
示例#18
0
        public void ChangeWithInheritance()
        {
            IndustrialSector industrialSector = DomainObjectIDs.IndustrialSector1.GetObject <IndustrialSector> ();
            Partner          partner          = DomainObjectIDs.Partner2.GetObject <Partner> ();

            Assert.That(industrialSector.Companies[partner.ID], Is.Null);
            Assert.That(ReferenceEquals(industrialSector, partner.IndustrialSector), Is.False);

            industrialSector.Companies.Add(partner);

            Assert.That(industrialSector.Companies[partner.ID], Is.Not.Null);
            Assert.That(partner.IndustrialSector, Is.SameAs(industrialSector));
        }
示例#19
0
        public void SetValue_WithObjectList_PerformsBidirectionalChange()
        {
            var sector  = IndustrialSector.NewObject();
            var company = Company.NewObject();

            var newCompanies = new ObjectList <Company> {
                company
            };

            CreateAccessor(sector, "Companies").SetValue(newCompanies);

            Assert.That(company.IndustrialSector, Is.SameAs(sector));
        }
        public void VirtualEndPointQuery_OneMany_ObjectIncluded_ThatLocallyPointsToSomewhereElse()
        {
            Company          company;
            IndustrialSector industrialSector; // virtual end point not yet resolved

            using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope())
            {
                PrepareInconsistentState_OneMany_ObjectIncluded(out company, out industrialSector);

                CheckSyncState(company, c => c.IndustrialSector, true);
                CheckSyncState(industrialSector, s => s.Companies, false);

                var otherCompany = industrialSector.Companies.FirstOrDefault(c => c != company);
                CheckSyncState(otherCompany, c => c.IndustrialSector, true);

                CheckActionWorks(company.Delete);
                ClientTransaction.Current.Rollback(); // required so that the remaining actions can be tried below

                // sync states not changed by Rollback
                CheckSyncState(company, c => c.IndustrialSector, true);
                CheckSyncState(industrialSector, s => s.Companies, false);

                CheckActionWorks(() => industrialSector.Companies.Remove(otherCompany));
                CheckActionWorks(() => industrialSector.Companies.Add(Company.NewObject()));

                var companyIndex = industrialSector.Companies.IndexOf(company);
                CheckActionThrows <InvalidOperationException> (
                    () => industrialSector.Companies.Remove(company), "out of sync with the opposite object property");
                CheckActionThrows <InvalidOperationException> (
                    () => industrialSector.Companies[companyIndex] = Company.NewObject(), "out of sync with the opposite object property");
                CheckActionThrows <InvalidOperationException> (
                    () => industrialSector.Companies = new ObjectList <Company>(), "out of sync with the opposite object property");
                CheckActionThrows <InvalidOperationException> (industrialSector.Delete, "out of sync with the opposite object property");

                CheckActionWorks(() => company.IndustrialSector = IndustrialSector.NewObject());

                BidirectionalRelationSyncService.Synchronize(ClientTransaction.Current, RelationEndPointID.Resolve(industrialSector, s => s.Companies));

                CheckSyncState(industrialSector, s => s.Companies, true);
                Assert.That(industrialSector.Companies, Has.No.Member(company));

                CheckActionWorks(() => industrialSector.Companies.Add(company));
            }

            CheckSyncState(company, c => c.IndustrialSector, true);
            CheckSyncState(industrialSector, s => s.Companies, true);

            Assert.That(company.IndustrialSector, Is.Null);
            Assert.That(industrialSector.Companies, Has.No.Member(company));
        }
        public void GetRelatedObjectsWithDerivation()
        {
            IndustrialSector       industrialSector = DomainObjectIDs.IndustrialSector2.GetObject <IndustrialSector> ();
            DomainObjectCollection collection       = industrialSector.Companies;

            Assert.That(collection.Count, Is.EqualTo(7));
            Assert.That(collection[DomainObjectIDs.Company1].GetPublicDomainObjectType(), Is.EqualTo(typeof(Company)));
            Assert.That(collection[DomainObjectIDs.Company2].GetPublicDomainObjectType(), Is.EqualTo(typeof(Company)));
            Assert.That(collection[DomainObjectIDs.Customer2].GetPublicDomainObjectType(), Is.EqualTo(typeof(Customer)));
            Assert.That(collection[DomainObjectIDs.Customer3].GetPublicDomainObjectType(), Is.EqualTo(typeof(Customer)));
            Assert.That(collection[DomainObjectIDs.Partner2].GetPublicDomainObjectType(), Is.EqualTo(typeof(Partner)));
            Assert.That(collection[DomainObjectIDs.Supplier2].GetPublicDomainObjectType(), Is.EqualTo(typeof(Supplier)));
            Assert.That(collection[DomainObjectIDs.Distributor1].GetPublicDomainObjectType(), Is.EqualTo(typeof(Distributor)));
        }
        public void MandatoryRelationNotSetExceptionForOneToManyRelation()
        {
            IndustrialSector newIndustrialSector = IndustrialSector.NewObject();

              Assert.That (
              () => TestableClientTransaction.Commit(),
              Throws.TypeOf<MandatoryRelationNotSetException>().With.Message.EqualTo (
              string.Format (
                  "Mandatory relation property 'Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Companies' of domain object '{0}' contains no items.",
                  newIndustrialSector.ID))
              .And.Property<MandatoryRelationNotSetException> (ex => ex.PropertyName).EqualTo (
                  "Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Companies")
              .And.Property<MandatoryRelationNotSetException> (ex => ex.DomainObject).SameAs (newIndustrialSector));
        }
示例#23
0
        public ActionResult Edit(IndustrialSector industrialSector)
        {
            // normaly we should have those parameters : "Edit(int id, FormCollection values)"
            // Then we would retrieve the existing sector from db (by his id) and then update the
            // fields with the form posted values.But in this specific case we can directly
            // pass an "IndustrialSector" instance, the binder has automatically bound the "id"
            // field from the request(/Sector/Edit/{id}) and the "sector" field from the form.
            // ...

            if (!_sectorService.EditIndustrialSector(industrialSector))
            {
                return(View(industrialSector));
            }

            return(RedirectToAction("Index"));
        }
示例#24
0
        protected IndustrialSector CreateIndustrialSectorInDatabaseAndLoad()
        {
            ObjectID objectID;

            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                IndustrialSector industrialSector = IndustrialSector.NewObject();
                Company          oldCompany       = Company.NewObject();
                oldCompany.Ceo = Ceo.NewObject();
                industrialSector.Companies.Add(oldCompany);
                objectID = industrialSector.ID;

                ClientTransaction.Current.Commit();
            }
            return(objectID.GetObject <IndustrialSector> ());
        }
示例#25
0
        public void SetValue_WithObjectList_Notifies()
        {
            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction);

            IndustrialSector sector = IndustrialSector.NewObject();
            var newCompanies        = new ObjectList <Company> {
                Company.NewObject()
            };

            var propertyAccessor = CreateAccessor(sector, "Companies");

            propertyAccessor.SetValue(newCompanies);

            listenerMock.AssertWasCalled(
                mock => mock.RelationChanged(TestableClientTransaction, sector, propertyAccessor.PropertyData.RelationEndPointDefinition, null, newCompanies[0]));
        }
示例#26
0
        private Order GetDeepTestGraph()
        {
            Order root = Order.NewObject();

            root.Official    = Official.NewObject();
            root.OrderTicket = OrderTicket.NewObject();
            root.OrderItems.Add(OrderItem.NewObject());
            root.OrderItems.Add(OrderItem.NewObject());
            root.Customer     = Customer.NewObject();
            root.Customer.Ceo = Ceo.NewObject();
            root.Customer.IndustrialSector = IndustrialSector.NewObject();
            root.Customer.IndustrialSector.Companies.Add(Company.NewObject());
            root.Customer.IndustrialSector.Companies[1].Ceo = Ceo.NewObject();
            root.Customer.IndustrialSector.Companies.Add(Company.NewObject());
            root.Customer.IndustrialSector.Companies[2].Ceo = Ceo.NewObject();
            return(root);
        }
示例#27
0
        public void Construction()
        {
            var transaction = ClientTransaction.CreateRootTransaction();
            IndustrialSector sector;

            using (transaction.EnterNonDiscardingScope())
            {
                sector = IndustrialSector.NewObject();
            }
            var data = new PropertyAccessorData(sector.ID.ClassDefinition, typeof(IndustrialSector).FullName + ".Name");

            var propertyAccessor = new PropertyAccessor(sector, data, transaction);

            Assert.That(propertyAccessor.DomainObject, Is.SameAs(sector));
            Assert.That(propertyAccessor.PropertyData, Is.SameAs(data));
            Assert.That(propertyAccessor.ClientTransaction, Is.SameAs(transaction));
        }
示例#28
0
        public void HasChangedAndOriginalValueSimple()
        {
            IndustrialSector sector   = DomainObjectIDs.IndustrialSector1.GetObject <IndustrialSector> ();
            PropertyAccessor property = CreateAccessor(sector, "Name");

            Assert.That(property.HasChanged, Is.False);
            var originalValue = property.GetValue <string>();

            Assert.That(originalValue, Is.Not.Null);
            Assert.That(property.GetOriginalValue <string> (), Is.EqualTo(originalValue));

            property.SetValue("Foo");
            Assert.That(property.HasChanged, Is.True);
            Assert.That(property.GetValue <string>(), Is.EqualTo("Foo"));
            Assert.That(property.GetOriginalValue <string> (), Is.Not.EqualTo(property.GetValue <string>()));
            Assert.That(property.GetOriginalValue <string> (), Is.EqualTo(originalValue));
        }
示例#29
0
        public CreateEditSectorForm(IndustrialSector sector, bool editMode)
        {
            InitializeComponent();

            _sector   = sector;
            _editMode = editMode;

            _modelState    = new Dictionary <string, string>();
            _sectorService = new IndustrialSectorService(new SimpleModelStateWrapper(_modelState));

            if (_editMode)
            {
                this.Text = "Edit Sector";
                this.createEditButton.Text = "Save";
            }

            this.sectorBindingSource.DataSource = _sector;
        }
示例#30
0
        public void GetValue_SetValue()
        {
            IndustrialSector sector = IndustrialSector.NewObject();

            Company company = Company.NewObject();

            company.IndustrialSector = sector;
            Assert.AreSame(sector, company.IndustrialSector, "related object");

            Assert.IsTrue(sector.Companies.ContainsObject(company), "related objects");
            var newCompanies = new ObjectList <Company> ();

            sector.Companies = newCompanies;
            Assert.That(sector.Companies, Is.SameAs(newCompanies));

            sector.Name = "Foo";
            Assert.AreEqual("Foo", sector.Name, "property value");
        }