public CastOrDefaultSpecK() { Specify(x => ObjectArray.CastOrDefault <CustomType> ().ToList()) .Case("for normal array", _ => _ .Given("CustomType array", x => ObjectArray = new object[] { new CustomType(1), new CustomType(2), new CustomType(3) }) .It("casts each element", x => x.Result.Should().BeEquivalentTo(new CustomType(1), new CustomType(2), new CustomType(3)))) .Case("for sparse array", _ => _ .Given("CustomType sparse array", x => ObjectArray = new object[] { new CustomType(1), null, new CustomType(3) }) .It("casts each element and sparse elements to default", x => x.Result.Should().BeEquivalentTo(new CustomType(1), null, new CustomType(3)))); Specify(x => ObjectArray.CastOrDefault <int> ().ToList()) .Case("for sparse int array", _ => _ .Given("int sparse array", x => ObjectArray = new object[] { 1, null, 3 }) .It("casts each element and sparse elements to default", x => x.Result.Should().BeEquivalentTo(1, 0, 3))); }