public void TestReadJsonWithLock()
        {
            SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/basic.json").ToURI());

            // Deserializes into a metadata JSON object.
            TestJson testJson = JsonTemplateMapper.ReadJsonFromFileWithLock <TestJson>(jsonFile);

            Assert.AreEqual(testJson.Number, 54);
            Assert.AreEqual(testJson.Text, "crepecake");
            Assert.AreEqual(
                testJson.Digest,
                DescriptorDigest.FromDigest(
                    "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"));
            Assert.IsInstanceOf <TestJson.InnerObjectClass>(testJson.InnerObject);
            Assert.AreEqual(testJson.InnerObject.Number, 23);

            Assert.AreEqual(
                testJson.InnerObject.Texts, new[] { "first text", "second text" });

            Assert.AreEqual(testJson.InnerObject.Digests, new[]
            {
                DescriptorDigest.FromDigest("sha256:91e0cae00b86c289b33fee303a807ae72dd9f0315c16b74e6ab0cdbe9d996c10"),
                DescriptorDigest.FromHash("4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236")
            });

            // ignore testJson.list
        }
        public void TestReadListOfJson()
        {
            SystemPath jsonFile = Paths.Get(TestResources.GetResource("core/json/basic_list.json").ToURI());

            string           jsonString  = Encoding.UTF8.GetString(Files.ReadAllBytes(jsonFile));
            IList <TestJson> listofJsons = JsonTemplateMapper.ReadListOfJson <TestJson>(jsonString);
            TestJson         json1       = listofJsons[0];
            TestJson         json2       = listofJsons[1];

            DescriptorDigest digest1 =
                DescriptorDigest.FromDigest(
                    "sha256:91e0cae00b86c289b33fee303a807ae72dd9f0315c16b74e6ab0cdbe9d996c10");
            DescriptorDigest digest2 =
                DescriptorDigest.FromDigest(
                    "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad");

            Assert.AreEqual(1, json1.Number);
            Assert.AreEqual(2, json2.Number);
            Assert.AreEqual("text1", json1.Text);
            Assert.AreEqual("text2", json2.Text);
            Assert.AreEqual(digest1, json1.Digest);
            Assert.AreEqual(digest2, json2.Digest);
            Assert.AreEqual(10, json1.InnerObject.Number);
            Assert.AreEqual(20, json2.InnerObject.Number);
            Assert.AreEqual(2, json1.List.Count);
            Assert.IsTrue(json2.List.Count == 0);
        }
Beispiel #3
0
 // Start is called before the first frame update
 private void Awake()
 {
     myHealth              = GetComponent <Health>();
     myEnergy              = GetComponent <Energy>();
     testingJson           = new TestJson();
     testingJson.maxHealth = myHealth.maxAmount;
     testingJson.maxEnergy = myEnergy.MaxEnergy;
 }
Beispiel #4
0
        public void CheckBasicJsonFormatReturnTheGoodSring()
        {
            var      format    = FormatterFactory.CreateFormat("JSON");
            string   retString = "{" + Environment.NewLine + "  \"Var1\": \"test\"," + Environment.NewLine + "  \"Var2\": \"test\"" + Environment.NewLine + "}";
            TestJson test      = new TestJson();

            Assert.AreEqual(retString, format.Format <TestJson>(test));
        }
Beispiel #5
0
    void OnLoad()
    {
        string input = "";

        input       = File.ReadAllText(Path.Combine(Application.persistentDataPath, "test.json"));
        testingJson = JsonUtility.FromJson <TestJson>(input);
        UpdateStats();
        Debug.Log("Loaded" + input);
    }
Beispiel #6
0
    public void Deserialize_WhenGivenEmpty_ReturnsDefaults()
    {
        var test = TestJson.Deserialize("{}");

        Assert.NotNull(test);

        Assert.Null(test.name);
        Assert.Equal(0, test.age);
        Assert.Null(test.home);
    }
Beispiel #7
0
        public async Task UpdateJsonValueTest([IncludeDataSources(false, TestProvName.AllSqlServer2016Plus)] string context)
        {
            var schema = new MappingSchema();

            schema.SetConverter <DbObject <TestJson>, string>(v => JsonConvert.SerializeObject(v.Value));
            schema.SetConverter <DbObject <TestJson>, DataParameter>(v => new DataParameter
            {
                DataType = DataType.NVarChar,
                Value    = JsonConvert.SerializeObject(v.Value)
            });
            schema.SetConverter <string, DbObject <TestJson> >(json => new DbObject <TestJson>(JsonConvert.DeserializeObject <TestJson>(json) !));

            using (var db = (DataConnection)GetDataContext(context, schema))
                using (var table = db.CreateLocalTable <TestTable>())
                {
                    var newRecord = new TestTable()
                    {
                        Id   = TestData.Guid1,
                        Json = new DbObject <TestJson>(new TestJson
                        {
                            String = "Test",
                            Number = 1
                        })
                    };

                    db.Insert(newRecord);

                    var savedRecord = await table.FirstAsync(x => x.Id == newRecord.Id).ConfigureAwait(false);

                    var newJson = new TestJson()
                    {
                        String = "Test1",
                        Number = 10
                    };

                    await table
                    .Where(o => o.Id == savedRecord.Id)
                    .Set(o => o.Json, o => o.Json !
                         .Set(j => j.Number, newJson.Number)
                         .Set(j => j.String, newJson.String)
                         ).UpdateAsync()
                    .ConfigureAwait(false);

                    var lastQuery = db.LastQuery;

                    savedRecord = await table.FirstAsync(x => x.Id == newRecord.Id).ConfigureAwait(false);

                    //Assert.AreEqual(savedRecord.Json.Value, newJson);

                    Assert.That(lastQuery, Contains.Substring("JSON_MODIFY(JSON_MODIFY"));
                }
        }
Beispiel #8
0
        public void Parse_GivenNegativeModifiedValue_ReturnsCreator()
        {
            // Arrange
            dynamic json = JObject.Parse(TestJson.Get("creator2"));

            var sut = new CreatorParser();

            // Act
            Creator result = sut.Parse(json);

            // Assert
            Assert.AreEqual(null, result.Modified);
        }
