/// <summary> /// Instantiates a new Serializer class and calls WriteEntry method on it. /// </summary> /// <param name="dataServiceContext"></param> /// <returns></returns> private static Person SetupSerializerAndCallWriteEntry(DataServiceContext dataServiceContext) { Person person = new Person(); Address address = new Address(); Car car1 = new Car(); person.Cars.Add(car1); person.HomeAddress = address; dataServiceContext.AttachTo("Cars", car1); dataServiceContext.AttachTo("Addresses", address); var requestInfo = new RequestInfo(dataServiceContext); var serializer = new Serializer(requestInfo); var headers = new HeaderCollection(); var clientModel = new ClientEdmModel(ODataProtocolVersion.V4); var entityDescriptor = new EntityDescriptor(clientModel); entityDescriptor.State = EntityStates.Added; entityDescriptor.Entity = person; var requestMessageArgs = new BuildingRequestEventArgs("POST", new Uri("http://www.foo.com/Northwind"), headers, entityDescriptor, HttpStack.Auto); var linkDescriptors = new LinkDescriptor[] { new LinkDescriptor(person, "Cars", car1, clientModel), new LinkDescriptor(person, "HomeAddress", address, clientModel) }; var odataRequestMessageWrapper = ODataRequestMessageWrapper.CreateRequestMessageWrapper(requestMessageArgs, requestInfo); serializer.WriteEntry(entityDescriptor, linkDescriptors, odataRequestMessageWrapper); return person; }
public void Init() { this._address = new Address { Street = "123 fake st" }; this._entity = new Customer { Id = 1, Address = this._address, Emails = new List<string> { "*****@*****.**"} }; var model = new ClientEdmModel(ODataProtocolVersion.V4); var entityType = model.GetOrCreateEdmType(typeof(Customer)); var complexType = model.GetOrCreateEdmType(typeof(Address)); this._complexValue = new ClientEdmStructuredValue(this._address, model, model.GetClientTypeAnnotation(complexType)); this._entityValue = new ClientEdmStructuredValue(this._entity, model, model.GetClientTypeAnnotation(entityType)); }
public void OnEntityReferenceLink() { Person p = new Person(); Address a = new Address(); var testUrl = new Uri("http://foo.com/link", UriKind.Absolute); ODataEntityReferenceLink refLink = new ODataEntityReferenceLink(); var wrappedWriter = this.SetupTestActionExecuted((context, requestPipeline) => { requestPipeline.OnEntityReferenceLink((args) => { args.Source.Should().BeSameAs(p); args.Target.Should().BeSameAs(a); args.EntityReferenceLink.Url = testUrl; }); }); wrappedWriter.WriteEntityReferenceLink(refLink, p, a); refLink.Url.Should().BeSameAs(testUrl); }
public void OnNavLinkEndShouldBeFired() { Person p = new Person(); Address a = new Address(); ODataNavigationLink link = new ODataNavigationLink(); var wrappedWriter = this.SetupTestActionExecuted((context, requestPipeline) => { requestPipeline.OnNavigationLinkEnding((args) => { args.Source.Should().BeSameAs(p); args.Target.Should().BeSameAs(a); args.Link.Name = "foo"; }); }); wrappedWriter.WriteEnd(link, p, a); link.Name.Should().Be("foo"); }