Skip to content

improve mockability of generated code #137

@jeffMSFT

Description

@jeffMSFT

The code generator emits a lot of boilerplate that could be captured in a base interface, and thus simplify the task of mocking a collection proxy. For example,

    public interface IItemCollection : ProxyExtensions.IReadOnlyQueryableSetBase<Models.IItem>

    {

        Models.IItemFetcher GetById(System.Guid id);

        Task<ProxyExtensions.IPagedCollection<Models.IItem>> ExecuteAsync();

        Task AddItemAsync(Models.IItem item, System.Boolean deferSaveChanges = false);

        Models.IItemFetcher this[System.Guid id]    { get; }
    }

...could become

    // unique to my model
    public partial interface IItemCollection : IEntityCollection<Models.IItem>
    {
        Models.IEntityFetcher<Models.IItem> GetById(System.Guid id);
    }

    // shared by all entity definitions, perhaps in ProxyExtensions assembly
    public interface IEntityCollection<T> : ProxyExtensions.IReadOnlyQueryableSetBase<T>
    {
        Task<ProxyExtensions.IPagedCollection<T>> ExecuteAsync();

        Task AddItemAsync(T item, System.Boolean deferSaveChanges = false);

        Models.IEntityFetcher<T> this[System.Guid id]    { get; }
    }

    public interface IEntityFetcher<TSource>

    {
        Task<T> ExecuteAsync();

        T Expand<TTarget>(System.Linq.Expressions.Expression<System.Func<TSource, TTarget>> navigationPropertyAccessor);
    }

Is the team amenable to this kind of refactoring?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions