예제 #1
0
        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));
        }
예제 #2
0
        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);
        }
예제 #3
0
        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());
        }
예제 #4
0
        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));
        }