コード例 #1
0
        public void TestUpdateOrderReturnsFalseWhenException()
        {
            #region Arrange
            var customFields = new List <CustomField>();
            var org          = CreateValidEntities.Organization(9);
            org.SetIdTo("9");
            for (int i = 0; i < 5; i++)
            {
                customFields.Add(CreateValidEntities.CustomField(i + 1));
                customFields[i].Organization = org;
                customFields[i].Rank         = i + 1;
            }

            customFields[4].Rank         = 1;
            customFields[0].Organization = CreateValidEntities.Organization(8);
            customFields[0].Organization.SetIdTo("8");
            new FakeCustomFields(0, CustomFieldRepository, customFields);
            var idsToReorder = new List <int>()
            {
                1, 4, 3, 2, 5, 99
            };

            CustomFieldRepository.Expect(a => a.EnsurePersistent(Arg <CustomField> .Is.Anything))
            .Throw(new ApplicationException("Fake Exception"));

            #endregion Arrange

            #region Act
            var result = Controller.UpdateOrder("9", idsToReorder)
                         .AssertResultIs <JsonNetResult>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("false", result.JsonResultString);
            CustomFieldRepository.AssertWasCalled(a => a.GetNullableById(Arg <int> .Is.Anything), x => x.Repeat.Times(2));
            #endregion Assert
        }