private static void Main(string[] args) { //var gameClientConfiguration = new GameClientConfiguration() //{ // User = new Domain.Common.Model.Network.UserData() { Username = "******", Password = "******" }, // Screen = new Domain.Common.Model.Network.ScreenData() { ScreenWidth = 1024, ScreenHeight = 768 }, // ServerIp = "192.168.188.42", // ServerPort = 8080, // ServerPeerName = "asteroid", // Background = new SpaceBackgroundElementsConfiguration() // { // AsteroidsCount = 300, // DebrisFieldCount = 1500, // StarsFieldCount = 2000 // } //}; var yamler = new YamlSerializerAdapter(); var jsonler = new JsonSerializerAdapter(); var msgler = new MsgPackSerializerAdapter(); //System.IO.File.WriteAllText("startup.yaml",yamler.Serialize(gameClientConfiguration)); var gameConfig = System.IO.File.ReadAllText(args[0]); var gameClientConfiguration = yamler.DeserializeObject <GameClientConfiguration>(gameConfig); //return; Console.WriteLine(gameConfig); using (var game = new Game1(gameClientConfiguration)) game.Run(); }
private IBsonSerializer <Newtonsoft.Json.Linq.JToken> CreateSubject() { //var subject = new JValueSerializer(); var subject = new JsonSerializerAdapter <Newtonsoft.Json.Linq.JToken>(); return(subject); }
public async Task FileJournalSmokeTest() { var config = new MemstateSettings(); var fileName = Path.GetTempFileName(); var journalWriter = new FileJournalWriter(config, fileName, 0); var subSource = new FileJournalSubscriptionSource(journalWriter); var records = new List <JournalRecord>(); var sub = subSource.Subscribe(0, records.Add); for (int i = 0; i < 1000; i++) { var command = new AddStringCommand(i.ToString()); journalWriter.Send(command); } await journalWriter.DisposeAsync().ConfigureAwait(false); sub.Dispose(); subSource.Dispose(); Assert.Equal(1000, records.Count); var serializer = new JsonSerializerAdapter(); var reader = new FileJournalReader(fileName, serializer); records.Clear(); foreach (var record in reader.GetRecords()) { records.Add(record); } Assert.True(records.Select(r => (int)r.RecordNumber).SequenceEqual(Enumerable.Range(0, 1000))); await reader.DisposeAsync().ConfigureAwait(false); File.Delete(fileName); }
public void constructor_with_wrappedSerializer_should_initialize_instance() { var wrappedSerializer = Substitute.For <Newtonsoft.Json.JsonSerializer>(); var result = new JsonSerializerAdapter <object>(wrappedSerializer); result.ValueType.Should().Be(typeof(object)); }
static void Main(string[] args) { //================================================================ // Test polymorphic objects var animalManager = new AnimalManager(); animalManager.Animals = new IAnimal[] { new Dog { Name = "Pochi", DogProperty = "Wan wan" }, new Cat { Name = "Tama", CatProperty = "Nya nya" } }; // Serializer. var serializer = new JsonSerializerAdapter(typeof(AnimalManager)); serializer.JsonSerializer.Formatting = Formatting.Indented; // Output file path. var path = Path.Combine(Directory.GetCurrentDirectory(), "AnimalManager.json"); // Serialize. using (var stream = File.Create(path)) { serializer.Serialize(stream, animalManager); } Console.WriteLine("Serialize:"); Console.WriteLine(path); using (var stream = File.Open(path, FileMode.Open)) using (var reader = new StreamReader(stream)) { string line; while ((line = reader.ReadLine()) != null) { Console.WriteLine(line); } } Console.WriteLine(); // Deserialize. AnimalManager loadedObject; using (var stream = File.Open(path, FileMode.Open)) { loadedObject = serializer.Deserialize(stream, null) as AnimalManager; } Console.WriteLine("Deserialize:"); Console.WriteLine(loadedObject); Console.WriteLine(); // Exit. Console.WriteLine("Press Enter to exit."); Console.ReadLine(); }
public void Deserialize_should_return_expected_result(string json, string expectedResult) { var subject = new JsonSerializerAdapter <C>(); var result = Deserialize <C>(subject, ToBson(json)); result.Id.Should().Be(ObjectId.Parse(expectedResult)); }
public void Deserialize_should_return_expected_result(string json, int?nullableInt32) { var subject = new JsonSerializerAdapter <C>(); var expectedResult = nullableInt32 == null ? null : (BsonInt32)nullableInt32.Value; var result = Deserialize <C>(subject, ToBson(json)); result.V.Should().Be(expectedResult); }
public void TryGetItemSerializationInfo_should_throw_when_contract_is_not_an_array_contract() { var subject = new JsonSerializerAdapter <C>(); BsonSerializationInfo info; Action action = () => subject.TryGetItemSerializationInfo(out info); action.ShouldThrow <BsonSerializationException>().And.Message.Contains("is not a JsonArrayContract"); }
public void TryGetMemberSerializationInfo_should_return_false_when_class_has_converter() { var subject = new JsonSerializerAdapter <E>(); BsonSerializationInfo info; Action action = () => subject.TryGetMemberSerializationInfo("F", out info); action.ShouldThrow <BsonSerializationException>(); }
public void TryGetItemSerializationInfo_should_return_false_when_contract_is_not_an_array_contract() { var subject = new JsonSerializerAdapter <C>(); BsonSerializationInfo info; var result = subject.TryGetItemSerializationInfo(out info); result.Should().BeFalse(); }
public void Deserialize_should_return_expected_result(string json, bool?nullableMaxKey) { var subject = new JsonSerializerAdapter <C>(); var expectedResult = nullableMaxKey == null ? null : BsonMaxKey.Value; var result = Deserialize <C>(subject, ToBson(json)); result.V.Should().Be(expectedResult); }
public void TryGetMemberSerializationInfo_should_return_false_for_non_existent_member() { var subject = new JsonSerializerAdapter <C>(); BsonSerializationInfo info; var result = subject.TryGetMemberSerializationInfo("X", out info); result.Should().BeFalse(); info.Should().BeNull(); }
public void Serialize_should_have_expected_result(int?nullableInt32, string expectedResult) { var subject = new JsonSerializerAdapter <C>(); var value = new C { V = nullableInt32 == null ? null : (BsonInt32)nullableInt32.Value }; var result = Serialize(subject, value); result.Should().Equal(ToBson(expectedResult)); }
public void Serialize_should_have_expected_result(string hexValue, string expectedResult) { var subject = new JsonSerializerAdapter <C>(); var value = new C { Id = ObjectId.Parse(hexValue) }; var result = Serialize(subject, value); result.Should().Equal(ToBson(expectedResult)); }
public void Serialize_should_have_expected_result(int x, string expectedResult) { var subject = new JsonSerializerAdapter <C>(); var value = new C { X = x }; var result = Serialize(subject, value); result.Should().Equal(ToBson(expectedResult)); }
public void Serialize_should_have_expected_result(bool?nullableMaxKey, string expectedResult) { var subject = new JsonSerializerAdapter <C>(); var value = new C { V = nullableMaxKey == null ? null : BsonMaxKey.Value }; var result = Serialize(subject, value); result.Should().Equal(ToBson(expectedResult)); }
public void Int32_can_be_cloned() { int i = 42; var serializer = new JsonSerializerAdapter(); var stream = new MemoryStream(); serializer.WriteObject(stream, i); stream.Position = 0; object o = serializer.ReadObject(stream); Assert.IsType <int>(o); }
public void Double_can_be_cloned() { double i = 42.10; var serializer = new JsonSerializerAdapter(); var stream = new MemoryStream(); serializer.WriteObject(stream, i); stream.Position = 0; object o = serializer.ReadObject(stream); Assert.IsType <double>(o); }
public void TryGetItemSerializationInfo_should_return_expected_result() { var subject = new JsonSerializerAdapter <int[]>(); BsonSerializationInfo info; var result = subject.TryGetItemSerializationInfo(out info); result.Should().BeTrue(); info.ElementName.Should().BeNull(); info.NominalType.Should().Be(typeof(int)); info.Serializer.Should().BeOfType <JsonSerializerAdapter <int> >(); info.Serializer.ValueType.Should().Be(typeof(int)); }
public void TryGetMemberSerializationInfo_should_return_expected_result_for_int_member() { var subject = new JsonSerializerAdapter <C>(); BsonSerializationInfo info; var result = subject.TryGetMemberSerializationInfo("N", out info); result.Should().BeTrue(); info.ElementName.Should().Be("n"); info.NominalType.Should().Be(typeof(int)); info.Serializer.Should().BeOfType <JsonSerializerAdapter <int> >(); info.Serializer.ValueType.Should().Be(typeof(int)); }
static void Main(string[] args) { //================================================================ // Test polymorphic objects var animalManager = new AnimalManager(); animalManager.Animals = new IAnimal[] { new Dog { Name = "Pochi", DogProperty = "Wan wan" }, new Cat { Name = "Tama", CatProperty = "Nya nya" } }; // Serializer. var serializer = new JsonSerializerAdapter(typeof(AnimalManager)); serializer.JsonSerializer.Formatting = Formatting.Indented; // Output file path. var path = Path.Combine(Directory.GetCurrentDirectory(), "AnimalManager.json"); // Serialize. using (var stream = File.Create(path)) { serializer.Serialize(stream, animalManager); } Console.WriteLine("Serialize:"); Console.WriteLine(path); using (var stream = File.Open(path, FileMode.Open)) using (var reader = new StreamReader(stream)) { string line; while ((line = reader.ReadLine()) != null) Console.WriteLine(line); } Console.WriteLine(); // Deserialize. AnimalManager loadedObject; using (var stream = File.Open(path, FileMode.Open)) { loadedObject = serializer.Deserialize(stream, null) as AnimalManager; } Console.WriteLine("Deserialize:"); Console.WriteLine(loadedObject); Console.WriteLine(); // Exit. Console.WriteLine("Press Enter to exit."); Console.ReadLine(); }
private static void Main(string[] args) { var yamler = new YamlSerializerAdapter(); var jsonler = new JsonSerializerAdapter(); var msgler = new MsgPackSerializerAdapter(); var config = yamler.DeserializeObject <GameServerConfiguration>(File.ReadAllText(args[0])); var world = new WorldGame(config); while (true) { world.Update(null); } }
public void TryGetItemSerializationInfo_should_throw_when_contract_has_a_converter() { var wrappedSerializer = new Newtonsoft.Json.JsonSerializer(); var arrayContract = new Newtonsoft.Json.Serialization.JsonArrayContract(typeof(int[])) { Converter = Substitute.For <Newtonsoft.Json.JsonConverter>() }; wrappedSerializer.ContractResolver = new DictionaryContractResolver( new Dictionary <Type, Newtonsoft.Json.Serialization.JsonContract> { { typeof(int[]), arrayContract } }); var subject = new JsonSerializerAdapter <int[]>(wrappedSerializer); BsonSerializationInfo info; Action action = () => subject.TryGetItemSerializationInfo(out info); action.ShouldThrow <BsonSerializationException>().And.Message.Should().Contain("has a Converter"); }
public void TryGetMemberSerializationInfo_should_return_expected_result_for_nested_document_member() { var subject = new JsonSerializerAdapter <C>(); BsonSerializationInfo info1; var result1 = subject.TryGetMemberSerializationInfo("D", out info1); result1.Should().BeTrue(); info1.ElementName.Should().Be("d"); info1.NominalType.Should().Be(typeof(D)); info1.Serializer.Should().BeOfType <JsonSerializerAdapter <D> >(); info1.Serializer.ValueType.Should().Be(typeof(D)); BsonSerializationInfo info2; var result2 = ((IBsonDocumentSerializer)info1.Serializer).TryGetMemberSerializationInfo("B", out info2); result2.Should().BeTrue(); info2.ElementName.Should().Be("b"); info2.NominalType.Should().Be(typeof(bool)); info2.Serializer.Should().BeOfType <JsonSerializerAdapter <bool> >(); info2.Serializer.ValueType.Should().Be(typeof(bool)); }
public void constructor_should_initialize_instance() { var result = new JsonSerializerAdapter <object>(); result.ValueType.Should().Be(typeof(object)); }
public void constructor_with_wrappedSerializer_should_throw_when_wrappedSerializer_is_null() { Action action = () => { var result = new JsonSerializerAdapter <object>(null); }; action.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("wrappedSerializer"); }