Beispiel #9
0
 public async Task <List <ShuttleLevel> > Read()
 {
     try
     {
         string json = new TestJson().Json; // Todo: use DI
         return(JsonConvert.DeserializeObject <List <ShuttleLevel> >(json));
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error occurred while trying to Read from JsonReader." + ex);
     }
     return(null);
 }
        public void TestWriteJson()
        {
            SystemPath jsonFile     = Paths.Get(TestResources.GetResource("core/json/basic.json").ToURI());
            string     expectedJson = Encoding.UTF8.GetString(Files.ReadAllBytes(jsonFile));

            TestJson testJson = new TestJson
            {
                Number = 54,
                Text   = "crepecake",
                Digest =
                    DescriptorDigest.FromDigest(
                        "sha256:8c662931926fa990b41da3c9f42663a537ccd498130030f9149173a0493832ad"),
                InnerObject = new TestJson.InnerObjectClass
                {
                    Number = 23,
                    Texts  = new List <string> {
                        "first text", "second text"
                    },
                    Digests = new[]
                    {
                        DescriptorDigest.FromDigest(
                            "sha256:91e0cae00b86c289b33fee303a807ae72dd9f0315c16b74e6ab0cdbe9d996c10"),
                        DescriptorDigest.FromHash(
                            "4945ba5011739b0b98c4a41afe224e417f47c7c99b2ce76830999c9a0861b236")
                    }
                }
            };

            TestJson.InnerObjectClass innerObject1 = new TestJson.InnerObjectClass
            {
                Number = 42,
                Texts  = new List <string>()
            };
            TestJson.InnerObjectClass innerObject2 = new TestJson.InnerObjectClass
            {
                Number = 99,
                Texts  = new List <string> {
                    "some text"
                },
                Digests =
                    new List <DescriptorDigest> {
                    DescriptorDigest.FromDigest(
                        "sha256:d38f571aa1c11e3d516e0ef7e513e7308ccbeb869770cb8c4319d63b10a0075e")
                }
            };
            testJson.List = new[] { innerObject1, innerObject2 };

            Assert.AreEqual(expectedJson, JsonTemplateMapper.ToUtf8String(testJson));
        }
Beispiel #11
0
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;

        if (tt == 0)
        {
            TestJson obj = new TestJson();
            obj.name = "obj";
            // Debug.Log(JsonMapper.ToJson(obj));

            Debug.Log("this is from handler" + JsonHandler.ToJson(obj));

            tt = 1;
        }
    }
Beispiel #12
0
        public void GetResponse_ReturnsSuccessFalse_OnError()
        {
            // Arrange
            dynamic json = JObject.Parse(TestJson.Get("api-error"));

            var sut = new EventParser();

            // Act
            Response <Event> result = sut.GetResponse <Event>(json);

            // Assert
            Assert.AreEqual(false, result.Success);
            Assert.AreEqual("409", result.Code);
            Assert.AreEqual("Limit greater than 100.", result.Status);
            Assert.IsNull(result.Data);
        }
Beispiel #13
0
        public void GetResponse_ReturnsSuccessTrue_OnSuccess()
        {
            // Arrange
            dynamic json = JObject.Parse(TestJson.Get("event-success"));

            var sut = new EventParser();

            // Act
            Response <Event> result = sut.GetResponse <Event>(json);

            // Assert
            Assert.AreEqual(true, result.Success);
            Assert.AreEqual("200", result.Code);
            Assert.AreEqual("Success.", result.Status);
            Assert.IsNotNull(result.Data);
        }
Beispiel #14
0
        public static void JsonTest9()
        {
            //原本的不可以,改了后可以
            Console.WriteLine("Enum/List/Dictionary Test");
            TestJson t = new TestJson();

            t.enumTestList.Add(EnumTest.c);
            t.enumDict.Add(EnumTest.c, 99999.999);
            var js = JsonMapper.ToJson(t);

            Console.WriteLine("js:\n" + js);
            var obj = JsonMapper.ToObject <TestJson>(js);

            Console.WriteLine(obj.ToString());
            Console.WriteLine("====================");
        }
Beispiel #15
0
        public void GetResponse_ReturnsSuccessFalse_OnAuthError()
        {
            // Arrange
            dynamic json = JObject.Parse(TestJson.Get("auth-error"));

            var sut = new EventParser();

            // Act
            Response <Event> result = sut.GetResponse <Event>(json);

            // Assert
            Assert.AreEqual(false, result.Success);
            Assert.AreEqual("InvalidCredentials", result.Code);
            Assert.AreEqual("The passed API key is invalid.", result.Status);
            Assert.IsNull(result.Data);
        }
Beispiel #16
0
        private void Start()
        {
            codeRamdon1   = UnityEngine.Random.Range(1, 9);
            codeRamdon2   = UnityEngine.Random.Range(1, 9);
            codeRamdon3   = UnityEngine.Random.Range(1, 9);
            codeRamdon4   = UnityEngine.Random.Range(1, 9);
            codeText.text = "" + codeRamdon1 + " " + codeRamdon2 + " " + codeRamdon3 + " " + codeRamdon4;

            codeRamdonglobal = int.Parse(codeRamdon1.ToString() + codeRamdon2.ToString() + codeRamdon3.ToString() +
                                         codeRamdon4.ToString());

            // envoi le code de connexion au serveur
            _testJson           = new TestJson();
            _testJson.eventName = "codeRandom";
            _testJson.codeUnity = codeRamdonglobal;

            SocketEvent.Client.sendMessage(SocketEvent.Client.ConvertDataObject(_testJson));
        }
