为什么会失败?

时间:2019-10-14 10:40:00

标签: c# visual-studio

“消息:声明为True。失败。应为:System.Collections.Generic.List 1[...] but found System.Collections.Generic.List 1 [...]”

我不知道为什么会失败。谁能帮我解决这个错误

        /// <summary>
        /// Test to Get the all the fee bands from Crm
        /// </summary>
        /// <returns>Response with a collection of ise_feeband entities</returns>
        [TestCategory("AnnualBillingService")]
        [TestMethod]
        public void GetFeeBandingListTest()
        {
            List<ISE_feeband> fee_bands = new List<ISE_feeband>() { };
            //fee_bands.Add(new ISE_feeband());           
            string entityname = "entity name";
            Guid ID = new Guid();

            using (ShimsContext.Create())
            {
                //Arrange
                ShimCrmService.AllInstances.FetchString = ((@this, fetchXml) =>
                {
                    return new Microsoft.Xrm.Sdk.EntityCollection()
                    {
                        EntityName = entityname,
                        MoreRecords = true,
                        MinActiveRowVersion = "version",
                        PagingCookie = "paging cookie",
                        TotalRecordCount = 10,
                        TotalRecordCountLimitExceeded = false,
                    };
                });

                //Act              
                var AnnualBillingService = new AnnualBillingService();
                var response = AnnualBillingService.GetFeeBandingList();

                //Assert
                Assert.IsNotNull(response, "Expected not-null response");
                Assert.IsTrue(response.FeeBands == fee_bands, "Expected: " + fee_bands + " but found " + response.FeeBands);
                foreach (var FeeBands in fee_bands)
                {
                    Assert.IsTrue(FeeBands.Id == ID, "Expects True");
                }
            }
        }

这是代码。我无法理解该错误,奇怪的是,预期结果与实际结果相同,并且仍然出现错误。

2 个答案:

答案 0 :(得分:0)

也许您正在寻找的是Collection的assert方法,用于比较类型的集合。 AreEqualAreEquivalent之间是有区别的,我不太确定您的案子在这里,所以请看一看两者!

点击此链接,您将找到方法和它们的文档,它将为您提供足够的帮助。 Clicky clicky

答案 1 :(得分:0)

        /// <summary>
        /// Test to Get the all the fee bands from Crm
        /// </summary>
        /// <returns>Response with a collection of ise_feeband entities</returns>
        [TestCategory("AnnualBillingService")]
        [TestMethod]
        public void GetFeeBandingListTest()
        {
            Guid ID = new Guid();
            List<ISE_feeband> fee_bands = new List<ISE_feeband>();

            using (ShimsContext.Create())
            {
                //Arrange
                ShimCrmService.AllInstances.FetchString = ((@this, fetchXml) =>
                {
                    var output = new Microsoft.Xrm.Sdk.EntityCollection()
                    {
                        EntityName = ISE_feeband.EntityLogicalName,
                    };
                    output.Entities.Add(new ISE_feeband()
                    {
                        Id = ID,                        
                    });
                    return output;
                });

                //Act              
                var AnnualBillingService = new AnnualBillingService();
                var response = AnnualBillingService.GetFeeBandingList();

                //Assert
                Assert.IsNotNull(response, "Expected not-null response");
                Assert.IsTrue(response.FeeBands.Count == 1, "Expected: " + fee_bands + " but found " + response.FeeBands);
                foreach (var FeeBands in fee_bands)
                {
                    Assert.IsTrue(FeeBands.ISE_feebandId == ID , "Expects True");
                }
            }
        }

问题解决了,谢谢大家:)