public async Task should_add_new_item(string jsonEntity) { var entity = JsonConvert.DeserializeObject <Item>(jsonEntity); var options = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: "should_add_new_items") .Options; using (var context = new TestCatalogContext(options)) { context.Database.EnsureCreated(); } using (var context = new TestCatalogContext(options)) { var sut = new ItemRepository(context); sut.Add(entity); await sut.UnitOfWork.SaveEntitiesAsync(); } using (var context = new TestCatalogContext(options)) { context.Items .FirstOrDefault(_ => _.Id == entity.Id) .ShouldNotBeNull(); } }
public async Task should_returns_null_with_id_not_present() { var options = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: "should_returns_null_with_id_not_present") .Options; using (var context = new TestCatalogContext(options)) { context.Database.EnsureCreated(); var sut = new ItemRepository(context); var result = await sut.GetAsync(Guid.NewGuid()); result.ShouldBeNull(); } }
public async Task should_return_record_by_id(string guid) { var options = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: "should_return_record_by_id") .Options; using (var context = new TestCatalogContext(options)) { context.Database.EnsureCreated(); var sut = new ItemRepository(context); var result = await sut.GetAsync(new Guid(guid)); result.Id.ShouldBe(new Guid(guid)); } }
public async Task should_get_data() { var options = new DbContextOptionsBuilder <CatalogContext>() .UseInMemoryDatabase(databaseName: "should_get_data") .Options; using (var context = new TestCatalogContext(options)) { context.Database.EnsureCreated(); var sut = new ItemRepository(context); var result = await sut.GetAsync(); result .Count .ShouldBe(4); } }