コード例 #1
0
        private async Task RunDataQueryModel(CosmosDbQueryModelRepository repository, int index)
        {
            try
            {
                //var queryModelId = Guid.NewGuid();
                //var testQueryModel = new TestQueryModel(queryModelId, "Hello Integration Test!" + index);
                var testQueryModel = _fixture.Create <TestQueryModel>();
                var queryModelId   = testQueryModel.id;

                await repository.Save(testQueryModel);

                var hydratedQueryModel = await repository.GetById <TestQueryModel>(queryModelId);

                var existing = await repository.DoesItemExist <TestQueryModel>(queryModelId);

                if (!existing)
                {
                    throw new Exception("DoesItemExist");
                }
                var hydratedQueryModel1 = await repository.QueryItem <TestQueryModel>(x => x.id == queryModelId);

                Assert.IsTrue(existing);
                Assert.IsNotNull(hydratedQueryModel);
                Assert.AreEqual(queryModelId, hydratedQueryModel.id);
                Assert.AreEqual(queryModelId, hydratedQueryModel1.id);

                hydratedQueryModel.DummyPayload = "DummyPayload" + queryModelId;

                await repository.Save(hydratedQueryModel);

                await repository.DeleteById <TestQueryModel>(queryModelId);

                existing = await repository.DoesItemExist <TestQueryModel>(queryModelId);

                if (existing)
                {
                    throw new Exception("DoesItemExist");
                }
            }
            catch (TaskCanceledException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
コード例 #2
0
        public async Task ShouldSuccesfullyCreateAndHydrateQueryModel()
        {
            // ARRANGE
            var repository = new CosmosDbQueryModelRepository(_database, _collection, _offerThroughput, _noOfPartitions, _endpoint, _authKey);

            var queryModelId   = Guid.NewGuid();
            var testQueryModel = new TestQueryModel(queryModelId, "Hello Integration Test!");

            // ACT
            await repository.Save(testQueryModel);

            var hydratedQueryModel = await repository.GetById <TestQueryModel>(queryModelId);

            var existing = await repository.DoesItemExist <TestQueryModel>(queryModelId);

            // ASSERT
            Assert.IsTrue(existing);
            Assert.IsNotNull(hydratedQueryModel);
            Assert.AreEqual(queryModelId, hydratedQueryModel.id);
            Assert.AreEqual("Hello Integration Test!", testQueryModel.DummyPayload);
            Assert.AreEqual(testQueryModel.DummyPayload, hydratedQueryModel.DummyPayload);
        }