Ejemplo n.º 1
0
        public void GetAccountProperties()
        {
            //Test request
            string expected = File.ReadAllText(Path.Combine(_requestsTestDataPath, "GetAccountProperties.xml"));
            var    request  = new GetAccountProperties
            {
                SessionId           = "sid",
                AccountEmail        = "*****@*****.**",
                AccountPropertyList = new TAccountPropertyList
                {
                    Items = new List <TAPIProperty>
                    {
                        new TAPIProperty {
                            PropName = "u_name"
                        },
                        new TAPIProperty {
                            PropName = "u_alias"
                        },
                        new TAPIProperty {
                            PropName = "u_type"
                        }
                    }
                }
            };
            var requestXml = request.ToXml().InnerXmlFormatted();

            Assert.AreEqual(expected, requestXml);

            //Test response
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(File.ReadAllText(Path.Combine(_responsesTestDataPath, "GetAccountProperties.xml")));
            var response = request.FromHttpRequestResult(new HttpRequestResult {
                Response = doc.InnerXml
            });

            Assert.AreEqual("result", response.Type);
            Assert.AreEqual(3, response.Items.Count);

            var name = response.Items.FirstOrDefault(x => x.APIProperty.PropName == "u_name");

            Assert.NotNull(name);
            Assert.AreEqual(typeof(TPropertyString), name.PropertyVal.GetType());
            Assert.AreEqual("Test", ((TPropertyString)name.PropertyVal).Val);
            Assert.AreEqual(TPermission.ReadWrite, response.Items.First().PropertyRight);

            var alias = response.Items.FirstOrDefault(x => x.APIProperty.PropName == "u_alias");

            Assert.NotNull(alias);
            Assert.AreEqual(typeof(TPropertyString), alias.PropertyVal.GetType());
            Assert.AreEqual("test", ((TPropertyString)alias.PropertyVal).Val);
            Assert.AreEqual(TPermission.ReadWrite, response.Items.Last().PropertyRight);

            var type = response.Items.FirstOrDefault(x => x.APIProperty.PropName == "u_type");

            Assert.NotNull(type);
            Assert.AreEqual(typeof(TPropertyString), type.PropertyVal.GetType());
            Assert.AreEqual("0", ((TPropertyString)type.PropertyVal).Val);
            Assert.AreEqual(TPermission.ReadWrite, response.Items.Last().PropertyRight);
        }
Ejemplo n.º 2
0
        public void GetAccountProperties_PropertySet()
        {
            //Test request
            string expected = File.ReadAllText(Path.Combine(_requestsTestDataPath, "GetAccountProperties_PropertySet.xml"));
            var request = new GetAccountProperties
            {
                SessionId = "sid",
                AccountEmail = "*****@*****.**",
                AccountPropertySet = TAccountPropertySet.Info
            };
            var requestXml = request.ToXml().InnerXmlFormatted();
            Assert.AreEqual(expected, requestXml);

            //Test response
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(File.ReadAllText(Path.Combine(_responsesTestDataPath, "GetAccountProperties_PropertySet.xml")));
            var response = request.FromHttpRequestResult(new HttpRequestResult { Response = doc.InnerXml });

            Assert.AreEqual("result", response.Type);
            Assert.AreEqual(5, response.Items.Count);

            var a_Name = response.Items.FirstOrDefault(x => x.APIProperty.PropName == "A_Name");
            Assert.NotNull(a_Name);
            Assert.AreEqual(typeof(TAccountName), a_Name.PropertyVal.GetType());
            Assert.AreEqual("Test", ((TAccountName)a_Name.PropertyVal).Name);
            Assert.True(String.IsNullOrEmpty(((TAccountName)a_Name.PropertyVal).Surname));
            Assert.AreEqual(TPermission.ReadWrite, a_Name.PropertyRight);

            var a_Quota = response.Items.FirstOrDefault(x => x.APIProperty.PropName == "A_Quota");
            Assert.NotNull(a_Quota);
            Assert.AreEqual(typeof(TAccountQuota), a_Quota.PropertyVal.GetType());
            Assert.AreEqual(934, ((TAccountQuota)a_Quota.PropertyVal).MailboxSize);
            Assert.AreEqual(0, ((TAccountQuota)a_Quota.PropertyVal).MailboxQuota);
            Assert.AreEqual(TPermission.ReadWrite, a_Quota.PropertyRight);

            var a_Image = response.Items.FirstOrDefault(x => x.APIProperty.PropName == "A_Image");
            Assert.NotNull(a_Image);
            Assert.AreEqual(typeof(TPropertyNoValue), a_Image.PropertyVal.GetType());
            Assert.AreEqual(TPermission.ReadWrite, a_Image.PropertyRight);

            var a_AliasList = response.Items.FirstOrDefault(x => x.APIProperty.PropName == "A_AliasList");
            Assert.NotNull(a_AliasList);
            Assert.AreEqual(typeof(TPropertyStringList), a_AliasList.PropertyVal.GetType());
            Assert.AreEqual(1, ((TPropertyStringList)a_AliasList.PropertyVal).Val.Count);
            Assert.AreEqual("test", ((TPropertyStringList)a_AliasList.PropertyVal).Val.First());
            Assert.AreEqual(TPermission.ReadWrite, a_AliasList.PropertyRight);

            var a_State = response.Items.FirstOrDefault(x => x.APIProperty.PropName == "A_State");
            Assert.NotNull(a_State);
            Assert.AreEqual(typeof(TAccountState), a_State.PropertyVal.GetType());
            Assert.AreEqual(TUserState.Empty, ((TAccountState)a_State.PropertyVal).State);
            Assert.AreEqual(TPermission.ReadWrite, a_State.PropertyRight);
        }