public void TestCreateOrUpdateQuotaAsync_Normal_CorrectQuotaFrame()
        {
            const string surveyId = "surveyId";
            var          quota    = new QuotaLevel(true)
            {
                Target      = 10,
                GrossTarget = 15,
                Attributes  =
                    new Collection <QuotaAttribute>
                {
                    new QuotaAttribute {
                        Name = "Attribute", IsSelectionOptional = true, OdinVariable = "var"
                    }
                }
            };

            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient
            .Setup(client => client.PutAsJsonAsync(It.IsAny <string>(), It.IsAny <QuotaLevel>()))
            .Returns(CreateTask(HttpStatusCode.OK, new StringContent("")));

            var target = new NfieldSurveysService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            target.CreateOrUpdateQuotaAsync(surveyId, quota).Wait();

            mockedHttpClient.Verify(hc => hc.PutAsJsonAsync(It.IsAny <string>(), quota), Times.Once());
        }
        public void TestQuotaQueryAsync_ServerReturnsQuery_ReturnsListWithQuotaLevel()
        {
            const string levelId = "LevelId";
            const string name    = "Name";

            var expectedQuotaLevel = new QuotaLevel
            {
                Id   = levelId,
                Name = name
            };
            var mockedNfieldConnection = new Mock <INfieldConnectionClient>();
            var mockedHttpClient       = CreateHttpClientMock(mockedNfieldConnection);

            mockedHttpClient
            .Setup(client => client.GetAsync(ServiceAddress + "surveys/1/quota"))
            .Returns(CreateTask(HttpStatusCode.OK, new StringContent(JsonConvert.SerializeObject(expectedQuotaLevel))));

            var target = new NfieldSurveysService();

            target.InitializeNfieldConnection(mockedNfieldConnection.Object);

            var actualQuotaLevel = target.QuotaQueryAsync("1").Result;

            mockedHttpClient.Verify(hc => hc.GetAsync(It.IsAny <string>()), Times.Once());
            Assert.Equal(expectedQuotaLevel.Id, actualQuotaLevel.Id);
            Assert.Equal(expectedQuotaLevel.Name, actualQuotaLevel.Name);
        }
        /// <summary>
        /// <see cref="INfieldSurveysService.CreateOrUpdateQuotaAsync"/>
        /// </summary>
        public Task <QuotaLevel> CreateOrUpdateQuotaAsync(string surveyId, QuotaLevel quota)
        {
            var uri = new Uri(SurveysApi, $"{surveyId}/{QuotaControllerName}");

            return(Client.PutAsJsonAsync(uri, quota)
                   .ContinueWith(
                       responseMessageTask => responseMessageTask.Result.Content.ReadAsStringAsync().Result)
                   .ContinueWith(
                       stringTask => JsonConvert.DeserializeObject <QuotaLevel>(stringTask.Result))
                   .FlattenExceptions());
        }
        /// <summary>
        /// <see cref="INfieldSurveysService.CreateOrUpdateQuotaAsync"/>
        /// </summary>
        public Task <QuotaLevel> CreateOrUpdateQuotaAsync(string surveyId, QuotaLevel quota)
        {
            string uri = string.Format(@"{0}{1}/{2}", SurveysApi.AbsoluteUri, surveyId, QuotaControllerName);

            return(Client.PutAsJsonAsync(uri, quota)
                   .ContinueWith(
                       responseMessageTask => responseMessageTask.Result.Content.ReadAsStringAsync().Result)
                   .ContinueWith(
                       stringTask => JsonConvert.DeserializeObject <QuotaLevel>(stringTask.Result))
                   .FlattenExceptions());
        }
        // Token: 0x060021F5 RID: 8693 RVA: 0x000C2188 File Offset: 0x000C0388
        protected string RenderELCQuota()
        {
            if (!this.isELCFolderWithQuota)
            {
                return(string.Empty);
            }
            QuotaLevel quotaLevel = QuotaLevel.Normal;
            int        num        = (int)Math.Round((double)this.elcFolderSize / (double)this.elcFolderQuota * 100.0);

            if (num >= 100)
            {
                quotaLevel = QuotaLevel.Exceeded;
            }
            else if (num >= 75)
            {
                quotaLevel = QuotaLevel.AboveWarning;
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("<div class=\"divElcComponent\" id=\"divElcQuota\">");
            stringBuilder.Append("<div class=\"divIBTxt\" id=\"divQuotaBar\">");
            StringBuilder stringBuilder2 = new StringBuilder();

            using (StringWriter stringWriter = new StringWriter(stringBuilder2))
            {
                RenderingUtilities.RenderQuotaBar(stringWriter, base.UserContext, num, quotaLevel);
            }
            stringBuilder.Append(stringBuilder2.ToString());
            stringBuilder.Append("</div> ");
            stringBuilder.Append("<div class=\"divIBTxt\" id=\"divFldUsg\" ");
            stringBuilder.Append((num < 100) ? string.Empty : "style=\"display:none;\" ");
            stringBuilder.Append(">");
            stringBuilder2 = new StringBuilder();
            using (StringWriter stringWriter2 = new StringWriter(stringBuilder2))
            {
                Utilities.RenderSizeWithUnits(stringWriter2, this.elcFolderQuota, false);
            }
            stringBuilder.AppendFormat(LocalizedStrings.GetHtmlEncoded(-659755432), "<span id=spnFldPrcntUsd>" + num + "</span>", stringBuilder2.ToString() + "</span>");
            stringBuilder.Append("</div> <div class=\"divIBTxt\" id=\"divFldExcd\" ");
            stringBuilder.Append((num < 100) ? "style=\"display:none;\" " : string.Empty);
            stringBuilder.Append(">");
            stringBuilder.Append(LocalizedStrings.GetHtmlEncoded(231890609));
            stringBuilder.Append("</div></div>");
            return(stringBuilder.ToString());
        }