public void When_using_embedded_serializer_resource_it_must_roundtrip() { // Arrange var initialObject = new SerializerTestObject { Name = "Some" }; var service = new MsgPackSerializationService(); // Act using (var stream = new MemoryStream()) { service.WriteObject(initialObject, stream); stream.Seek(0, SeekOrigin.Begin); var finalObject = service.ReadObject<SerializerTestObject>(stream); // Assert finalObject.Should().NotBeNull(); finalObject.Name.Should().Be(initialObject.Name); } }
public void When_using_embedded_serializer_resource_it_must_roundtrip() { // Arrange var initialObject = new SerializerTestObject { Name = "Some" }; var service = new MsgPackSerializationService(); // Act using (var stream = new MemoryStream()) { service.WriteObject(initialObject, stream); stream.Seek(0, SeekOrigin.Begin); var finalObject = service.ReadObject <SerializerTestObject>(stream); // Assert finalObject.Should().NotBeNull(); finalObject.Name.Should().Be(initialObject.Name); } }
private static void TrySaveToDisk([NotNull] ExternalAnnotationsCache cache) { try { EnsureDirectoryExists(); using (FileStream stream = File.Create(CachePath)) { using (new CodeTimer("ExternalAnnotationsCache:Write")) { var service = new MsgPackSerializationService(); service.WriteObject(cache, stream); } } } catch (IOException) { // When MSBuild runs in parallel, another process may be writing the cache file at the same time. } }
private static ExternalAnnotationsCache TryGetCacheFromDisk() { try { if (File.Exists(CachePath)) { using (FileStream stream = File.OpenRead(CachePath)) { using (new CodeTimer("ExternalAnnotationsCache:Read")) { var service = new MsgPackSerializationService(); var result = service.ReadObject<ExternalAnnotationsCache>(stream); if (result.ExternalAnnotations.Any()) { return result; } } } } } catch (UnauthorizedAccessException) { } catch (IOException) { } return null; }