Skip to content

Commit

Permalink
Address public API review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chinadragon0515 committed Sep 2, 2016
1 parent b113b14 commit febfa8e
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 43 deletions.
6 changes: 3 additions & 3 deletions src/Microsoft.Restier.Core/ApiBaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ public static void SetProperty(this ApiBase api, string name, object value)
}

/// <summary>
/// Clears a property.
/// Removes a property.
/// </summary>
/// <param name="api">
/// An API.
/// </param>
/// <param name="name">
/// The name of a property.
/// </param>
public static void ClearProperty(this ApiBase api, string name)
public static void RemoveProperty(this ApiBase api, string name)
{
api.GetPropertyBag().ClearProperty(name);
api.GetPropertyBag().RemoveProperty(name);
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Restier.Core/PropertyBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ public void SetProperty(string name, object value)
}

/// <summary>
/// Clears a property.
/// Removes a property.
/// </summary>
/// <param name="name">
/// The name of a property.
/// </param>
public void ClearProperty(string name)
public void RemoveProperty(string name)
{
Ensure.NotNull(name, "name");
this.properties.Remove(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ private void SetValues(object instance, Type type, IReadOnlyDictionary<string, o
propertyPair.Key));
}

// TODO GithubIssue #508
value = Activator.CreateInstance(propertyInfo.PropertyType);
SetValues(value, propertyInfo.PropertyType, dic);
}
Expand Down
17 changes: 6 additions & 11 deletions src/Microsoft.Restier.Publishers.OData/Model/OperationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ namespace Microsoft.Restier.Publishers.OData.Model
[AttributeUsage(AttributeTargets.Method)]
public sealed class OperationAttribute : Attribute
{
/// <summary>
/// Gets or sets the name of the operation.
/// The default name is same as method name.
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets or sets the namespace of the operation.
/// The default value will be same as the namespace of entity type.
Expand All @@ -32,23 +26,24 @@ public sealed class OperationAttribute : Attribute

/// <summary>
/// Gets or sets a value indicating whether the function is composable.
/// The default value is false
/// The default value is false.
/// </summary>
public bool IsComposable { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the operation is bound or not.
/// If it is set to true, then no matter what's the first parameter, it will be considered as bound.
/// If it is set to false, then no matter what's the first parameter, it will be considered as unbound.
/// The default value is false
/// The default value is false.
/// </summary>
public bool IsBound { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the operation has side effects.
/// If a operation does not have side effect, it means it is a function.
/// If a operation has side effect, it means it is a action.
/// The default value is false
/// If an operation does not have side effect, it means it is a function,
/// and need to use HTTP Get to call function.
/// If an operation has side effect, it means it is an action, and need to use HTTP post to call action.
/// The default value is false.
/// </summary>
public bool HasSideEffects { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ namespace Microsoft.Restier.Publishers.OData.Model
{
/// <summary>
/// Attribute that indicates a property is an entity set or singleton.
/// If the property type is IQueryable, it will be built as entity set or it will be built as singleton.
/// The name will be same as property name.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class ResourceAttribute : Attribute
{
/// <summary>
/// Gets or sets a value indicating whether it is singleton or entity set.
/// The default value is false means it is an entity set
/// </summary>
public bool IsSingleton { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ private void BuildEntitySetsAndSingletons(EdmModel model)
continue;
}

bool isSingleton = resourceAttribute.IsSingleton;
if ((!isSingleton && !IsEntitySetProperty(property))
|| (isSingleton && !IsSingletonProperty(property)))
bool isEntitySet = IsEntitySetProperty(property);
bool isSingleton = IsSingletonProperty(property);
if (!isSingleton && !isEntitySet)
{
// This means property type is not IQueryable<T> when indicating an entityset
// or not non-generic type when indicating a singleton
continue;
}

var propertyType = property.PropertyType;
if (!isSingleton)
if (isEntitySet)
{
propertyType = propertyType.GetGenericArguments()[0];
}
Expand All @@ -209,7 +209,7 @@ private void BuildEntitySetsAndSingletons(EdmModel model)
}

var container = model.EnsureEntityContainer(this.targetType);
if (!isSingleton)
if (isEntitySet)
{
if (container.FindEntitySet(property.Name) == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private class OperationMethodInfo

public string Name
{
get { return this.OperationAttribute.Name ?? this.Method.Name; }
get { return this.Method.Name; }
}

public string Namespace
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.Restier.Core.Tests/PropertyBag.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void PropertyBagManipulatesPropertiesCorrectly()
Assert.Equal("Test", api.GetProperty("Test"));
Assert.Equal("Test", api.GetProperty<string>("Test"));

api.ClearProperty("Test");
api.RemoveProperty("Test");
Assert.False(api.HasProperty("Test"));
Assert.Null(api.GetProperty("Test"));
Assert.Null(api.GetProperty<string>("Test"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public class ApiA : BaseApi
{
[Resource]
public IQueryable<Person> People { get; set; }
[Resource(IsSingleton = true)]
[Resource]
public Person Me { get; set; }
public IQueryable<Person> Invisible { get; set; }

Expand Down Expand Up @@ -236,7 +236,7 @@ public class ApiC : ApiB
{
[Resource]
public new IQueryable<Customer> Customers { get; set; }
[Resource(IsSingleton = true)]
[Resource]
public new Customer Me { get; set; }

public ApiC(IServiceProvider serviceProvider) : base(serviceProvider)
Expand Down Expand Up @@ -301,11 +301,11 @@ public ApiG(IServiceProvider serviceProvider) : base(serviceProvider)

public class ApiH : BaseApi
{
[Resource(IsSingleton = true)]
[Resource]
public Person Me { get; set; }
[Resource]
public IQueryable<Customer> Customers { get; set; }
[Resource(IsSingleton = true)]
[Resource]
public Customer Me2 { get; set; }

public static new IServiceCollection ConfigureApi(Type apiType, IServiceCollection services)
Expand Down
13 changes: 5 additions & 8 deletions test/Microsoft.Restier.TestCommon/PublicApi.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ public abstract class Microsoft.Restier.Core.ApiBase : IDisposable {
ExtensionAttribute(),
]
public sealed class Microsoft.Restier.Core.ApiBaseExtensions {
[
ExtensionAttribute(),
]
public static void ClearProperty (Microsoft.Restier.Core.ApiBase api, string name)

[
ExtensionAttribute(),
]
Expand Down Expand Up @@ -87,6 +82,11 @@ public sealed class Microsoft.Restier.Core.ApiBaseExtensions {
]
public static System.Threading.Tasks.Task`1[[Microsoft.Restier.Core.Query.QueryResult]] QueryAsync (Microsoft.Restier.Core.ApiBase api, Microsoft.Restier.Core.Query.QueryRequest request, params System.Threading.CancellationToken cancellationToken)

[
ExtensionAttribute(),
]
public static void RemoveProperty (Microsoft.Restier.Core.ApiBase api, string name)

[
ExtensionAttribute(),
]
Expand Down Expand Up @@ -656,7 +656,6 @@ public sealed class Microsoft.Restier.Publishers.OData.Model.OperationAttribute
bool HasSideEffects { [CompilerGeneratedAttribute(),]public get; [CompilerGeneratedAttribute(),]public set; }
bool IsBound { [CompilerGeneratedAttribute(),]public get; [CompilerGeneratedAttribute(),]public set; }
bool IsComposable { [CompilerGeneratedAttribute(),]public get; [CompilerGeneratedAttribute(),]public set; }
string Name { [CompilerGeneratedAttribute(),]public get; [CompilerGeneratedAttribute(),]public set; }
string Namespace { [CompilerGeneratedAttribute(),]public get; [CompilerGeneratedAttribute(),]public set; }
}

Expand All @@ -665,7 +664,5 @@ AttributeUsageAttribute(),
]
public sealed class Microsoft.Restier.Publishers.OData.Model.ResourceAttribute : System.Attribute, _Attribute {
public ResourceAttribute ()

bool IsSingleton { [CompilerGeneratedAttribute(),]public get; [CompilerGeneratedAttribute(),]public set; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -18,19 +19,22 @@
using Microsoft.Restier.Providers.EntityFramework;
using Microsoft.Restier.Publishers.OData.Model;
using System.Reflection;
using System.Runtime.Serialization;
using System.Web.OData.Builder;
using Microsoft.OData.Edm.Vocabularies;

namespace Microsoft.OData.Service.Sample.Trippin.Api
{
public class TrippinApi : EntityFrameworkApi<TrippinModel>
{
[NotMapped]
[IgnoreDataMember]
public TrippinModel ModelContext
{
get { return DbContext; }
}

[Resource(IsSingleton = true)]
[Resource]
public Person Me
{
get
Expand Down Expand Up @@ -85,7 +89,7 @@ public IQueryable<PersonWithAge> PeopleWithAge1
}
}

[Resource(IsSingleton = true)]
[Resource]
public PersonWithAge PeopleWithAgeMe
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
<HintPath>..\..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Web.DynamicData" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public IQueryable<Person> NewComePeople
}
}

[Resource(IsSingleton = true)]
[Resource]
public Person Me
{
get
Expand Down

0 comments on commit febfa8e

Please sign in to comment.