nbuilder

Class and extension method container class in same namespace. What is the benefit?

吃可爱长大的小学妹 提交于 2020-01-04 04:58:10
问题 I was trying NBuilder in my unit test. An excellent library. However, I could not explain the following structure of classes and interfaces. In FizzWare.NBuilder namespace: ISingleObjectBuilder SingleObjectBuilderExtensions In FizzWare.NBuilder.Implementation IObjectBuilder` ObjectBuilder SingleObjectBuilderExtensions is simply a wrapper on IObjectBuilder . The client code should usually use a class named Builder which has a static method that gives you ISingleObjectBuilder . You never need

How to mock a private readonly IList<T> property using moq

那年仲夏 提交于 2019-12-13 15:35:06
问题 I'm trying to mock this list: private readonly IList<MyClass> myList = new List<MyClass>(); using this (as seen here): IList<MyClass> mockList = Builder<MyClass>.CreateListOfSize(5).Build(); mockObj.SetupGet<IEnumerable<MyClass>>(o => o.myList).Returns(stakeHoldersList); However at runtime I get an InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[MyClass]' to type 'System.Collections.ObjectModel.ReadOnlyCollection`1[MyClass]'. What am I doing wrong? 回答1: