public void Initialize() { fakeStories = new Story[] { new Story { Message = "First story", PostedOn = new DateTime(2000, 1, 1, 15, 1, 0) }, new Story { Message = "Second story", PostedOn = new DateTime(2000, 1, 1, 15, 5, 0) } }; //Creates a fake ITimelineReaderService with a liked observer in order to //assert that the SUT relies on it timelineReaderServiceObserver = new StubObserver(); timelineReaderService = new Contracts.Interfaces.Fakes.StubITimelineReaderService { InstanceObserver = timelineReaderServiceObserver, GetTimelineString = userName => fakeStories }; storyFormatterObserver = new StubObserver(); storyFormatter = new Contracts.Interfaces.Fakes.StubIEntityFormatter<Story> { InstanceObserver = storyFormatterObserver, FormatT0 = story => story.Message }; sut = new ReadCommand(timelineReaderService, storyFormatter); }
/// <summary> /// Initializes a new instance of the <see cref="HttpEntityClient"/> class. /// </summary> /// <param name="baseAddress">The base address of the service.</param> /// <param name="formatter">The formatter that translates service responses into entitites.</param> /// <param name="convention">The convention to discover the resource name (or path) for the entities.</param> public HttpEntityClient(Uri baseAddress, IEntityFormatter formatter) { this.BaseAddress = baseAddress; this.http = new HttpClient(baseAddress); this.http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(formatter.ContentType)); this.EntityFormatter = formatter; }
public void Initialize() { fakeAggregatedStories = new AggregatedStory[] { new AggregatedStory { Story = new Story { Message = "First story", PostedOn = new DateTime(2000, 1, 1, 15, 1, 0) }}, new AggregatedStory { Story = new Story { Message = "Second story", PostedOn = new DateTime(2000, 1, 1, 15, 5, 0) }} }; //Creates a fake IAggregatorService with a liked observer in order to //assert that the SUT relies on it aggregatorServiceObserver = new StubObserver(); aggregatorService = new Contracts.Interfaces.Fakes.StubIAggregatorService { InstanceObserver = aggregatorServiceObserver, GetAggregatedStoriesString = userName => fakeAggregatedStories }; aggregatedStoryFormatterObserver = new StubObserver(); aggregatedStoryFormatter = new Contracts.Interfaces.Fakes.StubIEntityFormatter<AggregatedStory> { InstanceObserver = aggregatedStoryFormatterObserver, FormatT0 = aggregatedStory => aggregatedStory.Story.Message }; sut = new WallCommand(aggregatorService, aggregatedStoryFormatter); }
public EntityCommand(string entityType, string entityKey = "", Dictionary<string,string> switches = null, ISchemaChecker checker = null, IEntityFormatter formatter = null) :base(switches) { mEntityType = entityType; mEntityKey = entityKey; mChecker = checker; mFormatter = formatter; }
/// <summary> /// Initializes a new instance of the <see cref="T:Geocrest.Web.Mvc.Formatting.JsonReferenceLoopFormatter"/> class. /// </summary> /// <param name="formatter">The formatter.</param> /// <exception cref="T:System.ArgumentNullException"><paramref name="formatter"/></exception> public JsonReferenceLoopFormatter(IEntityFormatter formatter) { Throw.IfArgumentNull(formatter, "formatter"); this.formatter = formatter; this.SerializerSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DefaultValueHandling = DefaultValueHandling.Include }; }
public void Initialize() { //Creates a fake IEntityFormatter<Story> object that formats in an arbitrary test-recognizable way //just to assert that the SUT relies on it fakeStoryFormatter = new Contracts.Interfaces.Fakes.StubIEntityFormatter<Story> { FormatT0 = story => string.Format("FakeFormattedStory:{0}", story.Message) }; sut = new AggregatedStoryFormatter(fakeStoryFormatter); }
private static IEntityFormatter <TEntity> ResolveFormatter <TEntity>(TEntity entity) { IEntityFormatter <TEntity> result = null; Type entityType = typeof(TEntity); if (Formatters.ContainsKey(entityType)) { result = (IEntityFormatter <TEntity>)Formatters[entityType]; } return(result); }
public static TEntity ApplyFormatting <TEntity>(this TEntity entity) { if (entity != null) { IEntityFormatter <TEntity> formatter = ResolveFormatter(entity); if (formatter != null) { formatter.Apply(entity); } } return(entity); }
/// <summary> /// Initializes a new instance of the <see cref="T:Geocrest.Web.Hypermedia.Formatting.JsonHalFormatter"/> class. /// </summary> /// <param name="formatter">The formatter.</param> public JsonHalFormatter([Named("GeodataFormatter")] IEntityFormatter formatter) : base(formatter) { this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/hal+json")); this.AddQueryStringMapping("f", "haljson", "application/hal+json"); this.SerializerSettings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, DefaultValueHandling = DefaultValueHandling.Include }; this.SerializerSettings.Converters.Add(new ResourceCollectionConverter()); this.SerializerSettings.Converters.Add(new LinksConverter()); this.SerializerSettings.Converters.Add(new ResourceConverter()); }
public void ImplementsType <T>(bool direct) where T : class { if (Formatter != null) { return; } lock (_entityFormatters) if (_entityFormatters.TryGetValue(typeof(T), out var formatter)) { Formatter = formatter; } }
/// <summary> /// Gets a formatter of the specified type with an optional IEntityFormatter parameter. /// </summary> /// <param name="type">The type.</param> /// <param name="formatterName">Name of the formatter.</param> /// <returns> /// Returns an instance of <see cref="MediaTypeFormatter"/>. /// </returns> private MediaTypeFormatter GetFormatter(Type type, string formatterName = "") { MediaTypeFormatter formatter; if (!string.IsNullOrEmpty(formatterName)) { IEntityFormatter ef = BaseApplication.Kernel.Get <IEntityFormatter>(formatterName); formatter = (MediaTypeFormatter)BaseApplication.Kernel.Get(type, new IParameter[] { new ConstructorArgument("formatter", ef, true) }) ?? (MediaTypeFormatter)Activator.CreateInstance(type); } else { formatter = (MediaTypeFormatter)Activator.CreateInstance(type); } return(formatter); }
public ListEntitiesCommand(string entityType, string entityKey = "", Dictionary <string, string> switches = null, ISchemaChecker checker = null, IEntityFormatter formatter = null) : base(entityType, entityKey, switches, checker, formatter) { }
public EntityValueFormatter(IEntityFormatter <TEntity> entityFormatter) { _entityFormatter = entityFormatter; }
public void Add <T>(IEntityFormatter <T> formatter) where T : TSchema { _entityFormatters[formatter.EntityType] = formatter; }
/// <summary> /// Initializes a new instance of the <see cref="T:Geocrest.Web.Hypermedia.Formatting.XmlHalFormatter"/> class. /// </summary> /// <param name="formatter">The formatter.</param> public XmlHalFormatter([Named("GeodataFormatter")] IEntityFormatter formatter) : base(formatter) { this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/hal+xml")); this.AddQueryStringMapping("f", "halxml", "application/hal+xml"); }
public EntityValueEntityPropertyFormatter(PropertyInfo propertyInfo, IEntityFormatter <TEntityValue> entityFormatter) { _entityFormatter = entityFormatter; _property = new ReadOnlyProperty <TEntity, Value <TEntityValue> >(propertyInfo); }
/// <summary> /// Initializes a new instance of the <see cref="T:Geocrest.Web.Mvc.Formatting.XmlReferenceLoopFormatter"/> class. /// </summary> /// <param name="formatter">The formatter.</param> /// <exception cref="T:System.ArgumentNullException"><paramref name="formatter"/></exception> public XmlReferenceLoopFormatter(IEntityFormatter formatter) { Throw.IfArgumentNull(formatter, "formatter"); this.formatter = formatter; }
public void Add(int priority, IEntityFormatter formatter) { Formatters[priority] = formatter; }
public void AddCustomFormatter(IEntityFormatter formatter) { Add(CurrentCustomFormatterPosition++, formatter); }
/// <summary> /// Initializes a new instance of the <see cref="HttpEntityConventionClient"/> class. /// </summary> /// <param name="baseAddress">The base address of the service.</param> /// <param name="formatter">The formatter that translates service responses into entitites.</param> /// <param name="convention">The convention to discover the resource name (or path) for the entities.</param> public HttpEntityConventionClient(Uri baseAddress, IEntityFormatter formatter, IEntityResourceNameConvention convention) : base(baseAddress, formatter) { this.ResourceNameConvention = convention; }
/// <summary> /// </summary> /// <param name="aggregatorService">Service class to use to perform the command</param> /// <param name="storyFormatter">Object that this class uses to text-render the aggregated story items</param> public WallCommand(IAggregatorService aggregatorService, IEntityFormatter<AggregatedStory> storyFormatter) { this.aggregatorService = aggregatorService; this.storyFormatter = storyFormatter; }