This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IRepositoryFactory | |
{ | |
IRepository<TEntity> Create<TEntity>(RepositoryOptions options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DbContext : IDbContext | |
{ | |
public DbContext(IRepositoryFactory repoFactory, string connectionString, string dbName) | |
{ | |
if (string.IsNullOrWhiteSpace(connectionString)) | |
throw new ArgumentNullException("connectionString"); | |
if (string.IsNullOrWhiteSpace(dbName)) | |
throw new ArgumentNullException("dbName"); | |
this.Posts = repoFactory.Create<Entities.Video>(new RepositoryOptions(connectionString, dbName, "posts")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IDbContext | |
{ | |
IRepository<Entities.Post> Posts { get; } | |
IRepository<Entities.User> Users { get; } | |
IRepository<Entities.Tag> Tags { get; } | |
IRepository<Entities.Taxonomy> Taxonomies { get; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IRepository<TEntity> | |
{ | |
string CollectionName { get; } | |
Task<long> CountAsync(FilterDefinition<TEntity> filter); | |
IFindFluent<TEntity, TEntity> Find(FilterDefinition<TEntity> filter); | |
IFindFluent<TEntity, TEntity> Find(Expression<Func<TEntity, bool>> filter); | |
Task<TEntity> FindOneAndReplaceAsync(FilterDefinition<TEntity> filter, TEntity replacement); | |
Task<TEntity> FindOneAndReplaceAsync(Expression<Func<TEntity, bool>> filter, TEntity replacement); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Repository<TEntity> : IRepository<TEntity> | |
{ | |
private readonly IMongoCollection<TEntity> _collection; | |
public Repository(IMongoCollection<TEntity> collection) | |
{ | |
if (null == collection) | |
throw new ArgumentNullException("collection"); | |
_collection = collection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FakeAsyncCursor<TEntity> : IAsyncCursor<TEntity> | |
{ | |
private readonly IEnumerable<TEntity> _items; | |
public FakeAsyncCursor(IEnumerable<TEntity> items) | |
{ | |
_items = items ?? Enumerable.Empty<TEntity>(); | |
} | |
public IEnumerable<TEntity> Current |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FakeFindFluent<TEntity> : IFindFluent<TEntity, TEntity> | |
{ | |
private readonly IEnumerable<TEntity> _items; | |
public FakeFindFluent(IEnumerable<TEntity> items) | |
{ | |
_items = items ?? Enumerable.Empty<TEntity>(); | |
} | |
public Task<TEntity> FirstOrDefaultAsync(CancellationToken cancellationToken) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mockFooService, | |
sut; | |
describe('FooController tests', function () { | |
beforeEach(function($q, $controller){ | |
mockFooService = { | |
bar: function() { | |
return $q.reject({ data: { message: 'Error message' } }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myApp = angular.module('myApp',[]); | |
myApp.controller('FooController', ['$scope', 'fooService', function($scope, fooService) { | |
var instance = this; | |
$scope.loadingStatus = 'none'; | |
instance.onBarCompleted = function(){ | |
$scope.loadingStatus = 'completed'; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myClassInstaceDeserialized = JsonConvert.DeserializeObject<MyClass>(jsonData, new JsonSerializerSettings | |
{ | |
TypeNameHandling = TypeNameHandling.Objects | |
}); |