Exemple #1
0
        public virtual async Task Test_Update_Replaces_Existing_Model()
        {
            //arrange
            IGenericRepositoryCrudable <TKeyType, TModelType> repository = BuildEmptyRepository();
            TModelType model1 = BuildRandomModel(true);
            await repository.TryCreateAsync(model1)
            .ConfigureAwaitFalse();

            TModelType model2 = BuildRandomModel(false);

            //act
            await repository.UpdateAsync(this.ProduceKeyFromModel(model1), model2)
            .ConfigureAwaitFalseVoid();

            bool containsModel1 = await repository.ContainsAsync(ProduceKeyFromModel(model1))
                                  .ConfigureAwaitFalse();

            TModelType model3 = await repository.RetrieveAsync(ProduceKeyFromModel(model1))
                                .ConfigureAwaitFalse();

            //assert
            //Model1 should still seem like its in the database, but it should be Model2.
            Assert.True(containsModel1, $"Model1 key was in the database.");
            Assert.AreEqual(ProduceKeyFromModel(model1), ProduceKeyFromModel(model3));
        }
Exemple #2
0
        public async Task Test_Retreieve_Produces_Correct_Result([Range(1, 10)] int count)
        {
            //arrange
            IGenericRepositoryCrudable <TKeyType, TModelType> repository = BuildEmptyRepository();
            Dictionary <TKeyType, TModelType> models = await BuildTestModelDictionary(count, repository);

            //assert
            foreach (var kvp in models)
            {
                TModelType result = await repository.RetrieveAsync(kvp.Key);

                //We need to check that equality AND key values are the same
                Assert.AreEqual(ProduceKeyFromModel(result), kvp.Key, $"Retrieve produced model with non-matching keys.");
            }
        }