Esempio 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);
        }
Esempio 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);
        }
Esempio n. 3
0
        public void GetUserAccountProperties()
        {
            var api        = new IceWarpRpcApi();
            var authResult = Authenticate(api);

            var propertyNames = ClassHelper.Properites(typeof(User), BindingFlags.Instance | BindingFlags.Public).Select(x => x.Name).ToList();

            Assert.AreEqual(153, propertyNames.Count);

            var request = new GetAccountProperties
            {
                SessionId           = authResult.SessionId,
                AccountEmail        = "*****@*****.**",
                AccountPropertyList = new TAccountPropertyList
                {
                    Items = propertyNames.Select(x => new TAPIProperty {
                        PropName = x
                    }).ToList()
                }
            };
            var getPropertiesResult = api.Execute(_url, request);

            Assert.NotNull(getPropertiesResult);
            Assert.NotNull(getPropertiesResult.HttpRequestResult);
            Assert.True(getPropertiesResult.HttpRequestResult.Success);
            Assert.NotNull(getPropertiesResult.Items);

            var user = new User(getPropertiesResult.Items);

            Assert.True(user.U_Type.HasValue);
            Assert.AreEqual(AccountType.User, user.U_Type.Value);
            Assert.AreEqual("test", user.U_EmailAlias);
            Assert.True(user.U_Admin.HasValue);
            Assert.True(user.U_Admin.Value);
            Assert.True(user.U_MaxBoxSize.HasValue);
            Assert.AreEqual(0, user.U_MaxBoxSize);
            Assert.True(user.U_AccountValidTill_Date.HasValue);
            Assert.AreEqual(1899, user.U_AccountValidTill_Date.Value.Year);
            Assert.AreEqual(12, user.U_AccountValidTill_Date.Value.Month);
            Assert.AreEqual(30, user.U_AccountValidTill_Date.Value.Day);

            LogOut(api, authResult.SessionId);
        }