public void TestExpirationWithNullValueWillSave()
        {
            #region Arrange
            var record = GetValid(99);
            record.Expiration = null;
            #endregion Arrange

            #region Act
            AutoApprovalRepository.DbContext.BeginTransaction();
            AutoApprovalRepository.EnsurePersistent(record);
            AutoApprovalRepository.DbContext.CommitChanges();
            #endregion Act

            #region Assert
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            Assert.AreEqual(null, record.Expiration);
            #endregion Assert
        }
예제 #2
0
        public void TestDeletePostRedirectsToIndexWhenAutoApprovalNotFound3()
        {
            #region Arrange
            SetupData3();
            #endregion Arrange

            #region Act
            var result = Controller.Delete(4, new AutoApproval())
                         .AssertActionRedirect()
                         .ToAction <AutoApprovalController>(a => a.Index(false));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(false, result.RouteValues["showAll"]);
            AutoApprovalRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <AutoApproval> .Is.Anything));
            AutoApprovalRepository.AssertWasNotCalled(a => a.Remove(Arg <AutoApproval> .Is.Anything));
            #endregion Assert
        }
        public void TestUserWithAPopulatedValueSaves()
        {
            #region Arrange
            AutoApproval autoApproval = GetValid(9);
            autoApproval.User = UserRepository.Queryable.Single(a => a.Id == "3");
            #endregion Arrange

            #region Act
            AutoApprovalRepository.DbContext.BeginTransaction();
            AutoApprovalRepository.EnsurePersistent(autoApproval);
            AutoApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.AreEqual("3", autoApproval.User.Id);
            Assert.IsFalse(autoApproval.IsTransient());
            Assert.IsTrue(autoApproval.IsValid());
            #endregion Assert
        }
        public void TestIsActiveIsTrueSaves()
        {
            #region Arrange
            var autoApproval = GetValid(9);
            autoApproval.IsActive = true;
            #endregion Arrange

            #region Act
            AutoApprovalRepository.DbContext.BeginTransaction();
            AutoApprovalRepository.EnsurePersistent(autoApproval);
            AutoApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsTrue(autoApproval.IsActive);
            Assert.IsFalse(autoApproval.IsTransient());
            Assert.IsTrue(autoApproval.IsValid());
            #endregion Assert
        }
        public void TestLessThanIsFalseSaves()
        {
            #region Arrange
            AutoApproval autoApproval = GetValid(9);
            autoApproval.LessThan = false;
            #endregion Arrange

            #region Act
            AutoApprovalRepository.DbContext.BeginTransaction();
            AutoApprovalRepository.EnsurePersistent(autoApproval);
            AutoApprovalRepository.DbContext.CommitTransaction();
            #endregion Act

            #region Assert
            Assert.IsFalse(autoApproval.LessThan);
            Assert.IsFalse(autoApproval.IsTransient());
            Assert.IsTrue(autoApproval.IsValid());
            #endregion Assert
        }
        public void TestMaxAmount3()
        {
            #region Arrange
            var record = CreateValidEntities.AutoApproval(99);
            record.MaxAmount = 99999999.99m;
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual(99999999.99m, record.MaxAmount);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
예제 #7
0
        public void TestDeletePostRedirectsWhenAlreadyDeactivated()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "NotMe");
            SetupData3();
            #endregion Arrange

            #region Act
            var result = Controller.Delete(1, new AutoApproval(), true)
                         .AssertActionRedirect()
                         .ToAction <AutoApprovalController>(a => a.Index(true));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(true, result.RouteValues["showAll"]);
            AutoApprovalRepository.AssertWasNotCalled(a => a.EnsurePersistent(Arg <AutoApproval> .Is.Anything));
            AutoApprovalRepository.AssertWasNotCalled(a => a.Remove(Arg <AutoApproval> .Is.Anything));
            #endregion Assert
        }
 public void Setup()
 {
     _transactionScope       = new TransactionScope();
     _autoApprovalRepository =
         new AutoApprovalRepository(ConfigurationManager.ConnectionStrings["Unity"].ConnectionString);
     _docTypeRepository    = new DocTypeRepository(ConfigurationManager.ConnectionStrings["Unity"].ConnectionString);
     _subDocTypeRepository = new SubDocTypeRepository(ConfigurationManager.ConnectionStrings["Unity"].ConnectionString);
     _manCoRepository      = new ManCoRepository(ConfigurationManager.ConnectionStrings["Unity"].ConnectionString);
     _docType      = BuildMeA.DocType("code", "description");
     _manCo1       = BuildMeA.ManCo("code1", "description1");
     _manCo2       = BuildMeA.ManCo("code2", "description2");
     _subDocType1  = BuildMeA.SubDocType("code 1", "description 1").WithDocType(_docType);
     _subDocType2  = BuildMeA.SubDocType("code 2", "description 3").WithDocType(_docType);
     _autoApproval =
         BuildMeA.AutoApproval().WithDocType(_docType).WithSubDocType(_subDocType1).WithManCo(_manCo1);
     _autoApproval2 =
         BuildMeA.AutoApproval().WithDocType(_docType).WithSubDocType(_subDocType2).WithManCo(_manCo2);
     _autoApproval3 =
         BuildMeA.AutoApproval().WithDocType(_docType).WithSubDocType(_subDocType2).WithManCo(_manCo1);
 }
        public void TestExpirationWithFutureDateDateWillSave()
        {
            #region Arrange
            var compareDate = DateTime.UtcNow.ToPacificTime().AddDays(15);
            var record      = GetValid(99);
            record.Expiration = compareDate;
            #endregion Arrange

            #region Act
            AutoApprovalRepository.DbContext.BeginTransaction();
            AutoApprovalRepository.EnsurePersistent(record);
            AutoApprovalRepository.DbContext.CommitChanges();
            #endregion Act

            #region Assert
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            Assert.AreEqual(compareDate, record.Expiration);
            #endregion Assert
        }
        public void TestAutoApprovalAccountIfPopulatedSaves()
        {
            #region Arrange
            var record = CreateValidEntities.AutoApproval(99);
            record.TargetUser = null;
            record.Account    = AccountRepository.Queryable.Single(a => a.Id == "3");
            #endregion Arrange

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

            #region Assert
            Assert.AreEqual("3", record.Account.Id);
            Assert.IsFalse(record.IsTransient());
            Assert.IsTrue(record.IsValid());
            #endregion Assert
        }
