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)); }
public async Task Test_Can_Add_Two_Unique_Models_To_Repository() { //arrange IGenericRepositoryCrudable <TKeyType, TModelType> repository = BuildEmptyRepository(); TModelType model1 = BuildRandomModel(true); TModelType model2 = BuildRandomModel(true); //act bool addResult1 = await repository.TryCreateAsync(model1); bool addResult2 = await repository.TryCreateAsync(model2); //assert Assert.True(addResult1, $"Could not add Model1: {model1.ToString()} to repository for some reason."); Assert.True(addResult2, $"Could not add Model1: {model2.ToString()} to repository for some reason."); }
public async Task Test_Can_Add_New_Model_To_Repository() { //arrange IGenericRepositoryCrudable <TKeyType, TModelType> repository = BuildEmptyRepository(); TModelType model = BuildRandomModel(true); //act bool addResult = await repository.TryCreateAsync(model); //assert Assert.True(addResult, $"Could not add Model: {model.ToString()} to repository for some reason."); }
private async Task <Dictionary <TKeyType, TModelType> > BuildTestModelDictionary(int count, IGenericRepositoryCrudable <TKeyType, TModelType> repository) { Dictionary <TKeyType, TModelType> models = new Dictionary <TKeyType, TModelType>(); for (int i = 0; i < count; i++) { TModelType model = BuildRandomModel(true); await repository.TryCreateAsync(model); models[ProduceKeyFromModel(model)] = model; } return(models); }
public async Task Test_Adding_Duplicate_Model_Throws_Exception_With_Exeption_Mentioning_Key() { //arrange IGenericRepositoryCrudable <TKeyType, TModelType> repository = BuildEmptyRepository(); TModelType model = BuildRandomModel(true); //act bool addResult = await repository.TryCreateAsync(model); //assert Assert.ThrowsAsync <ArgumentException>(async() => await repository.TryCreateAsync(model)); //Check message value try { await repository.TryCreateAsync(model); } catch (Exception e) { Assert.True(e.Message.ToLower().Contains("key"), $"Exception methods should contain the word key somewhere in their message. Was: {e.Message}"); } }