コード例 #1
0
        public void Gets_expected_results_from_database_with_custom_metadata()
        {
            Database.AddStorageModelsToDatabase(StorageModels);

            var getTask = Database.StorageModelQueries.GetAllAsync();

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, StorageModels);
        }
コード例 #2
0
        public void Gets_expected_results_from_database()
        {
            Database.AddTestModelsToDatabase(TestModels);

            var getTask = Database.ModelQueries.GetAllAsync();

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, TestModels);
        }
コード例 #3
0
        public void Gets_expected_results_from_database_with_custom_metadata()
        {
            Database.AddStorageModelsToDatabase(StorageModels);

            var getTask = Database.StorageModelQueries.GetManyAsync(m => m.Model.Name.StartsWith(TestStorageName));

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, StorageModels);
        }
コード例 #4
0
        public void Gets_expected_subset_results_from_database_with_custom_metadata()
        {
            Database.AddStorageModelsToDatabase(StorageModels);

            var ids     = StorageModels.Skip(1).Take(3).Select(m => m.Model.Id);
            var getTask = Database.StorageModelQueries.GetManyAsync(m => ids.Contains(m.Model.Id));

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, StorageModels.Skip(1).Take(3).ToList());
        }
コード例 #5
0
        public void Gets_expected_subset_results_from_database()
        {
            Database.AddTestModelsToDatabase(TestModels);

            var ids     = TestModels.Skip(1).Take(3).Select(m => m.Id);
            var getTask = Database.ModelQueries.GetManyAsync(m => ids.Contains(m.Id));

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, TestModels.Skip(1).Take(3).ToList());
        }
コード例 #6
0
        public void Adds_records_to_database()
        {
            var addTask = Task.Run(() => Database.ModelCommands.AddManyAsync(TestModels));

            addTask.Wait();

            var getTask = Task.Run(() => Database.ModelQueries.GetAllAsync());

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, TestModels);
        }
コード例 #7
0
        public void Adds_record_to_database_with_custom_metadata()
        {
            var addTask = Task.Run(() => Database.StorageModelCommands.AddManyAsync(StorageModels));

            addTask.Wait();

            var getTask = Task.Run(() => Database.StorageModelQueries.GetAllAsync());

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, StorageModels);
        }
コード例 #8
0
        public void Removes_expected_result_from_database_with_custom_metadata()
        {
            Database.AddStorageModelsToDatabase(StorageModels);

            var removeTask = Database.StorageModelCommands.RemoveOneAsync(StorageModels[1].Model);

            removeTask.Wait();

            var getTask = Database.StorageModelQueries.GetAllAsync();

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, StorageModels.Where(m => m.Model.Id != StorageModels[1].Model.Id).ToList());
        }
コード例 #9
0
        public void Removes_expected_result_from_database()
        {
            Database.AddTestModelsToDatabase(TestModels);

            var removeTask = Database.ModelCommands.RemoveOneAsync(TestModels[1]);

            removeTask.Wait();

            var getTask = Database.ModelQueries.GetAllAsync();

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, TestModels.Where(m => m.Id != TestModels[1].Id).ToList());
        }
コード例 #10
0
        public void Remove_does_nothing_when_querying_for_nonexistent_data_with_custom_metadata()
        {
            Database.AddStorageModelsToDatabase(StorageModels);

            var removeTask = Database.StorageModelCommands.RemoveManyAsync(m => m.Model.Id == Guid.NewGuid());

            removeTask.Wait();

            var getTask = Database.StorageModelQueries.GetAllAsync();

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, StorageModels);
        }
コード例 #11
0
        public void Remove_does_nothing_when_querying_for_nonexistent_data()
        {
            Database.AddTestModelsToDatabase(TestModels);

            var nonExistent = new TestModel("me no exist", Guid.NewGuid());
            var removeTask  = Database.ModelCommands.RemoveOneAsync(nonExistent);

            removeTask.Wait();

            var getTask = Database.ModelQueries.GetAllAsync();

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, TestModels);
        }
コード例 #12
0
        public void Adds_when_model_does_not_exist_in_database_with_custom_metadata()
        {
            Database.AddStorageModelsToDatabase(StorageModels);

            var newModels = StorageModel.CreateMany("New models", count: 2);
            var models    = newModels.ToDictionary(m => m.Model.Id, m => m);

            var addOrUpdateTask = Database.StorageModelCommands.AddOrUpdateManyAsync(models);

            addOrUpdateTask.Wait();

            var getTask = Database.StorageModelQueries.GetManyAsync(m => models.Keys.Contains(m.Model.Id));

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, newModels);
        }
コード例 #13
0
        public void Does_not_overwrite_other_records()
        {
            Database.AddTestModelsToDatabase(TestModels);

            var updatedModel = TestModels[1];

            updatedModel.Name = "Updated name";

            var updateTask = Database.ModelCommands.UpdateOneAsync(updatedModel);

            updateTask.Wait();

            var getTask = Database.ModelQueries.GetManyAsync(m => m.Id != updatedModel.Id);

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, TestModels.Where(m => m.Id != updatedModel.Id).ToList());
        }