예제 #11
0
        public void TestCreatePostRedirectsWhenValid7()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            SetupData2();
            var autoApprovalToCreate = CreateValidEntities.AutoApproval(9);
            autoApprovalToCreate.User       = null;
            autoApprovalToCreate.TargetUser = CreateValidEntities.User(66);
            autoApprovalToCreate.Account    = null;
            autoApprovalToCreate.MaxAmount  = (decimal)765.32;
            autoApprovalToCreate.LessThan   = false;
            autoApprovalToCreate.Equal      = true;
            autoApprovalToCreate.Expiration = DateTime.UtcNow.ToPacificTime().Date.AddDays(1);
            #endregion Arrange

            #region Act
            var result = Controller.Create(autoApprovalToCreate, true)
                         .AssertActionRedirect()
                         .ToAction <AutoApprovalController>(a => a.Index(true));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(true, result.RouteValues["showAll"]);
            AutoApprovalRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <AutoApproval> .Is.Anything));
            var args = (AutoApproval)AutoApprovalRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <AutoApproval> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.AreEqual("Me", args.User.Id);
            Assert.AreEqual((decimal)765.32, args.MaxAmount);
            Assert.IsFalse(args.LessThan);
            Assert.IsTrue(args.Equal);
            Assert.AreEqual("LastName66", args.TargetUser.LastName);
            Assert.IsNull(args.Account);
            Assert.AreEqual(DateTime.UtcNow.ToPacificTime().Date.AddDays(1), args.Expiration);
            Assert.AreEqual("AutoApproval Created Successfully Warning, will expire in 5 days or less", Controller.Message);
            #endregion Assert
        }
예제 #12
0
        public void TestDeletePostRedirectsToErrorWhenValid()
        {
            #region Arrange
            Controller.ControllerContext.HttpContext = new MockHttpContext(0, new[] { "" }, "Me");
            SetupData3();
            #endregion Arrange

            #region Act
            var result = Controller.Delete(3, new AutoApproval(), true)
                         .AssertActionRedirect()
                         .ToAction <AutoApprovalController>(a => a.Index(true));
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(true, result.RouteValues["showAll"]);
            Assert.AreEqual("AutoApproval Deactivated Successfully", Controller.Message);
            AutoApprovalRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <AutoApproval> .Is.Anything));
            var args = (AutoApproval)AutoApprovalRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <AutoApproval> .Is.Anything))[0][0];
            Assert.IsNotNull(args);
            Assert.IsFalse(args.IsActive);
            AutoApprovalRepository.AssertWasNotCalled(a => a.Remove(Arg <AutoApproval> .Is.Anything));
            #endregion Assert
        }
        public void TestUserWithNewValueDoesNotSave()
        {
            AutoApproval autoApproval = null;

            try
            {
                #region Arrange
                autoApproval      = GetValid(9);
                autoApproval.User = new User();
                #endregion Arrange

                #region Act
                AutoApprovalRepository.DbContext.BeginTransaction();
                AutoApprovalRepository.EnsurePersistent(autoApproval);
                AutoApprovalRepository.DbContext.CommitTransaction();
                #endregion Act
            }
            catch (Exception ex)
            {
                Assert.IsNotNull(autoApproval);
                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;
            }
        }