Beispiel #17
0
        /// <summary>
        /// 选项卡改变事件
        /// </summary>
        /// <param name="sender">控件对象</param>
        /// <param name="e">事件参数</param>
        private void ApplyControl_SelectedTabChanged(object sender, TabStripTabChangedEventArgs e)
        {
            int tabSelectedIndex = ApplyControl.SelectedTabIndex;

            switch (tabSelectedIndex)
            {
            case 0:    //检查
                ClearData();
                dgExecItemCK.DataSource = null;
                Check     = new CheckJson();
                ExamClass = 1;
                break;

            case 1:    //化验
                dgExecItem.DataSource = null;
                Test      = new TestJson();
                ExamClass = 2;
                break;

            case 2:    //治疗
                dgExecItemZL.DataSource = null;
                ExamClass = 4;
                break;
            }

            IsLoad = true;
            //UpdateData = null;

            if (string.IsNullOrEmpty(ApplyHeadID))
            {
                ApplyHeadID = TempApplyHeadID;
            }

            if (!string.IsNullOrEmpty(ApplyHeadID))
            {
                if (ApplyType == ApplyControl.SelectedTabIndex.ToString())
                {
                    InvokeController("GetHeadDetail");
                }
            }

            InvokeController("GetExecDept");
            InitdgData();
        }
Beispiel #18
0
    public void Deserialize_WhenGivenFilled_ReturnsExpected()
    {
        var test = TestJson.Deserialize(@"
{
    ""name"": ""john"",
    ""age"": 24,
    ""home"": {
        ""address"": ""123 house street""
    }
}"
                                        );

        Assert.NotNull(test);
        Assert.NotNull(test.home);

        Assert.Equal("john", test.name);
        Assert.Equal(24, test.age);
        Assert.Equal("123 house street", test.home.address);
    }
