2017-03-04 7 views
0

VS 2015 사용.Catel : Deserialize가 1 단위 테스트에서 작동하지 않습니다.

Catel 4.4.0에서 4.5.4로 내 업 그레 이드 중입니다. 물론 SavableModelBase.Load 매개 변수를 사용하여 모델에 많은 변경 사항이 있었지만 수정 된 사항이 있으며 모든 내용이 오류 또는 경고없이 컴파일됩니다.

단위 테스트를 실행했지만 실패한 테스트가 1 개 있습니다. 이 테스트를 수행하려면 대리인이 이전에 serialize 된 XML 데이터 파일을로드해야합니다. 그런 다음 대리자는 연도 별 컬렉션에서 YearConstants 인스턴스를 검색합니다.

이 대리자를 사용하여 단위 테스트가 실행
public static YearConstants GetYearConstantsByYearAndFileName(int year, string fileName) 
    { 
     using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) 
     { 
      var constants = ConstantsData.Load(fs, SerializationMode.Xml, null); 
      var results = constants.YearConstantsList.Where(x => x.Year == year).FirstOrDefault(); 
      if (results == null) 
      { 
       throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, "YearConstants not found for [{0}] in file [{1}]", year, fileName)); 
      } 

      return results; 
     } 
    } 

에서, "상수"var에 값을 가지고 있지만, 어떤 년 데이터를 포함하지 않습니다 대리자입니다. 난 그냥 같은 파일을로드 테스트 단위 테스트를 추가 한

System.InvalidCastException occurred 
    HResult=-2147467262 
    Message=Unable to cast object of type 'Catel.Runtime.Serialization.Xml.XmlSerializationContextInfo' to type 'Catel.Runtime.Serialization.Binary.BinarySerializationContextInfo'. 
    Source=Catel.Core 
    StackTrace: 
     at Catel.Runtime.Serialization.SerializerBase`1.Deserialize(Object model, ISerializationContextInfo serializationContext, ISerializationConfiguration configuration) in C:\CI_WS\Ws\97969\Source\Catel\src\Catel.Core\Catel.Core.Shared\Runtime\Serialization\SerializerBase.deserialization.cs:line 154 
    InnerException: 

그것은 예외없이 통과 : 나는 모든 CLR 예외에 휴식 때, 나는 다음과 같은 예외를 받고 있어요

[TestMethod] 
    [DeploymentItem(@"TestData\GeorgiaConstants.xml")] 
    public void ConstantsData_SerializationWithLiveDataTest() 
    { 
     using (var fs = new FileStream("GeorgiaConstants.xml", FileMode.Open, FileAccess.Read)) 
     { 
      var constants = ConstantsData.Load(fs, SerializationMode.Xml, null); 
      Assert.IsNotNull(constants, "The constants data was not correctly loaded from 'GeorgiaConstants.xml' file."); 
      Assert.AreEqual(5, constants.YearConstantsList.Count, "The expected number of year constants was not loaded from the 'GeorgiaConstants.xml' file."); 

      // We should have year constants for 2016 for a while in the file. 
      var yearConstants = constants.YearConstantsList.Where(x => x.Year == 2016).FirstOrDefault(); 
      Assert.IsNotNull(yearConstants, "The year constants for year = 2016 were not found in 'GeorgiaConstants.xml' file."); 

      // We shouldn't be able to find year constants for a year this old. 
      yearConstants = constants.YearConstantsList.Where(x => x.Year == 1999).FirstOrDefault(); 
      Assert.IsNull(yearConstants, "The year constants for year = 1999 were UNEXPECTEDLY found in 'GeorgiaConstants.xml' file."); 
     } 
    } 

두 파일 스트림 모두 읽은 바이트 수가 같습니다. 또한 상수 XML 파일에는 올바르게 읽혀지는 "만든 날짜", "수정 된 날짜"및 "만든 날짜"문자열이 포함되어 있습니다. 자체적으로 실패한 유닛 테스트를 실행하면 파일 공유/잠금 문제가되지 않도록 여전히 실패합니다. ObservableCollection of year 상수가 2 번째 코드에서는 올바르게 읽히지 만 첫 번째 코드에서는 올바르게 읽히지 않습니다.

시도 할 물건이 부족합니다. 누구든지이 또는 내가 사용할 수있는 또 다른 접근 방법에 대한 원인에 대한 제안을 가지고 있습니까?

덕분에, 랜디

답변

1

는 XML 및 바이너리 직렬화 방법을 혼합 것처럼 보인다. 이 문제를 해결할 수 있도록 official issue tracker에 티켓을 만드십시오.

+0

항공권을 만들었습니다. 내가 첨부 할 문제를 복제하는 작은 프로젝트를 만들 수 있는지 알 수 있지만 앱에 너무 많은 코드가있어 어려울 수 있습니다. – RandyB