Private Accessor and generic types
- Hi:
I am trying to test a class that has a nested private class within it, and calling a method that returns a List<PrivateEmbeddedClass>. The generated test classes seem to support this, but fail at runtime as the generic type for the list is different in the test than in production code. Allow me to explain.
This is what my class to test looks like:
7 internal class StateObsequioVariosCandidatos : StateObsequioBase
8 {
9 #region Class CantidadRegaloLineaItem
10
11 private class CantidadRegaloLineaItem
12 {
13 public double Cantidad { get; set; }
14 public bool IsCajas { get; set; }
15 public int LineaOid { get; set; }
16 }
17 #endregion
18
19 private List<CantidadRegaloLineaItem> getSortedListaCantidad(int albaranOid, int codigoBarrasRegaloOid)
20 {
21 DevExpress.Xpo.XPQuery<GestionNet.Datos.AlbaranDetalle> xpQueryLineas =
22 new DevExpress.Xpo.XPQuery<GestionNet.Datos.AlbaranDetalle>(UnitOfWork);
23 var queryLineas = from linea in xpQueryLineas
24 where linea.Albaran.Oid == albaranOid &&
25 linea.CodigoBarras.Oid == codigoBarrasRegaloOid &&
26 !linea.IsLineaRegalo
27 orderby linea.Cantidad descending
28 select new CantidadRegaloLineaItem()
29 {
30 Cantidad = linea.Cantidad,
31 IsCajas = linea.IsCajas,
32 LineaOid = linea.Oid
33 };
34 return queryLineas.ToList();
35 }
You can see the embedded class CantidadRegaloLineaItem within the class StateObsequioVariosCandidatos, and the method I'm trying to test private List<CantidadRegaloLineaItem> getSortedListaCantidad(...).
Okay, now for the test class.
252 IStateObsequio stateObsequio = new StateObsequioVariosCandidatos(...)
253 PrivateObject param0 = new PrivateObject(stateObsequio);
254 StateObsequioVariosCandidatos_Accessor target = new StateObsequioVariosCandidatos_Accessor(param0);
255 List<StateObsequioVariosCandidatos_Accessor.CantidadRegaloLineaItem> actual =
256 target.getSortedListaCantidad(albaranOid, codigoBarrasRegaloOid);
You can see the lines 255 and 256 declare a generic list of a simulated type (logical as this is a private type), but fails when the line is executed complaining that it can't convert a list from type StateObsequioVariosCandidatos.CantidadRegaloLineaItem to type StateObsequioVariosCandidatos_Accessor.CantidadRegaloLineaItem.
My question is, is there a way around this problem?
Thanks,
Martin.
Been programming since 1982, still going


