xt_oss/oss/entities/
style.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone,Serialize, Deserialize, Default)]
4pub struct Style {
5    #[serde(rename = "Name")]
6    pub name: String,
7    #[serde(rename = "Content")]
8    pub content: String,
9    #[serde(rename = "Category")]
10    pub category: Option<String>,
11    #[serde(
12        rename = "CreateTime",
13        skip_serializing_if = "Option::is_none",
14    )]
15    pub create_time: Option<String>,
16    #[serde(
17        rename = "LastModifyTime",
18        skip_serializing_if = "Option::is_none",
19    )]
20    pub last_modify_time: Option<String>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize, Default)]
24pub struct StyleList {
25    #[serde(rename = "Style")]
26    pub style: Option<Vec<Style>>,
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32    #[test]
33    fn style_1() {
34        let xml_content = r#"<Style>
35  <Name>imagestyle</Name>
36  <Content>image/resize,p_50</Content>
37  <Category>image</Category>
38  <CreateTime>Wed, 20 May 2020 12:07:15 GMT</CreateTime>
39  <LastModifyTime>Wed, 20 May 2020 12:07:15 GMT</LastModifyTime>
40</Style>"#;
41
42        let style: Style = quick_xml::de::from_str(&xml_content).unwrap();
43        assert_eq!(style.category, Some("image".to_string()));
44    }
45
46    #[test]
47    fn style_2() {
48        let xml_content = r#"<?xml version="1.0" encoding="UTF-8"?>
49<StyleList>
50    <Style>
51        <Name>imagestyle</Name>
52        <Content>image/resize,p_50</Content>
53        <Category>image</Category>
54        <CreateTime>Wed, 20 May 2020 12:07:15 GMT</CreateTime>
55        <LastModifyTime>Wed, 20 May 2020 12:07:15 GMT</LastModifyTime>
56    </Style>
57    <Style>
58        <Name>imagestyle1</Name>
59        <Content>image/resize,w_200</Content>
60        <Category>image</Category>
61        <CreateTime>Wed, 20 May 2020 12:08:04 GMT</CreateTime>
62        <LastModifyTime>Wed, 20 May 2020 12:07:15 GMT</LastModifyTime>
63    </Style>
64    <Style>
65        <Name>imagestyle2</Name>
66        <Content>image/resize,w_300</Content>
67        <Category>image</Category>
68        <CreateTime>Fri, 12 Mar 2021 06:19:13 GMT</CreateTime>
69        <LastModifyTime>Wed, 20 May 2020 12:07:15 GMT</LastModifyTime>
70    </Style>
71</StyleList>"#;
72
73        let style_list: StyleList = quick_xml::de::from_str(&xml_content).unwrap();
74        let left = "image/resize,p_50";
75        let right = &style_list.style.unwrap()[0].content;
76        assert_eq!(left, right);
77    }
78
79    #[test]
80    fn style_3() {
81        let style = Style {
82            name: "imagestyle".to_string(),
83            content: "image/resize,p_50".to_string(),
84            category: Some("image".to_string()),
85            create_time: None,
86            last_modify_time: None,
87        };
88
89        let left = quick_xml::se::to_string(&style).unwrap();
90        let right = r#"<Style><Name>imagestyle</Name><Content>image/resize,p_50</Content><Category>image</Category></Style>"#;
91        assert_eq!(left, right);
92    }
93}