コード例 #14
0
        public void Does_not_overwrite_other_records()
        {
            Database.AddTestModelsToDatabase(TestModels);

            TestModels[1].Name = "Updated name 1";
            TestModels[2].Name = "Updated name 2";

            var models     = TestModels.Skip(1).Take(2).ToDictionary(m => m.Id, m => m);
            var updateTask = Database.ModelCommands.UpdateManyAsync(models);

            updateTask.Wait();

            var getTask = Database.ModelQueries.GetManyAsync(m => !models.Keys.Contains(m.Id));

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, TestModels.Where(m => !models.Keys.Contains(m.Id)).ToList());
        }
コード例 #15
0
        public void Updates_each_when_models_exist_in_database()
        {
            Database.AddTestModelsToDatabase(TestModels);

            TestModels[1].Name = "Updated name 1";
            TestModels[2].Name = "Updated name 2";

            var models          = TestModels.Skip(1).Take(2).ToDictionary(m => m.Id, m => m);
            var addOrUpdateTask = Database.ModelCommands.AddOrUpdateManyAsync(models);

            addOrUpdateTask.Wait();

            var getTask = Database.ModelQueries.GetManyAsync(m => models.Keys.Contains(m.Id));

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, TestModels.Where(m => models.Keys.Contains(m.Id)).ToList());
        }
コード例 #16
0
        public void Does_not_overwrite_other_records_with_custom_metadata()
        {
            Database.AddStorageModelsToDatabase(StorageModels);

            var updatedModel = StorageModels[1];

            updatedModel.Model.Name         = "Updated name";
            updatedModel.Metadata.FirstName = "Updated first name";
            updatedModel.Metadata.LastName  = "Updated last name";

            var updateTask = Database.StorageModelCommands.UpdateOneAsync(updatedModel.Model, updatedModel.Metadata);

            updateTask.Wait();

            var getTask = Database.StorageModelQueries.GetManyAsync(m => m.Model.Id != updatedModel.Model.Id);

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, StorageModels.Where(m => m.Model.Id != updatedModel.Model.Id).ToList());
        }
コード例 #17
0
        public void Updates_each_when_models_exist_in_database_with_custom_metadata()
        {
            Database.AddStorageModelsToDatabase(StorageModels);

            StorageModels[1].Model.Name         = "Updated name 1";
            StorageModels[1].Metadata.FirstName = "Updated first name 1";
            StorageModels[1].Metadata.LastName  = "Updated last name 1";
            StorageModels[2].Model.Name         = "Updated name 2";
            StorageModels[2].Metadata.FirstName = "Updated first name 2";
            StorageModels[2].Metadata.LastName  = "Updated last name 2";

            var models     = StorageModels.Skip(1).Take(2).ToDictionary(m => m.Model.Id, m => m);
            var updateTask = Database.StorageModelCommands.UpdateManyAsync(models);

            updateTask.Wait();

            var getTask = Database.StorageModelQueries.GetManyAsync(m => models.Keys.Contains(m.Model.Id));

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, StorageModels.Where(m => models.Keys.Contains(m.Model.Id)).ToList());
        }
コード例 #18
0
        public void Does_not_overwrite_other_records_with_custom_metadata()
        {
            Database.AddStorageModelsToDatabase(StorageModels);

            StorageModels[1].Model.Name         = "Updated name 1";
            StorageModels[1].Metadata.FirstName = "Updated first name 1";
            StorageModels[1].Metadata.LastName  = "Updated last name 1";
            StorageModels[2].Model.Name         = "Updated name 2";
            StorageModels[2].Metadata.FirstName = "Updated first name 2";
            StorageModels[2].Metadata.LastName  = "Updated last name 2";

            var models          = StorageModels.Skip(1).Take(2).ToDictionary(m => m.Model.Id, m => m);
            var addOrUpdateTask = Database.StorageModelCommands.AddOrUpdateManyAsync(models);

            addOrUpdateTask.Wait();

            var getTask = Database.StorageModelQueries.GetManyAsync(m => !models.Keys.Contains(m.Model.Id));

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, StorageModels.Where(m => !models.Keys.Contains(m.Model.Id)).ToList());
        }
コード例 #19
0
        public void Adds_when_model_does_not_exist_in_database()
        {
            Database.AddTestModelsToDatabase(TestModels);

            var newModels = new[]
            {
                new TestModel("New name 1", Guid.NewGuid()),
                new TestModel("New name 2", Guid.NewGuid())
            };

            var models = newModels.ToDictionary(m => m.Id, m => m);

            var addOrUpdateTask = Database.ModelCommands.AddOrUpdateManyAsync(models);

            addOrUpdateTask.Wait();

            var getTask = Database.ModelQueries.GetManyAsync(m => models.Keys.Contains(m.Id));

            getTask.Wait();

            var results = getTask.Result.ToList();

            AssertResults.Match(results, newModels);
        }