VS 2015を使用する。Catel:1ユニットテストでDeserializeが動作し、別のユニットが失敗する
私のアプリケーションをCatel 4.4.0から4.5.4にアップグレードします。もちろん、SavableModelBase.Loadパラメータを使用してモデルに多数の変更がありましたが、修正されたものがあり、エラーや警告なしでコンパイルされます。
私はユニットテストを実行しましたが、失敗したテストは1つあります。このテストでは、以前にシリアライズされた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の年定数は2番目のコードでは正しく読み込まれていますが、最初のコードでは正しく読み込まれていません。
私は試してみることを使い果たしました。誰かが私が使うことができるこのアプローチまたは別のアプローチの原因に関する提案をしていますか?
おかげで、 ランディ
私はチケットを作成しました。私は問題を再現する小さなプロジェクトを作成することができますが、それは難しいかもしれませんが、アプリケーションには非常に多くのコードがあります。 – RandyB