public void When_the_verb_is_POST_the_Collection_passes_parameters_on_the_URI_and_in_the_body() { Init(model => { Method = Any.OdcmMethodPost(); Method.Class = model.EntityContainer; Method.ReturnType = Class; Method.IsCollection = false; Method.IsBoundToCollection = false; model.EntityContainer.Methods.Add(Method); }); using (var mockService = new MockService()) { var service = mockService .CreateContainer(EntityContainerType); mockService.ValidateParameterPassing("POST", service, "", Method, ServerMethodNameGenerator(), TargetEntity); } }
public void The_Service_parses_the_response() { var responseKeyValues = Class.GetSampleKeyArguments().ToArray(); var response = Class.GetSampleJObject(responseKeyValues); using (var mockService = new MockService()) { mockService .OnInvokeMethodRequest("GET", "/" + ServerMethodNameGenerator(), null, null) .RespondWithGetEntity(TargetEntity.Class.GetDefaultEntitySetName(), response); var service = mockService .CreateContainer(EntityContainerType, Any.TokenGetterFunction()); var result = service.InvokeMethod<Task>(Method.Name + "Async").GetPropertyValue<EntityBase>("Result"); result.ValidatePropertyValues(responseKeyValues); } }
public void When_it_changes_a_namespace_then_requests_OdataType_is_set_to_the_old_namespace() { var oldNamespace = _model.EntityContainer.Namespace; var namespacePrefix = Any.CSharpIdentifier(); var namespaceRename = Any.CSharpIdentifier(); var newNamespace = new OdcmNamespace(namespacePrefix + "." + namespaceRename); var namespaceMap = new Dictionary<string, string> { { oldNamespace.Name, namespaceRename } }; var proxy = GetProxyWithChangedNamespaces(namespacePrefix, namespaceMap); var @class = oldNamespace.Classes.OfType<OdcmEntityClass>().First(); var entityArtifacts = GetEntityArtifactsFromNewNamespace(@class, newNamespace, proxy, oldNamespace); using (var mockService = new MockService() ) { mockService .OnRequest(c => c.Request.Method == "POST" && c.Request.Path.Value == @class.GetDefaultEntitySetPath() && IsNamespaceReplaced(c.Request, oldNamespace.Name, newNamespace.Name)) .RespondWith( (c, b) => { c.Response.StatusCode = 201; c.Response.WithDefaultODataHeaders(); c.Response.WithODataEntityResponseBody(b, @class.GetDefaultEntitySetName(), null); }); var collection = mockService .CreateContainer(proxy.GetClass(newNamespace.Name, _model.EntityContainer.Name)) .GetPropertyValue<ReadOnlyQueryableSetBase>(entityArtifacts.Class.GetDefaultEntitySetName()); var instance = entityArtifacts.ConcreteType.Initialize(@class.GetSampleKeyArguments().ToArray()); var task = collection.InvokeMethod<Task>("Add" + @class.Name + "Async", args: new[] { instance, false }); task.Wait(); }
[Fact(Skip = "https://github.com/Microsoft/Vipr/issues/43")] public void When_it_changes_a_namespace_then_responses_odata_type_is_translated_to_new_namespace() { var oldNamespace = _model.EntityContainer.Namespace; var namespacePrefix = Any.CSharpIdentifier(); var namespaceRename = Any.CSharpIdentifier(); var newNamespace = new OdcmNamespace(namespacePrefix + "." + namespaceRename); var namespaceMap = new Dictionary<string, string> { { oldNamespace.Name, namespaceRename } }; var entityClasses = oldNamespace.Classes.OfType<OdcmEntityClass>().ToList(); var baseClass = entityClasses.Where(c => c.Base == null).RandomElement(); entityClasses.Remove(baseClass); baseClass.IsAbstract = true; var derivedClass = entityClasses.RandomElement(); entityClasses.Remove(derivedClass); derivedClass.Base = baseClass; entityClasses.RandomElement().Base = baseClass; var proxy = GetProxyWithChangedNamespaces(namespacePrefix, namespaceMap); var entityArtifacts = GetEntityArtifactsFromNewNamespace(derivedClass, newNamespace, proxy, oldNamespace); var responseObject = entityArtifacts.Class.GetSampleJObject(derivedClass.GetSampleKeyArguments().Concat(baseClass.GetSampleKeyArguments()).ToArray()); var responseOdataType = String.Format("#{0}.{1}", oldNamespace.Name, derivedClass.Name); var singletonPath = baseClass.GetDefaultSingletonPath(); using (var mockService = new MockService(true) ) { mockService .OnRequest(c => c.Request.Method == "GET" && c.Request.Path.Value == singletonPath) .RespondWith( (c, b) => { c.Response.StatusCode = 200; c.Response.WithDefaultODataHeaders(); c.Response.WithODataEntityResponseBody(mockService.GetBaseAddress(), baseClass.GetDefaultEntitySetName(), responseObject, new JProperty("@odata.type", new JValue(responseOdataType))); }); var fetcher = mockService .CreateContainer(proxy.GetClass(newNamespace.Name, _model.EntityContainer.Name)) .GetPropertyValue<RestShallowObjectFetcher>(baseClass.GetDefaultSingletonName()); var task = fetcher.ExecuteAsync(); var result = task.GetPropertyValue<EntityBase>("Result");