Exemple #1
0
        public void TestWorkgroupAccountNewPurchaserDoesNotSave()
        {
            var thisFar = false;

            try
            {
                #region Arrange
                var record = GetValid(9);
                record.Purchaser = new User();
                thisFar          = true;
                #endregion Arrange

                #region Act
                WorkgroupAccountRepository.DbContext.BeginTransaction();
                WorkgroupAccountRepository.EnsurePersistent(record);
                WorkgroupAccountRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsTrue(thisFar);
                Assert.IsNotNull(ex);
                Assert.AreEqual("object references an unsaved transient instance - save the transient instance before flushing or set cascade action for the property to something that would make it autosave. Type: Purchasing.Core.Domain.User, Entity: Purchasing.Core.Domain.User", ex.Message);
                throw;
            }
        }
Exemple #2
0
        public void TestWorkgroupAccountsFieldAccountWithAValueOfNullDoesNotSave()
        {
            WorkgroupAccount record = null;

            try
            {
                #region Arrange
                record         = GetValid(9);
                record.Account = null;
                #endregion Arrange

                #region Act
                WorkgroupAccountRepository.DbContext.BeginTransaction();
                WorkgroupAccountRepository.EnsurePersistent(record);
                WorkgroupAccountRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception)
            {
                Assert.IsNotNull(record);
                Assert.AreEqual(record.Account, null);
                var results = record.ValidationResults().AsMessageList();
                results.AssertErrorsAre("The Account field is required.");
                Assert.IsTrue(record.IsTransient());
                Assert.IsFalse(record.IsValid());
                throw;
            }
        }
Exemple #3
0
        public void TestAddAccountPostRedirectsToAccountsWhenValid()
        {
            #region Arrange
            SetupDataForAccounts1();
            var workgroupAccountToCreate = CreateValidEntities.WorkgroupAccount(9);
            workgroupAccountToCreate.Workgroup = WorkgroupRepository.GetNullableById(2); //This one will be replaced
            workgroupAccountToCreate.Account.SetIdTo("Blah");
            workgroupAccountToCreate.AccountManager.SetIdTo("AccMan");
            workgroupAccountToCreate.Approver.SetIdTo("App");
            workgroupAccountToCreate.Purchaser.SetIdTo("Purchase");
            #endregion Arrange

            #region Act
            var result = Controller.AddAccount(3, workgroupAccountToCreate, null)
                         .AssertActionRedirect()
                         .ToAction <WorkgroupController>(a => a.Accounts(3));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.RouteValues["id"]);
            Assert.AreEqual("Workgroup account saved.", Controller.Message);

            WorkgroupAccountRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <WorkgroupAccount> .Is.Anything));
            var args = (WorkgroupAccount)WorkgroupAccountRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <WorkgroupAccount> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual(3, args.Workgroup.Id);
            Assert.AreEqual("Blah", args.Account.Id);
            Assert.AreEqual("AccMan", args.AccountManager.Id);
            Assert.AreEqual("App", args.Approver.Id);
            Assert.AreEqual("Purchase", args.Purchaser.Id);
            #endregion Assert
        }
Exemple #4
0
        public void TestWorkgroupAccountWithNullPurchaserSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Purchaser = null;
            #endregion Arrange

            #region Act
            WorkgroupAccountRepository.DbContext.BeginTransaction();
            WorkgroupAccountRepository.EnsurePersistent(record);
            WorkgroupAccountRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(null, record.Purchaser);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Exemple #5
0
        public void TestWorkgroupAccountWithExistingPurchaserSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Purchaser = UserRepository.Queryable.Single(a => a.Id == "3");
            #endregion Arrange

            #region Act
            WorkgroupAccountRepository.DbContext.BeginTransaction();
            WorkgroupAccountRepository.EnsurePersistent(record);
            WorkgroupAccountRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual("3", record.Purchaser.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Exemple #6
0
        public void TestWorkgroupAccountWithExistingWorkgroupSaves()
        {
            #region Arrange
            var record = GetValid(9);
            record.Workgroup = Repository.OfType <Workgroup>().Queryable.Single(a => a.Id == 3);
            #endregion Arrange

            #region Act
            WorkgroupAccountRepository.DbContext.BeginTransaction();
            WorkgroupAccountRepository.EnsurePersistent(record);
            WorkgroupAccountRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual(3, record.Workgroup.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
Exemple #7
0
        public void TestAddAccountPostReturnsViewWhenInvalid()
        {
            #region Arrange
            SetupDataForAccounts1();
            var workgroupAccountToCreate = CreateValidEntities.WorkgroupAccount(9);
            workgroupAccountToCreate.Workgroup = WorkgroupRepository.GetNullableById(2); //This one will be replaced
            //workgroupAccountToCreate.Account.SetIdTo("Blah");
            workgroupAccountToCreate.Account = null;
            workgroupAccountToCreate.AccountManager.SetIdTo("AccMan");
            workgroupAccountToCreate.Approver.SetIdTo("App");
            workgroupAccountToCreate.Purchaser.SetIdTo("Purchase");

            new FakeAccounts(0, AccountRepository);
            #endregion Arrange

            #region Act
            var result = Controller.AddAccount(3, workgroupAccountToCreate, null)
                         .AssertViewRendered()
                         .WithViewData <WorkgroupAccountModel>();
            #endregion Act

            #region Assert
            Controller.ModelState.AssertErrorsAre("Account not found");
            WorkgroupAccountRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <WorkgroupAccount> .Is.Anything));

            Assert.IsNotNull(result);
            Assert.AreEqual(10, result.Accounts.Count());
            Assert.AreEqual(12, result.WorkGroupPermissions.Count());
            Assert.AreEqual(1, result.Approvers.Count());
            Assert.AreEqual(1, result.AccountManagers.Count());
            Assert.AreEqual(1, result.Purchasers.Count());
            Assert.IsNotNull(result.WorkgroupAccount);
            Assert.AreEqual(0, result.WorkgroupAccount.Id);

            Assert.AreEqual(3, result.WorkgroupAccount.Workgroup.Id);
            Assert.AreEqual(null, result.WorkgroupAccount.Account);
            Assert.AreEqual("AccMan", result.WorkgroupAccount.AccountManager.Id);
            Assert.AreEqual("App", result.WorkgroupAccount.Approver.Id);
            Assert.AreEqual("Purchase", result.WorkgroupAccount.Purchaser.Id);
            #endregion Assert
        }