public void ConstructorShouldConstructWithSetters() { // Arrange (set up variables for row constructor) var text = "Some Text"; var value = 1734542d; var distance = new ResponseDistance { Text = text, Value = value }; var duration = new ResponseDuration { Text = text + value, Value = value }; var status = "Single"; var element = new ResponseElement { Distance = distance, Duration = duration, Status = status }; // Act (create row with variables) var row = new ResponseRow { Elements = new List <ResponseElement> { element } }; // Assert (ensure model properties are set to variables) Assert.NotNull(row.Elements); Assert.Single(row.Elements); Assert.Equal(element, row.Elements[0]); }
public void IIIF003() { string[] files = new string[] { "2.IIIF003Policy.xml", "2.IIIF003Request.xml", "2.IIIF003Response.xml" }; Assert.AreEqual(files.Length, 3); FileInfo policyFile = new FileInfo(Consts.Path + files[0]); FileInfo requestFile = new FileInfo(Consts.Path + files[1]); FileInfo responseFile = new FileInfo(Consts.Path + files[2]); using (FileStream fs = new FileStream(policyFile.FullName, FileMode.Open, FileAccess.Read)) using (FileStream fs1 = new FileStream(requestFile.FullName, FileMode.Open, FileAccess.Read)) using (FileStream fs2 = new FileStream(responseFile.FullName, FileMode.Open, FileAccess.Read)) { // Load Policy PolicyDocument policyDocument = (PolicyDocument)PolicyLoader.LoadPolicyDocument(fs, XacmlVersion.Version20, DocumentAccess.ReadOnly); // Load Request ContextDocumentReadWrite requestDocument = ContextLoader.LoadContextDocument(fs1, XacmlVersion.Version20); // Load ResponseElement ContextDocumentReadWrite responseDocument = ContextLoader.LoadContextDocument(fs2, XacmlVersion.Version20); EvaluationEngine engine = new EvaluationEngine(); ResponseElement res = engine.Evaluate(policyDocument, (ContextDocument)requestDocument); Assert.AreEqual(((ResultElement)res.Results[0]).Obligations.Count, ((ResultElement)responseDocument.Response.Results[0]).Obligations.Count); Assert.AreEqual(responseDocument.Response.Results.Count, res.Results.Count); Assert.IsTrue(((ResultElement)res.Results[0]).Decision.ToString() == ((ResultElement)responseDocument.Response.Results[0]).Decision.ToString(), string.Format("Decission incorrect Expected:{0} Returned:{1}", ((ResultElement)responseDocument.Response.Results[0]).Decision.ToString(), ((ResultElement)res.Results[0]).Decision.ToString())); Assert.IsTrue(((ResultElement)res.Results[0]).Status.StatusCode.Value == ((ResultElement)responseDocument.Response.Results[0]).Status.StatusCode.Value, String.Format("Status incorrect Expected:{0} Returned:{1}", ((ResultElement)responseDocument.Response.Results[0]).Status.StatusCode.Value, ((ResultElement)res.Results[0]).Status.StatusCode.Value)); } }
private static void VerifySubstitutionResponseElement(ResponseElement element) { var httpBlockElement = (SubstitutionResponseElement)element; Assert.NotNull(httpBlockElement); Assert.Equal(DefaultHttpResponseSubstitutionCallback, httpBlockElement.Callback); }
public string FindTokenValue(string name) { var claim = ResponseElement.Elements("token") .SingleOrDefault(elt => elt.Attribute("name").Value == name); return(claim?.Attribute("value").Value); }
public void ConstructorShouldConstructWithSetters() { // Arrange (create variables for model properties) var text = "Some Text"; var value = 1734542d; var distance = new ResponseDistance { Text = text, Value = value }; var duration = new ResponseDuration { Text = text + value, Value = value }; var status = "Single"; // Act (create model with variables) var element = new ResponseElement { Distance = distance, Duration = duration, Status = status }; // Assert (ensure the properties are set to the proper variables) Assert.Equal(distance, element.Distance); Assert.Equal(duration, element.Duration); Assert.Equal(status, element.Status); }
public string FindClaimValue(string claimType, string issuer = null) { var claim = ResponseElement.Elements("claim") .SingleOrDefault(elt => elt.Attribute("type").Value == claimType && (issuer == null || elt.Attribute("issuer").Value == issuer)); return(claim?.Attribute("value").Value); }
byte[] SerializeElement(ResponseElement e) { using (var ms = new MemoryStream()) { OutputCache.Serialize(ms, e); ms.Flush(); return(ms.GetBuffer()); } }
private static void VerifyMemoryResponseElement(ResponseElement element) { var memoryElement = (MemoryResponseElement)element; Assert.NotNull(memoryElement); Assert.Equal(DefaultHttpResponseBufferElementBufferSize, memoryElement.Length); Assert.Equal(DefaultHttpResponseBufferElementBuffer, memoryElement.Buffer); }
public string FindClaimValue(string claimType) { XElement claim = ResponseElement.Elements("claim").SingleOrDefault(elt => elt.Attribute("type").Value == claimType); if (claim == null) { return(null); } return(claim.Attribute("value").Value); }
public void ConstructorShouldConstructWithSetters() { // Arrange (set up variables for the Distance Matrix) var text = "Some Text"; var value = 1734542d; var distance = new ResponseDistance { Text = text, Value = value }; var duration = new ResponseDuration { Text = text + value, Value = value }; var status = "Single"; var element = new ResponseElement { Distance = distance, Duration = duration, Status = status }; var row1 = new ResponseRow { Elements = new List <ResponseElement> { element, element } }; var row2 = new ResponseRow { Elements = new List <ResponseElement> { element, element } }; // Act (create a DistanceMatrixResponse object by passing in parameters) var response = new Response { DestinationAddresses = new List <string> { "2124 Parker St.", "2399 Prospect St." }, OriginAddresses = new List <string> { "2132 Oxford St.", "2216 Blake St." }, Rows = new List <ResponseRow> { row1, row2 }, Status = status }; // Assert (ensure the properties are set to the values) Assert.Equal(2, response.DestinationAddresses.Count); Assert.Equal(2, response.OriginAddresses.Count); Assert.Equal(2, response.Rows.Count); Assert.Equal(status, response.Status); }
private static void VerifyOutputCacheFileResponseElement(ResponseElement element) { var cacheFileElement = (OutputCacheFileResponseElement)element; Assert.NotNull(cacheFileElement); Assert.Equal(DefaultHttpFileResponseElementFilePath, cacheFileElement.Path); Assert.Equal(DefaultHttpFileResponseElementOffset, cacheFileElement.Offset); Assert.Equal(DefaultHttpFileResponseElementSize, cacheFileElement.Length); Assert.False(cacheFileElement.IsImpersonating); Assert.True(cacheFileElement.SupportsLongTransmitFile); }
private static IEnumerable <XElement> DehydrateExpected(ResponseElement element) { return(from expected in element.ExpectedResponses select new XElement("Expected", new XAttribute("Trim", expected.Trim), expected.Key == null ? null : new XElement("KeyExpression", expected.Key.RawExpression), DehydrateExpressions(expected), new XElement("Destination", new XElement("Name", expected.Destination == null ? null : expected.Destination.Name), new XElement("Default", expected.Destination == null ? new object() : expected.Destination.Default)), new XElement("FailureMessage", expected.FailureMessage))); }
public OutputCacheEntry CreateOutputCacheEntry(CachedRawResponse cachedRawResponse, string depKey, string[] fileDependencies) { // // Do the converting from FX internal IHttpResponseElement classes to public ResponseElement classes List <ResponseElement> responseElements = new List <ResponseElement>(); foreach (var buffer in cachedRawResponse.RawResponse.Buffers) { Type type = buffer.GetType(); ResponseElement elem = null; // // HttpFileResponseElement if (type == HttpFileResponseElementType) { elem = CreateFileResponseElement(buffer); } // // HttpSubstBlockResponseElement else if (type == HttpSubstBlockResponseElementType) { elem = CreateSubstBlockResponseElement(buffer); } // // IHttpResponseElement else { elem = CreateMemoryResponseElement(buffer); } if (elem != null) { responseElements.Add(elem); } } return(new OutputCacheEntry() { CachedVaryId = cachedRawResponse.CachedVaryId, Settings = cachedRawResponse.CachePolicy, KernelCacheUrl = cachedRawResponse.KernelCacheUrl, DependenciesKey = depKey, Dependencies = fileDependencies, StatusCode = cachedRawResponse.RawResponse.StatusCode, StatusDescription = cachedRawResponse.RawResponse.StatusDescription, HeaderElements = cachedRawResponse.RawResponse.Headers, ResponseBuffers = responseElements }); }
/// <summary> /// esempio http://localhost/Laser.Orchard/expoincitta/api/Laser.Orchard.ContentExtension/Content?ContentType=User /// da richiamare come application/json e non come form /// </summary> /// <param name="ContentType"></param> /// <param name="Language"></param> /// <returns></returns> public dynamic Get(string ContentType, string Language = "it-IT") { ContentTypeDefinition contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(ContentType); if (contentTypeDefinition == null) { Response resp = new Response() { Success = false, Message = T("ContentType not exist").ToString(), ErrorCode = ErrorCode.Validation }; return(resp); } var eObj = new ExpandoObject() as IDictionary <string, Object>; #region Tutti i field foreach (ContentTypePartDefinition ctpd in contentTypeDefinition.Parts) { var fields = ctpd.PartDefinition.Fields.ToList(); string tipofield = ""; foreach (ContentPartFieldDefinition singleField in fields) { tipofield = singleField.FieldDefinition.Name; if (tipofield == typeof(TaxonomyField).Name) { #region Tassonomia in Lingua var taxobase = _taxonomyService.GetTaxonomyByName(singleField.Settings["TaxonomyFieldSettings.Taxonomy"]); int idmaster = taxobase.Id; if (taxobase.ContentItem.As <LocalizationPart>() != null) { if (((dynamic)taxobase.ContentItem).LocalizationPart.MasterContentItem != null) { idmaster = ((dynamic)taxobase.ContentItem).LocalizationPart.MasterContentItem.Id; } if (((dynamic)taxobase.ContentItem).LocalizationPart.Culture != null) { if (((dynamic)taxobase.ContentItem).LocalizationPart.Culture.Culture != Language) { taxobase = _taxonomyService.GetTaxonomies().Where(x => (x.Id == idmaster || (((dynamic)x.ContentItem).LocalizationPart.MasterContentItem != null && ((dynamic)x.ContentItem).LocalizationPart.MasterContentItem.Id == idmaster)) && ((dynamic)x.ContentItem).LocalizationPart.Culture.Culture == Language).FirstOrDefault(); } } } List <TermPart> cata = _taxonomyService.GetTerms(taxobase.Id).ToList();//.GetTermsForContentItem(currentUser.Id, singleField.Name).ToList(); List <string> ListCategory = new List <string>(); ListCategory = cata.Select(x => x.Id.ToString()).ToList(); List <ElementDetail> elements = new List <ElementDetail>(); foreach (var term in taxobase.Terms) { Int32?valore = term.Id; Int32?mediaid = null; try { MediaLibraryPickerField mpf = (MediaLibraryPickerField)(term.Fields.Where(x => x.FieldDefinition.Name == "MediaLibraryPickerField").FirstOrDefault()); mediaid = mpf.Ids[0]; } catch { } if (!term.Selectable) { valore = null; } if (term.FullPath == "/" + term.Id.ToString() || term.FullPath == term.Id.ToString()) { elements.Add(new ElementDetail() { Name = term.Name, Value = valore, ImageId = mediaid }); } else { Int32 idtermfather = Convert.ToInt32(term.FullPath.Split('/')[term.FullPath.Split('/').Length - 2]); FindTaxoVM(elements, idtermfather).Children.Add(new ElementDetail() { Name = term.Name, Value = valore, ImageId = mediaid }); } } ResponseElement re = new ResponseElement(); bool solofoglie = Convert.ToBoolean(singleField.Settings["TaxonomyFieldSettings.LeavesOnly"]); if (solofoglie) { ElementDetail TempElement = new ElementDetail(); //elemento fittizzio per procedura ricorsiva TempElement.Children = elements; AnnullaNonFoglie(TempElement); elements = TempElement.Children; } re.Values = elements; re.Setting = new ResponseSetting { Type = "Taxonomie", Required = Convert.ToBoolean(singleField.Settings["TaxonomyFieldSettings.Required"]), SingleChoice = Convert.ToBoolean(singleField.Settings["TaxonomyFieldSettings.SingleChoice"]) }; eObj.Add(ctpd.PartDefinition.Name + "." + singleField.Name, re); #endregion Tassonomia in Lingua } else if (tipofield == typeof(EnumerationField).Name) { string[] elencovalori = singleField.Settings["EnumerationFieldSettings.Options"].Split(new string[] { "\r\n" }, StringSplitOptions.None); List <string> elencoValoriInLingua = new List <string>(); List <ElementDetail> ele = new List <ElementDetail>(); foreach (string val in elencovalori) { ElementDetail tvm = new ElementDetail(); tvm.Value = val; tvm.Name = _localizedStringManager .GetLocalizedString(new string[] { "UserEnumeratore" }, val, Language) .Format; ele.Add(tvm); } ResponseElement re = new ResponseElement(); re.Values = ele; bool singlechoise = true; if (singleField.Settings["EnumerationFieldSettings.ListMode"] == "Listbox" || singleField.Settings["EnumerationFieldSettings.ListMode"] == "Checkbox") { singlechoise = false; } re.Setting = new ResponseSetting { Type = "Enumerator", Required = Convert.ToBoolean(singleField.Settings["EnumerationFieldSettings.Required"]), SingleChoice = singlechoise }; eObj.Add(ctpd.PartDefinition.Name + "." + singleField.Name, re); } } } #endregion Tutti i field return(Json(eObj)); }
private static XElement DehydrateElement(ResponseElement element) { return(new XElement("Element", new XElement("KeyExpression", element.Key.RawExpression), DehydrateExpected(element))); }