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 DatabaseBackedCreatureEntryRepository([JetBrains.Annotations.NotNull] ContentDatabaseContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            Context = context;

            GenericRepository = new GeneralGenericCrudRepositoryProvider <int, CreatureEntryModel>(context.Creatures, context);
        }
Exemple #3
0
        public DatabaseBackedCreatureTemplateEntryRepository([NotNull] ContentDatabaseContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            Context = context;

            GenericRepository = new GeneralGenericCrudRepositoryProvider <int, CreatureTemplateEntryModel>(context.Set <CreatureTemplateEntryModel>(), context);
        }
Exemple #4
0
        protected GenericDatabaseBackedGameObjectBehaviorEntryRepository([JetBrains.Annotations.NotNull] ContentDatabaseContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            Context = context;

            GenericRepository = new GeneralGenericCrudRepositoryProvider <int, TEntryType>(context.Set <TEntryType>(), context);
        }
Exemple #5
0
        public virtual async Task Test_Contains_Id_False_On_Empty_Repository(TKeyType key)
        {
            //arrange
            IGenericRepositoryCrudable <TKeyType, TModelType> repository = BuildEmptyRepository();

            TKeyType keyValue = key;

            //act
            bool result = await repository.ContainsAsync(keyValue);

            //assert
            Assert.False(result, $"Expected empty repository with {nameof(IGenericRepositoryCrudable<TKeyType, TModelType>.ContainsAsync)} to produce false on empy.");
        }
Exemple #6
0
        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.");
        }
Exemple #7
0
        public async Task Test_Contains_Works_When_Unique_Models_Are_Added([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)
            {
                bool result = await repository.ContainsAsync(kvp.Key);

                Assert.True(result, $"Could not find Key: {kvp.Key.ToString()} Model: {kvp.Value.ToString()} in the repository for some reason.");
            }
        }
Exemple #8
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.");
            }
        }
Exemple #9
0
        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.");
        }
Exemple #10
0
        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}");
            }
        }
Exemple #11
0
        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);
        }
Exemple #12
0
 public DatabaseBackedGuildCharacterMembershipRepository(CharacterDatabaseContext context)
 {
     GenericGuildRelationshipRepository = new GeneralGenericCrudRepositoryProvider <int, CharacterGuildMemberRelationshipModel>(context.GuildMembers, context);
 }
 /// <inheritdoc />
 public DatabaseBackedCharacterSessionRepository(CharacterDatabaseContext context)
 {
     Context            = context ?? throw new ArgumentNullException(nameof(context));
     GenericCrudService = new GeneralGenericCrudRepositoryProvider <int, CharacterSessionModel>(context.CharacterSessions, context);
 }