CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
csla.netcore.test/Serialization/SerializationTests.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="SerializationTests.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Text;
11using Csla.TestHelpers;
14using System.IO;
15
16#if !NUNIT
17using Microsoft.VisualStudio.TestTools.UnitTesting;
18#else
19using NUnit.Framework;
20using TestClass = NUnit.Framework.TestFixtureAttribute;
21using TestInitialize = NUnit.Framework.SetUpAttribute;
22using TestCleanup = NUnit.Framework.TearDownAttribute;
23using TestMethod = NUnit.Framework.TestAttribute;
24#endif
25using Csla;
26
28{
29 [TestClass]
30 public class SerializationTests
31 {
32 private static TestDIContext _testDIContext;
33
35 public static void ClassInitialize(TestContext context)
36 {
37 _testDIContext = TestDIContextFactory.CreateDefaultContext();
38 }
39
40 [TestMethod]
42 {
44 Assert.AreEqual(typeof(Csla.Serialization.Mobile.MobileFormatter), serializer);
45 }
46
47 [TestMethod]
48 public void UseMobileFormatter()
49 {
50 ApplicationContext applicationContext;
51 applicationContext = _testDIContext.CreateTestApplicationContext();
52
54 Assert.AreEqual(typeof(Csla.Serialization.Mobile.MobileFormatter), serializer);
55 var s = Csla.Serialization.SerializationFormatterFactory.GetFormatter(applicationContext);
56 Assert.IsInstanceOfType(s, typeof(Csla.Serialization.Mobile.MobileFormatter));
57 }
58
59 [TestMethod]
60 public void UseCustomFormatter()
61 {
62 try
63 {
64 IServiceCollection services = new ServiceCollection();
65 services.AddCsla(o => o
66 .Serialization(o => o.SerializationFormatter(typeof(CustomFormatter))));
67 var provider = services.BuildServiceProvider();
68 var applicationContext = provider.GetRequiredService<ApplicationContext>();
69
70 var serializerType = ApplicationContext.SerializationFormatter;
71 Assert.AreEqual(typeof(CustomFormatter), serializerType);
72 var s = Csla.Serialization.SerializationFormatterFactory.GetFormatter(applicationContext);
73 Assert.IsInstanceOfType(s, typeof(CustomFormatter));
74 }
75 finally
76 {
77 // reset the serializer back to default
78 IServiceCollection services = new ServiceCollection();
79 services.AddCsla(o => o
80 .Serialization(o => o.SerializationFormatter(typeof(Csla.Serialization.Mobile.MobileFormatter))));
81 var provider = services.BuildServiceProvider();
82 var applicationContext = provider.GetRequiredService<ApplicationContext>();
83 }
84 }
85 }
86
87 public class CustomFormatter : Csla.Serialization.ISerializationFormatter
88 {
89 public object Deserialize(Stream serializationStream) => throw new NotImplementedException();
90 public object Deserialize(byte[] serializationStream) => throw new NotImplementedException();
91 public void Serialize(Stream serializationStream, object graph) => throw new NotImplementedException();
92 public byte[] Serialize(object graph) => throw new NotImplementedException();
93 }
94}
Provides consistent context information between the client and server DataPortal objects.
static Type SerializationFormatter
Gets the serialization formatter type used by CSLA .NET for all explicit object serialization (such a...
Serializes and deserializes objects at the field level.
object Deserialize(byte[] serializationStream)
Converts a serialization stream into an object graph.
byte[] Serialize(object graph)
Converts an object graph into a byte stream.
object Deserialize(Stream serializationStream)
void Serialize(Stream serializationStream, object graph)
Type to carry context information for DI in unit tests