Пример #1
0
        internal static void ProcessingInRamWithObject()
        {
            var obj = new ModelOne()
            {
                Key   = 3,
                Value = "MyValue",
                Label = "MyLabel",
            };

            JsonSerializer serializer = new JsonSerializer();

            //serializer.Converters.Add(new JavaScriptDateTimeConverter());
            //serializer.NullValueHandling = NullValueHandling.Ignore;

            //using (StreamWriter sw = new StreamWriter(@"c:\json.txt"))
            //using (JsonWriter writer = new JsonTextWriter(sw))
            //{
            //    serializer.Serialize(writer, product);
            //    // {"ExpiryDate":new Date(1230375600000),"Price":0}
            //}


            string ser = JsonConvert.SerializeObject(obj);

            Console.WriteLine(ser);

            var dObj = JsonConvert.DeserializeObject <ModelOne>(ser);
        }
Пример #2
0
        public static void StaticProcessingToFile()
        {
            var obj = new ModelOne()
            {
                Key   = 2,
                Value = "MyValue",
                Label = "MyLabel",
            };

            using (var writer = new StreamWriter(@"StaticProcessingToFile.txt"))
            {
                writer.Write(JsonConvert.SerializeObject(obj));
            }
            // File.WriteAllText("StaticProcessingToFile.txt", JsonConvert.SerializeObject(obj));

            var dObj = new ModelOne();

            using (var reader = new StreamReader("StaticProcessingToFile.txt"))
            {
                string str = reader.ReadToEnd();
                dObj = JsonConvert.DeserializeObject <ModelOne>(str);
            }
            // var obj = JsonConvert.DeserializeObject(File.ReadAllText("StaticProcessingToFile.txt"));

            Console.WriteLine(dObj);
        }
Пример #3
0
        public void When_only_having_member_Rev_It_extracts_the_Rev()
        {
            var model = new ModelOne {
                Rev = "ModelOne:Rev:1"
            };

            SUT.GetValueFrom(model).Should().Be(model.Rev);
        }
Пример #4
0
        public void When_only_having_member_Id_It_extracts_the_id()
        {
            var model = new ModelOne {
                Id = "ModelOne:Id:1"
            };

            SUT.GetValueFrom(model).Should().Be(model.Id);
        }
Пример #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var model_one = new ModelOne("/home/angel/code/WebPython/WebPython/pyfiles/gmm0.9.hdf5");
            var result    = model_one.Predict(1, 2, 3, 4, 5, 6, 7, 8);

            Console.WriteLine($"result : {result}");
        }
Пример #6
0
        public void When_serializing_entity_with_Id_It_will_translate_it_to__id()
        {
            var model = new ModelOne {
                Id = "abc", Value = "def"
            };

            var json = SUT.Serialize(model);

            json.Should().Contain("\"_id\":\"abc\"");
        }
Пример #7
0
        public void When_serializing_entity_with_strings_needing_escaping_it_will_escape_them()
        {
            var model = new ModelOne {
                Id = @"some\id", Value = @"This ""Needs"" \escaping\\"
            };

            var json = SUT.Serialize(model);

            json.Should().Contain("\"_id\":\"some\\\\id\"");
            json.Should().Contain("\"value\":\"This \\\"Needs\\\" \\\\escaping\\\\\\\\\"");
        }
Пример #8
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Starting tryout");
            var container = RegisterComponents();

            using (var lifetimeScope = container.BeginLifetimeScope())
            {
                var modelWizard = lifetimeScope.Resolve <IModelWizard>();

                var model = new ModelOne();
                modelWizard.CastFireBall(model);
            }

            System.Console.ReadLine();
        }
