public async Task GetEnvironmentByName() { // arrange var db = new MongoClient(); IMongoCollection <Environment> collection = _mongoResource.CreateCollection <Environment>(); var initial = new Environment("foo", "bar"); await collection.InsertOneAsync(initial, options : null, default); var repository = new EnvironmentRepository(collection); // act Environment retrieved = await repository.GetEnvironmentAsync("foo"); // assert Assert.Equal(initial.Id, retrieved.Id); Assert.Equal(initial.Description, retrieved.Description); }
public async Task AddEnvironment() { // arrange var db = new MongoClient(); IMongoCollection <Environment> collection = _mongoResource.CreateCollection <Environment>(); var repository = new EnvironmentRepository(collection); var environment = new Environment("foo", "bar"); // act await repository.AddEnvironmentAsync(environment); // assert Environment retrieved = await collection.AsQueryable() .Where(t => t.Id == environment.Id) .FirstOrDefaultAsync(); Assert.Equal(environment.Name, retrieved.Name); Assert.Equal(environment.Description, retrieved.Description); }
public async Task GetMultipleEnvironments() { // arrange var db = new MongoClient(); IMongoCollection <Environment> collection = _mongoResource.CreateCollection <Environment>(); var a = new Environment("foo1", "bar"); var b = new Environment("foo2", "bar"); await collection.InsertOneAsync(a, options : null, default); await collection.InsertOneAsync(b, options : null, default); var repository = new EnvironmentRepository(collection); // act IReadOnlyDictionary <Guid, Environment> retrieved = await repository.GetEnvironmentsAsync(new[] { a.Id, b.Id }); // assert Assert.True(retrieved.ContainsKey(a.Id)); Assert.True(retrieved.ContainsKey(b.Id)); }
public async Task UpdateEnvironment() { // arrange var db = new MongoClient(); IMongoCollection <Environment> collection = _mongoResource.CreateCollection <Environment>(); var initial = new Environment("foo", "bar"); await collection.InsertOneAsync(initial, options : null, default); var repository = new EnvironmentRepository(collection); // act var updated = new Environment(initial.Id, initial.Name, "abc"); await repository.UpdateEnvironmentAsync(updated); // assert Environment retrieved = await collection.AsQueryable() .Where(t => t.Id == initial.Id) .FirstOrDefaultAsync(); Assert.Equal(updated.Name, retrieved.Name); Assert.Equal(updated.Description, retrieved.Description); }