public void The_same_Id_exists_only_once() { //Arrange var datastore = new InMemoryDataStore <IData>(); var id = 42; var item1 = new Mock <IData>(); item1.SetupGet(fake => fake.Id).Returns(id); var item2 = new Mock <IData>(); item2.SetupGet(fake => fake.Id).Returns(id); var items = new[] { item1.Object, item2.Object }; //Act datastore.AddOrUpdateAsync(items).Wait(); var retrieved = datastore.GetAllAsync().Result; //Assert Assert.AreEqual(1, retrieved.Count(item => item.Id == id)); }
public void The_same_item_is_not_added_twice() { //Arrange var datastore = new InMemoryDataStore <IData>(); var items = new[] { new Mock <IData>().Object }; //Act datastore.AddOrUpdateAsync(items).Wait(); var countAfterFirstAdd = datastore.GetAllAsync().Result.Count(); datastore.AddOrUpdateAsync(items).Wait(); var countAfterSecondAdd = datastore.GetAllAsync().Result.Count(); //Assert Assert.AreEqual(countAfterFirstAdd, countAfterSecondAdd); }
public void Added_items_can_be_retrieved() { //Arrange var datastore = new InMemoryDataStore <IData>(); var items = new[] { new Mock <IData>().Object }; //Act datastore.AddOrUpdateAsync(items).Wait(); var retrieved = datastore.GetAllAsync().Result; //Assert Assert.AreEqual(items.Single(), retrieved.Single()); }
public void Update_updated_the_existing_item() { //Arrange var datastore = new InMemoryDataStore <IData>(); var id = 42; var item1 = new Mock <IData>(); item1.SetupGet(fake => fake.Id).Returns(id); var item2 = new Mock <IData>(); item2.SetupGet(fake => fake.Id).Returns(id); datastore.AddOrUpdateAsync(new[] { item1.Object }).Wait(); //Act datastore.UpdateAsync(id, item2.Object).Wait(); var retrieved = datastore.GetAllAsync().Result; //Assert Assert.AreEqual(item2.Object, retrieved.Single(item => item.Id == id)); }