Пример #9
0
        [TestMethod] public void floTest()
        {
            var data = new ModelOne
            {
                Id            = 1232385789,
                HomeAttribute = "myhome",
                Model2Id      = 55555555,
                Model2        = new Model2
                {
                    Id   = 55555555,
                    Name = "myName"
                },
                MoreModel2Id = new List <long?> {
                    1, 2, 3
                },
                MoreModel2 = new List <Model2>
                {
                    new Model2
                    {
                        Id   = 1,
                        Name = "arr"
                    },
                    new Model2
                    {
                        Id   = 2,
                        Name = "arrr"
                    },
                    new Model2
                    {
                        Id   = 3,
                        Name = "arrr"
                    },
                }
            };

            var doc = JsonApiDocumentExtensions.CreateDocumentFromApiResource <ModelOneResource>(data);

            doc.IncludeRelation <ModelOneResource>(data, $"{nameof(ModelOne.MoreModel2)},{nameof(ModelOne.Model2)}");

            var jsonString   = JsonConvert.SerializeObject(doc, Formatting.Indented);
            var deserialized = JsonConvert.DeserializeObject <JsonApiDocument>(jsonString);
            Func <string, bool> foundAttributes;
            var resultData = deserialized.ToObject <ModelOne, ModelOneResource>(out foundAttributes);

            resultData.Model2     = deserialized.Included.GetResource(resultData.Model2Id, typeof(Model2))?.ToObject <Model2, Model2Resource>();
            resultData.MoreModel2 = resultData.MoreModel2Id?.Select(x => deserialized.Included.GetResource(x, typeof(Model2))?.ToObject <Model2, Model2Resource>());
            Assert.IsTrue(foundAttributes(nameof(data.HomeAttribute)));
        }
Пример #10
0
        public static void StaticProcessingInRam()
        {
            var obj = new ModelOne()
            {
                Key   = 1,
                Value = "MyValue",
                Label = "MyLabel",
            };

            string ser = JsonConvert.SerializeObject(obj);

            Console.WriteLine(ser);

            var dObj = JsonConvert.DeserializeObject <ModelOne>(ser);

            Console.WriteLine(dObj);
        }
Пример #11
0
        public void ConvertSameModelBothWays_Simple()
        {
            var obj = new ModelOne()
            {
                Type  = ModelType.Simple,
                Key   = 1,
                Label = "Label 1",
                Value = "TestValue",
            };

            var ser = JsonSerializer.Serialize(obj);

            Assert.AreEqual("{\"Type\":0,\"Key\":1,\"Value\":\"TestValue\",\"Label\":\"Label 1\"}", ser);

            var bObj = JsonSerializer.Deserialize <ModelOne>(ser);

            Assert.IsTrue(obj == bObj);
        }
Пример #12
0
        public void ConvertModelWithPlainEnum()
        {
            var obj = new ModelOne()
            {
                Type  = ModelType.Simple,
                Key   = 1,
                Label = "Label 1",
                Value = "TestValue",
            };

            var options = new JsonSerializerOptions();

            options.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
            options.Converters.Add(new JsonStringEnumConverter());
            //options.WriteIndented = true;
            var ser = JsonSerializer.Serialize(obj, options);


            Assert.AreEqual("{\"Type\":\"simple\",\"Key\":1,\"Value\":\"TestValue\",\"Label\":\"Label 1\"}", ser);
        }
        public void TestContainerTwoObj()
        {
            ModelOne modelOne = new ModelOne()
            {
                Name = nameof(ModelOne)
            };
            ModelsSecond modelTwo = new ModelsSecond()
            {
                Name = nameof(ModelsSecond)
            };

            _container.Regicter <IModel, ModelOne>(modelOne);
            Assert.AreEqual(typeof(ModelOne), _container.Resolve <IModel>().GetType());
            var modelResolveOne = _container.Resolve <IModel>();

            Assert.IsTrue(object.ReferenceEquals(modelOne, modelResolveOne));
            _container.ChangeRecordContainer <IModel, ModelsSecond>(modelTwo);
            var modelResolveTwo = _container.Resolve <IModel>();

            Assert.AreEqual(typeof(ModelsSecond), _container.Resolve <IModel>().GetType());
            Assert.IsTrue(object.ReferenceEquals(modelTwo, modelResolveTwo));
        }