Beispiel #19
0
        public void Parse_ReturnsCharacter()
        {
            // Arrange
            dynamic json = JObject.Parse(TestJson.Get("character"));

            var sut = new CharacterParser();

            // Act
            Character result = sut.Parse(json);

            // Assert
            Assert.AreEqual(1011334, result.Id);
            Assert.AreEqual("3-D Man", result.Name);
            Assert.AreEqual("Test description", result.Description);
            Assert.AreEqual(new DateTimeOffset(new DateTime(2014, 4, 29, 14, 18, 17), new TimeSpan(-4, 0, 0)), result.Modified);
            Assert.AreEqual("http://i.annihil.us/u/prod/marvel/i/mg/c/e0/535fecbbb9784", result.Thumbnail.Path);
            Assert.AreEqual("jpg", result.Thumbnail.Extension);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/characters/1011334", result.ResourceUri);

            Assert.AreEqual(12, result.Comics.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/characters/1011334/comics", result.Comics.CollectionUri);
            Assert.AreEqual(12, result.Comics.Items.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/21366", result.Comics.Items.First().ResourceUri);
            Assert.AreEqual("Avengers: The Initiative (2007) #14", result.Comics.Items.First().Name);
            Assert.AreEqual(null, result.Comics.Items.First().Type);
            Assert.AreEqual(null, result.Comics.Items.First().Role);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/10225", result.Comics.Items.Last().ResourceUri);
            Assert.AreEqual("Marvel Premiere (1972) #37", result.Comics.Items.Last().Name);
            Assert.AreEqual(null, result.Comics.Items.Last().Type);
            Assert.AreEqual(null, result.Comics.Items.Last().Role);
            Assert.AreEqual(12, result.Comics.Returned);

            Assert.AreEqual(3, result.Series.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/characters/1011334/series", result.Series.CollectionUri);
            Assert.AreEqual(3, result.Series.Items.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/1945", result.Series.Items.First().ResourceUri);
            Assert.AreEqual("Avengers: The Initiative (2007 - 2010)", result.Series.Items.First().Name);
            Assert.AreEqual(null, result.Series.Items.First().Type);
            Assert.AreEqual(null, result.Series.Items.First().Role);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/2045", result.Series.Items.Last().ResourceUri);
            Assert.AreEqual("Marvel Premiere (1972 - 1981)", result.Series.Items.Last().Name);
            Assert.AreEqual(null, result.Series.Items.Last().Type);
            Assert.AreEqual(null, result.Series.Items.Last().Role);
            Assert.AreEqual(3, result.Series.Returned);

            Assert.AreEqual(21, result.Stories.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/characters/1011334/stories", result.Stories.CollectionUri);
            Assert.AreEqual(20, result.Stories.Items.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/19947", result.Stories.Items.First().ResourceUri);
            Assert.AreEqual("Cover #19947", result.Stories.Items.First().Name);
            Assert.AreEqual("cover", result.Stories.Items.First().Type);
            Assert.AreEqual(null, result.Stories.Items.First().Role);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/54371", result.Stories.Items.Last().ResourceUri);
            Assert.AreEqual("Avengers: The Initiative (2007) #14, Spotlight Variant - Int", result.Stories.Items.Last().Name);
            Assert.AreEqual("interiorStory", result.Stories.Items.Last().Type);
            Assert.AreEqual(null, result.Stories.Items.Last().Role);
            Assert.AreEqual(20, result.Stories.Returned);

            Assert.AreEqual(1, result.Events.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/characters/1011334/events", result.Events.CollectionUri);
            Assert.AreEqual(1, result.Events.Items.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/events/269", result.Events.Items.Single().ResourceUri);
            Assert.AreEqual("Secret Invasion", result.Events.Items.Single().Name);
            Assert.AreEqual(null, result.Events.Items.Single().Type);
            Assert.AreEqual(null, result.Events.Items.Single().Role);
            Assert.AreEqual(1, result.Events.Returned);

            Assert.AreEqual(3, result.Urls.Count);
            Assert.AreEqual("detail", result.Urls.First().Type);
            Assert.AreEqual("http://marvel.com/characters/74/3-d_man?utm_campaign=apiRef&utm_source=20f18f98d97b8d7b9733fa6bdcfaea77", result.Urls.First().Value);
            Assert.AreEqual("comiclink", result.Urls.Last().Type);
            Assert.AreEqual("http://marvel.com/comics/characters/1011334/3-d_man?utm_campaign=apiRef&utm_source=20f18f98d97b8d7b9733fa6bdcfaea77", result.Urls.Last().Value);
        }
        public void Parse_ReturnsStory()
        {
            // Arrange
            dynamic json = JObject.Parse(TestJson.Get("story"));

            var sut = new StoryParser();

            // Act
            Story result = sut.Parse(json);

            // Assert
            Assert.AreEqual(26, result.Id);
            Assert.AreEqual("Haunted by her own father's death, Elektra finds that killing her latest target's daughter Ñ the only witness to the murder Ñ is", result.Title);
            Assert.AreEqual("Test description", result.Description);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/26", result.ResourceUri);
            Assert.AreEqual("story", result.Type);
            Assert.AreEqual(new DateTimeOffset(new DateTime(1969, 12, 31, 19, 0, 0), new TimeSpan(-5, 0, 0)), result.Modified);
            Assert.AreEqual(null, result.Thumbnail);

            Assert.AreEqual(2, result.Creators.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/26/creators", result.Creators.CollectionUri);
            Assert.AreEqual(2, result.Creators.Items.Count);
            Assert.AreEqual("Yoshitaka Amano", result.Creators.Items.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/29", result.Creators.Items.First().ResourceUri);
            Assert.AreEqual(null, result.Creators.Items.First().Type);
            Assert.AreEqual("penciller", result.Creators.Items.First().Role);
            Assert.AreEqual("Greg Rucka", result.Creators.Items.Last().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/28", result.Creators.Items.Last().ResourceUri);
            Assert.AreEqual(null, result.Creators.Items.Last().Type);
            Assert.AreEqual("writer", result.Creators.Items.Last().Role);
            Assert.AreEqual(2, result.Creators.Returned);

            Assert.AreEqual(0, result.Characters.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/26/characters", result.Characters.CollectionUri);
            Assert.AreEqual(0, result.Characters.Items.Count);
            Assert.AreEqual(0, result.Characters.Returned);

            Assert.AreEqual(1, result.Series.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/26/series", result.Series.CollectionUri);
            Assert.AreEqual(1, result.Series.Items.Count);
            Assert.AreEqual("Elektra & Wolverine: The Redeemer (1999)", result.Series.Items.Single().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/25", result.Series.Items.Single().ResourceUri);
            Assert.AreEqual(null, result.Series.Items.Single().Type);
            Assert.AreEqual(null, result.Series.Items.Single().Role);
            Assert.AreEqual(1, result.Series.Returned);

            Assert.AreEqual(1, result.Comics.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/26/comics", result.Comics.CollectionUri);
            Assert.AreEqual(1, result.Comics.Items.Count);
            Assert.AreEqual("Elektra & Wolverine: The Redeemer (Hardcover)", result.Comics.Items.Single().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/960", result.Comics.Items.Single().ResourceUri);
            Assert.AreEqual(null, result.Comics.Items.Single().Type);
            Assert.AreEqual(null, result.Comics.Items.Single().Role);
            Assert.AreEqual(1, result.Comics.Returned);

            Assert.AreEqual(0, result.Events.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/26/events", result.Events.CollectionUri);
            Assert.AreEqual(0, result.Events.Items.Count);
            Assert.AreEqual(0, result.Events.Returned);

            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/960", result.OriginalIssue.ResourceUri);
            Assert.AreEqual("Elektra & Wolverine: The Redeemer (Hardcover)", result.OriginalIssue.Name);
        }
Beispiel #21
0
        public void Parse_ReturnsCreator()
        {
            // Arrange
            dynamic json = JObject.Parse(TestJson.Get("creator"));

            var sut = new CreatorParser();

            // Act
            Creator result = sut.Parse(json);

            // Assert
            Assert.AreEqual(12844, result.Id);
            Assert.AreEqual("Aco", result.FirstName);
            Assert.AreEqual("Middle Name", result.MiddleName);
            Assert.AreEqual("Last Name", result.LastName);
            Assert.AreEqual("Suffix", result.Suffix);
            Assert.AreEqual("Aco", result.FullName);
            Assert.AreEqual(new DateTimeOffset(new DateTime(2016, 4, 15, 16, 42, 10), new TimeSpan(-4, 0, 0)), result.Modified);
            Assert.AreEqual("http://i.annihil.us/u/prod/marvel/i/mg/b/40/image_not_available", result.Thumbnail.Path);
            Assert.AreEqual("jpg", result.Thumbnail.Extension);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/12844", result.ResourceUri);

            Assert.AreEqual(2, result.Comics.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/12844/comics", result.Comics.CollectionUri);
            Assert.AreEqual(2, result.Comics.Items.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/55740", result.Comics.Items.First().ResourceUri);
            Assert.AreEqual("Squadron Supreme Vol. 2: Civil War II (Trade Paperback)", result.Comics.Items.First().Name);
            Assert.AreEqual(null, result.Comics.Items.First().Type);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/60051", result.Comics.Items.Last().ResourceUri);
            Assert.AreEqual("Uncanny X-Men Annual (2016) #1", result.Comics.Items.Last().Name);
            Assert.AreEqual(null, result.Comics.Items.Last().Type);
            Assert.AreEqual(2, result.Comics.Returned);

            Assert.AreEqual(2, result.Series.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/12844/series", result.Series.CollectionUri);
            Assert.AreEqual(2, result.Series.Items.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/20519", result.Series.Items.First().ResourceUri);
            Assert.AreEqual("Squadron Supreme Vol. 2: Civil War II (2016)", result.Series.Items.First().Name);
            Assert.AreEqual(null, result.Series.Items.First().Type);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/22014", result.Series.Items.Last().ResourceUri);
            Assert.AreEqual("Uncanny X-Men Annual (2016)", result.Series.Items.Last().Name);
            Assert.AreEqual(null, result.Series.Items.Last().Type);
            Assert.AreEqual(2, result.Series.Returned);

            Assert.AreEqual(2, result.Stories.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/12844/stories", result.Stories.CollectionUri);
            Assert.AreEqual(2, result.Stories.Items.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/122524", result.Stories.Items.First().ResourceUri);
            Assert.AreEqual("story from Squadron Supreme (2016)", result.Stories.Items.First().Name);
            Assert.AreEqual("interiorStory", result.Stories.Items.First().Type);
            Assert.AreEqual(null, result.Stories.Items.First().Role);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/130633", result.Stories.Items.Last().ResourceUri);
            Assert.AreEqual("cover from Uncanny X-Men Annual (2020) #1", result.Stories.Items.Last().Name);
            Assert.AreEqual("cover", result.Stories.Items.Last().Type);
            Assert.AreEqual(null, result.Stories.Items.Last().Role);
            Assert.AreEqual(2, result.Stories.Returned);

            Assert.AreEqual(0, result.Events.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/12844/events", result.Events.CollectionUri);
            Assert.AreEqual(0, result.Events.Items.Count);
            Assert.AreEqual(0, result.Events.Returned);

            Assert.AreEqual(1, result.Urls.Count);
            Assert.AreEqual("detail", result.Urls.Single().Type);
            Assert.AreEqual("http://marvel.com/comics/creators/12844/aco?utm_campaign=apiRef&utm_source=20f18f98d97b8d7b9733fa6bdcfaea77", result.Urls.Single().Value);
        }
Beispiel #22
0
        public void Parse_ReturnsComic()
        {
            // Arrange
            dynamic json = JObject.Parse(TestJson.Get("comic"));

            var sut = new ComicParser();

            // Act
            Comic result = sut.Parse(json);

            // Assert
            Assert.AreEqual(21472, result.Id);
            Assert.AreEqual(0, result.DigitalId);
            Assert.AreEqual("Ultimate Spider-Man (Spanish Language Edition) (2000) #8", result.Title);
            Assert.AreEqual(8, result.IssueNumber);
            Assert.AreEqual("Variant description", result.VariantDescription);
            Assert.AreEqual("Test description", result.Description);
            Assert.AreEqual(null, result.Modified);
            Assert.AreEqual("TestIsbn0001", result.Isbn);
            Assert.AreEqual("TestUpc0001", result.Upc);
            Assert.AreEqual("TestDiamondCode0001", result.DiamondCode);
            Assert.AreEqual("TestEan0001", result.Ean);
            Assert.AreEqual("TestIssn0001", result.Issn);
            Assert.AreEqual("Comic", result.Format);
            Assert.AreEqual(0, result.PageCount);

            Assert.AreEqual(1, result.TextObjects.Count);
            Assert.AreEqual("issue_solicit_text", result.TextObjects.Single().Type);
            Assert.AreEqual("en-us", result.TextObjects.Single().Language);
            Assert.AreEqual("\"The Marvel Age of Comics continues! This time around, Spidey meets his match against such classic villains as Electro and the Lizard, and faces the return of one of his first foes: the Vulture! Plus: Spider-Man vs. the Living Brain, Peter Parker's fight with Flash Thompson, and the wall-crawler tackles the high-flying Human Torch!\"", result.TextObjects.Single().Text);

            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/21472", result.ResourceUri);

            Assert.AreEqual(1, result.Urls.Count);
            Assert.AreEqual("detail", result.Urls.Single().Type);
            Assert.AreEqual("http://marvel.com/comics/issue/21472/ultimate_spider-man_spanish_language_edition_2000_8?utm_campaign=apiRef&utm_source=20f18f98d97b8d7b9733fa6bdcfaea77", result.Urls.Single().Value);

            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/5105", result.Series.ResourceUri);
            Assert.AreEqual("Ultimate Spider-Man (Spanish Language Edition) (2000 - 2001)", result.Series.Name);

            Assert.AreEqual(2, result.Variants.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/56155", result.Variants.First().ResourceUri);
            Assert.AreEqual("Old Man Logan (2016) #8", result.Variants.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/60075", result.Variants.Last().ResourceUri);
            Assert.AreEqual("Old Man Logan (2016) #8 (Albuquerque Death of X Variant)", result.Variants.Last().Name);

            Assert.AreEqual(0, result.Collections.Count);

            Assert.AreEqual(4, result.CollectedIssues.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/546", result.CollectedIssues.First().ResourceUri);
            Assert.AreEqual("Marvel Age Spider-Man (2004) #8", result.CollectedIssues.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/681", result.CollectedIssues.Last().ResourceUri);
            Assert.AreEqual("Marvel Age Spider-Man (2004) #5", result.CollectedIssues.Last().Name);

            Assert.AreEqual(2, result.Dates.Count);
            Assert.AreEqual("onsaleDate", result.Dates.First().Type);
            Assert.AreEqual(new DateTimeOffset(new DateTime(2029, 12, 31), new TimeSpan(-5, 0, 0)), result.Dates.First().Date);
            Assert.AreEqual("focDate", result.Dates.Last().Type);
            Assert.AreEqual(null, result.Dates.Last().Date);

            Assert.AreEqual(1, result.Prices.Count);
            Assert.AreEqual("printPrice", result.Prices.Single().Type);
            Assert.AreEqual(2.25, result.Prices.Single().Price);

            Assert.AreEqual("http://i.annihil.us/u/prod/marvel/i/mg/b/40/image_not_available", result.Thumbnail.Path);
            Assert.AreEqual("jpg", result.Thumbnail.Extension);

            Assert.AreEqual(4, result.Images.Count);
            Assert.AreEqual("http://i.annihil.us/u/prod/marvel/i/mg/a/40/4bc689a4ce796", result.Images.First().Path);
            Assert.AreEqual("jpg", result.Images.First().Extension);
            Assert.AreEqual("http://i.annihil.us/u/prod/marvel/i/mg/9/20/4bc665483c3aa", result.Images.Last().Path);
            Assert.AreEqual("jpg", result.Images.Last().Extension);

            Assert.AreEqual(0, result.Creators.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/21472/creators", result.Creators.CollectionUri);
            Assert.AreEqual(0, result.Creators.Items.Count);
            Assert.AreEqual(0, result.Creators.Returned);

            Assert.AreEqual(1, result.Characters.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/21472/characters", result.Characters.CollectionUri);
            Assert.AreEqual(1, result.Characters.Items.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/characters/1011010", result.Characters.Items.Single().ResourceUri);
            Assert.AreEqual("Spider-Man (Ultimate)", result.Characters.Items.Single().Name);
            Assert.AreEqual(null, result.Characters.Items.Single().Type);
            Assert.AreEqual(null, result.Characters.Items.Single().Role);
            Assert.AreEqual(1, result.Characters.Returned);

            Assert.AreEqual(2, result.Stories.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/21472/stories", result.Stories.CollectionUri);
            Assert.AreEqual(2, result.Stories.Items.Count);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/48972", result.Stories.Items.First().ResourceUri);
            Assert.AreEqual("Cover #48972", result.Stories.Items.First().Name);
            Assert.AreEqual("cover", result.Stories.Items.First().Type);
            Assert.AreEqual(null, result.Stories.Items.First().Role);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/48973", result.Stories.Items.Last().ResourceUri);
            Assert.AreEqual("Interior #48973", result.Stories.Items.Last().Name);
            Assert.AreEqual("interiorStory", result.Stories.Items.Last().Type);
            Assert.AreEqual(null, result.Stories.Items.Last().Role);
            Assert.AreEqual(2, result.Stories.Returned);

            Assert.AreEqual(0, result.Events.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/21472/events", result.Events.CollectionUri);
            Assert.AreEqual(0, result.Events.Items.Count);
            Assert.AreEqual(0, result.Events.Returned);
        }
Beispiel #23
0
        /// <summary>
        /// 打印执行单
        /// </summary>
        /// <param name="sender">触发控件</param>
        /// <param name="e">事件参数</param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
            DataTable  dtReport         = new DataTable();
            List <int> iApplyHeadIDList = new List <int>();

            switch (tabControl1.SelectedTabIndex)
            {
            case 0:     //检查
                dtReport = (DataTable)grdApplyList.DataSource;
                break;

            case 1:     //检验
                dtReport = (DataTable)grdExamList.DataSource;
                break;

            case 2:     //治疗
                dtReport = (DataTable)grdTreatList.DataSource;
                break;
            }

            foreach (DataRow dr in dtReport.Rows)
            {
                int    iApplyHeadID = Convert.ToInt32(dr["ApplyHeadID"]);
                string sAppyContent = string.Empty;
                Dictionary <string, object> myDictionary = new Dictionary <string, object>();

                myDictionary.Add("EmpName", empName);
                myDictionary.Add("WorkName", workName);

                myDictionary.Add("PatName", dr["PatName"].ToString());
                myDictionary.Add("Age", GetAge(dr["Age"].ToString()));
                myDictionary.Add("PatSex", dr["Sex"].ToString());
                myDictionary.Add("DiseaseName", dr["EnterDiseaseName"].ToString());
                myDictionary.Add("SerialNumber", dr["CaseNumber"].ToString());
                myDictionary.Add("cureno", dr["SerialNumber"].ToString());
                myDictionary.Add("BedNo", dr["BedNo"].ToString());
                myDictionary.Add("ExcuteDeptName", dr["ExecuteDeptName"]);
                myDictionary.Add("ApplyDeptName", dr["ApplyDeptName"]);
                myDictionary.Add("ApplyDeptDoctor", dr["ApplyDeptDoctor"]);
                myDictionary.Add("ApplyDate", dr["ApplyDate"]);
                myDictionary.Add("TotalFee", Convert.ToDecimal(dr["TotalFee"].ToString()));
                myDictionary.Add("ItemName", dr["ItemName"]);
                sAppyContent = dr["ApplyContent"].ToString();

                switch (tabControl1.SelectedTabIndex)
                {
                case 0:
                    CheckJson check = JsonConvert.DeserializeObject <CheckJson>(sAppyContent);
                    myDictionary.Add("Assay", check.Assay);
                    myDictionary.Add("Assist", check.Assist);
                    myDictionary.Add("Digest", check.Digest);
                    myDictionary.Add("Signs", check.Signs);
                    myDictionary.Add("Xray", check.Xray);
                    myDictionary.Add("Part", check.Part);
                    EfwControls.CustomControl.ReportTool.GetReport((InvokeController("this") as AbstractController).LoginUserInfo.WorkId, 2013, 0, myDictionary, null).Print(false);
                    break;

                case 1:
                    TestJson test = JsonConvert.DeserializeObject <TestJson>(sAppyContent);
                    myDictionary.Add("Sample", test.SampleName);
                    myDictionary.Add("Purpose", test.Goal);
                    EfwControls.CustomControl.ReportTool.GetReport((InvokeController("this") as AbstractController).LoginUserInfo.WorkId, 2012, 0, myDictionary, null).Print(false);
                    break;

                case 2:
                    EfwControls.CustomControl.ReportTool.GetReport((InvokeController("this") as AbstractController).LoginUserInfo.WorkId, 2014, 0, myDictionary, null).Print(false);
                    break;
                }

                iApplyHeadIDList.Add(iApplyHeadID);
            }

            UpdateApplyPrint(iApplyHeadIDList);
        }
Beispiel #24
0
        static void TestJson()
        {
            TestJson test = new TestJson();

            test.Test();
        }
        public void Parse_ReturnsSeries()
        {
            // Arrange
            dynamic json = JObject.Parse(TestJson.Get("series"));

            var sut = new SeriesParser();

            // Act
            Series result = sut.Parse(json);

            // Assert
            Assert.AreEqual(18454, result.Id);
            Assert.AreEqual("100th Anniversary Special (2014 - Present)", result.Title);
            Assert.AreEqual("Test description", result.Description);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/18454", result.ResourceUri);
            Assert.AreEqual(1, result.Urls.Count);
            Assert.AreEqual("detail", result.Urls.Single().Type);
            Assert.AreEqual("http://marvel.com/comics/series/18454/100th_anniversary_special_2014_-_present?utm_campaign=apiRef&utm_source=20f18f98d97b8d7b9733fa6bdcfaea77", result.Urls.Single().Value);
            Assert.AreEqual(2014, result.StartYear);
            Assert.AreEqual(2099, result.EndYear);
            Assert.AreEqual("Rated T", result.Rating);
            Assert.AreEqual("limited", result.Type);
            Assert.AreEqual(new DateTimeOffset(new DateTime(2015, 1, 14, 8, 48, 32), new TimeSpan(-5, 0, 0)), result.Modified);
            Assert.AreEqual("http://i.annihil.us/u/prod/marvel/i/mg/b/40/image_not_available", result.Thumbnail.Path);
            Assert.AreEqual("jpg", result.Thumbnail.Extension);

            Assert.AreEqual(5, result.Creators.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/18454/creators", result.Creators.CollectionUri);
            Assert.AreEqual(5, result.Creators.Items.Count);
            Assert.AreEqual("Andy Lanning", result.Creators.Items.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/485", result.Creators.Items.First().ResourceUri);
            Assert.AreEqual(null, result.Creators.Items.First().Type);
            Assert.AreEqual("writer", result.Creators.Items.First().Role);
            Assert.AreEqual("David Lopez", result.Creators.Items.Last().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/12392", result.Creators.Items.Last().ResourceUri);
            Assert.AreEqual(null, result.Creators.Items.Last().Type);
            Assert.AreEqual("penciller (cover)", result.Creators.Items.Last().Role);
            Assert.AreEqual(5, result.Creators.Returned);

            Assert.AreEqual(0, result.Characters.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/18454/characters", result.Characters.CollectionUri);
            Assert.AreEqual(0, result.Characters.Items.Count);
            Assert.AreEqual(0, result.Characters.Returned);

            Assert.AreEqual(10, result.Stories.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/18454/stories", result.Stories.CollectionUri);
            Assert.AreEqual(10, result.Stories.Items.Count);
            Assert.AreEqual("cover from 100th Anniversary Special (2014) #1", result.Stories.Items.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/110101", result.Stories.Items.First().ResourceUri);
            Assert.AreEqual("cover", result.Stories.Items.First().Type);
            Assert.AreEqual(null, result.Stories.Items.First().Role);
            Assert.AreEqual("story from 100th Anniversary Special (2014) #5", result.Stories.Items.Last().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/110110", result.Stories.Items.Last().ResourceUri);
            Assert.AreEqual("interiorStory", result.Stories.Items.Last().Type);
            Assert.AreEqual(null, result.Stories.Items.Last().Role);
            Assert.AreEqual(10, result.Stories.Returned);

            Assert.AreEqual(5, result.Comics.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/18454/comics", result.Comics.CollectionUri);
            Assert.AreEqual(5, result.Comics.Items.Count);
            Assert.AreEqual("100th Anniversary Special (2014) #1", result.Comics.Items.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/49008", result.Comics.Items.First().ResourceUri);
            Assert.AreEqual(null, result.Comics.Items.First().Type);
            Assert.AreEqual(null, result.Comics.Items.First().Role);
            Assert.AreEqual("100th Anniversary Special (2014) #1", result.Comics.Items.Last().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/49007", result.Comics.Items.Last().ResourceUri);
            Assert.AreEqual(null, result.Comics.Items.Last().Type);
            Assert.AreEqual(null, result.Comics.Items.Last().Role);
            Assert.AreEqual(5, result.Comics.Returned);

            Assert.AreEqual(0, result.Events.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/18454/events", result.Events.CollectionUri);
            Assert.AreEqual(0, result.Events.Items.Count);
            Assert.AreEqual(0, result.Events.Returned);

            Assert.AreEqual("http://gateway.marvel.com/v1/public/events/240", result.Next.ResourceUri);
            Assert.AreEqual("Days of Future Present", result.Next.Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/events/233", result.Previous.ResourceUri);
            Assert.AreEqual("Atlantis Attacks", result.Previous.Name);
        }
Beispiel #26
0
        public void Parse_ReturnsEvent()
        {
            // Arrange
            dynamic json = JObject.Parse(TestJson.Get("event"));

            var sut = new EventParser();

            // Act
            Event result = sut.Parse(json);

            // Assert
            Assert.AreEqual(116, result.Id);
            Assert.AreEqual("Acts of Vengeance!", result.Title);
            Assert.AreEqual("Loki sets about convincing the super-villains of Earth to attack heroes other than those they normally fight in an attempt to destroy the Avengers to absolve his guilt over inadvertently creating the team in the first place.", result.Description);

            Assert.AreEqual(2, result.Urls.Count);
            Assert.AreEqual("detail", result.Urls.First().Type);
            Assert.AreEqual("http://marvel.com/comics/events/116/acts_of_vengeance?utm_campaign=apiRef&utm_source=20f18f98d97b8d7b9733fa6bdcfaea77", result.Urls.First().Value);
            Assert.AreEqual("wiki", result.Urls.Last().Type);
            Assert.AreEqual("http://marvel.com/universe/Acts_of_Vengeance!?utm_campaign=apiRef&utm_source=20f18f98d97b8d7b9733fa6bdcfaea77", result.Urls.Last().Value);

            Assert.AreEqual(new DateTimeOffset(new DateTime(2013, 6, 28, 16, 31, 24), new TimeSpan(-4, 0, 0)), result.Modified);
            Assert.AreEqual(new DateTime(1989, 12, 10), result.Start);
            Assert.AreEqual(new DateTime(2008, 1, 4), result.End);
            Assert.AreEqual("http://i.annihil.us/u/prod/marvel/i/mg/9/40/51ca10d996b8b", result.Thumbnail.Path);
            Assert.AreEqual("jpg", result.Thumbnail.Extension);

            Assert.AreEqual(117, result.Creators.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/events/116/creators", result.Creators.CollectionUri);
            Assert.AreEqual(20, result.Creators.Items.Count);
            Assert.AreEqual("Jeff Albrecht", result.Creators.Items.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/2707", result.Creators.Items.First().ResourceUri);
            Assert.AreEqual(null, result.Creators.Items.First().Type);
            Assert.AreEqual("inker", result.Creators.Items.First().Role);
            Assert.AreEqual("John Byrne", result.Creators.Items.Last().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/creators/1827", result.Creators.Items.Last().ResourceUri);
            Assert.AreEqual(null, result.Creators.Items.Last().Type);
            Assert.AreEqual("artist", result.Creators.Items.Last().Role);
            Assert.AreEqual(20, result.Creators.Returned);

            Assert.AreEqual(85, result.Characters.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/events/116/characters", result.Characters.CollectionUri);
            Assert.AreEqual(20, result.Characters.Items.Count);
            Assert.AreEqual("Alpha Flight", result.Characters.Items.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/characters/1010370", result.Characters.Items.First().ResourceUri);
            Assert.AreEqual(null, result.Characters.Items.First().Type);
            Assert.AreEqual(null, result.Characters.Items.First().Role);
            Assert.AreEqual("Dazzler", result.Characters.Items.Last().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/characters/1009267", result.Characters.Items.Last().ResourceUri);
            Assert.AreEqual(null, result.Characters.Items.Last().Type);
            Assert.AreEqual(null, result.Characters.Items.Last().Role);
            Assert.AreEqual(20, result.Characters.Returned);

            Assert.AreEqual(145, result.Stories.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/events/116/stories", result.Stories.CollectionUri);
            Assert.AreEqual(20, result.Stories.Items.Count);
            Assert.AreEqual("Cover #12960", result.Stories.Items.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/12960", result.Stories.Items.First().ResourceUri);
            Assert.AreEqual("cover", result.Stories.Items.First().Type);
            Assert.AreEqual(null, result.Stories.Items.First().Role);
            Assert.AreEqual("Thieves Honor", result.Stories.Items.Last().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/stories/14921", result.Stories.Items.Last().ResourceUri);
            Assert.AreEqual("interiorStory", result.Stories.Items.Last().Type);
            Assert.AreEqual(null, result.Stories.Items.Last().Role);
            Assert.AreEqual(20, result.Stories.Returned);

            Assert.AreEqual(52, result.Comics.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/events/116/comics", result.Comics.CollectionUri);
            Assert.AreEqual(20, result.Comics.Items.Count);
            Assert.AreEqual("Alpha Flight (1983) #79", result.Comics.Items.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/12744", result.Comics.Items.First().ResourceUri);
            Assert.AreEqual(null, result.Comics.Items.First().Type);
            Assert.AreEqual(null, result.Comics.Items.First().Role);
            Assert.AreEqual("Doctor Strange, Sorcerer Supreme (1988) #11", result.Comics.Items.Last().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/comics/20170", result.Comics.Items.Last().ResourceUri);
            Assert.AreEqual(null, result.Comics.Items.Last().Type);
            Assert.AreEqual(null, result.Comics.Items.Last().Role);
            Assert.AreEqual(20, result.Comics.Returned);

            Assert.AreEqual(22, result.Series.Available);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/events/116/series", result.Series.CollectionUri);
            Assert.AreEqual(20, result.Series.Items.Count);
            Assert.AreEqual("Alpha Flight (1983 - 1994)", result.Series.Items.First().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/2116", result.Series.Items.First().ResourceUri);
            Assert.AreEqual(null, result.Series.Items.First().Type);
            Assert.AreEqual(null, result.Series.Items.First().Role);
            Assert.AreEqual("Web of Spider-Man (1985 - 1995)", result.Series.Items.Last().Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/series/2092", result.Series.Items.Last().ResourceUri);
            Assert.AreEqual(null, result.Series.Items.Last().Type);
            Assert.AreEqual(null, result.Series.Items.Last().Role);
            Assert.AreEqual(20, result.Series.Returned);

            Assert.AreEqual("http://gateway.marvel.com/v1/public/events/240", result.Next.ResourceUri);
            Assert.AreEqual("Days of Future Present", result.Next.Name);
            Assert.AreEqual("http://gateway.marvel.com/v1/public/events/233", result.Previous.ResourceUri);
            Assert.AreEqual("Atlantis Attacks", result.Previous.Name);
        }
Beispiel #27
0
        public async Task <CreateSystemResponse> Create(CreateSystem system)
        {
            var response = new CreateSystemResponse();

            if (string.IsNullOrEmpty(system.Name))
            {
                response.Error = "Введите название системы";
                return(response);
            }
            if (system.Name.Length > 40)
            {
                response.Error = "Слишком длинное название системы";
                return(response);
            }
            if (system.About == null)
            {
                system.About = "";
            }
            if (system.About.Length > 140)
            {
                response.Error = "Слишком длинное описание системы";
                return(response);
            }
            var user = await _userManager.GetUserAsync(User);

            var obj = new Test
            {
                Name        = system.Name,
                Description = system.About,
                User        = user
            };
            var        pictureTask = Task.CompletedTask;
            FileStream stream      = null;

            if (system.Picture != null)
            {
                if (system.Picture.Length > 5 * 1024 * 1024)
                {
                    response.Error = "Картинка слишком большая";
                    return(response);
                }
                var path = "/systems/" + obj.Id;
                switch (system.Picture.ContentType)
                {
                case "image/gif":
                    path += ".gif";
                    break;

                case "image/jpeg":
                    path += ".jpg";
                    break;

                case "image/png":
                    path += ".png";
                    break;

                default:
                    response.Error = "Картинка неизвестного формата";
                    return(response);
                }
                stream      = new FileStream(_hostingEnvironment.WebRootPath + path, FileMode.Create);
                pictureTask = system.Picture.CopyToAsync(stream);
                path       += "?d=" + DateTimeOffset.Now.ToUnixTimeMilliseconds();
                obj.Picture = path;
            }
            var responseObj = new TestJson
            {
                system = new SystemJson
                {
                    name    = obj.Name,
                    picture = obj.Picture,
                    about   = obj.Description,
                    pub     = obj.Published,
                    guid    = obj.Id.ToString()
                }
            };
            var json = JsonConvert.SerializeObject(responseObj);

            obj.PublishedJson = json;
            obj.AutosavedJson = json;
            _db.Tests.Add(obj);

            response.Succeded = true;
            response.Json     = json;

            await Task.WhenAll(pictureTask, _db.SaveChangesAsync());

            stream?.Close();
            return(response);
        }