private static void InternalCanGetByIdAndThrowExceptionIfNotFound(Action <GuidIdTestEntity> insert, Func <Guid, GuidIdTestEntity> getById)
        {
            var testEntity = new GuidIdTestEntity
            {
                Id       = Guid.NewGuid(),
                SomeData = 10
            };

            insert(testEntity);
            var resultEntity = getById(testEntity.Id);

            Assert.AreEqual(resultEntity.SomeData, testEntity.SomeData);

            // Test exception throwing
            var notExistsKey = Guid.NewGuid();

            try
            {
                getById(notExistsKey);
            }
            catch (Exception e)
            {
                var argumentException = e as ArgumentException;
                if (e is AggregateException aggregateException)
                {
                    argumentException = aggregateException.InnerExceptions.First() as ArgumentException;
                }

                Assert.NotNull(argumentException);
                Assert.AreEqual($"{typeof(GuidIdTestEntity).Name} with id {notExistsKey} not found", argumentException.Message);
            }
        }
        public void CanAutofillGuidIdOnInsert()
        {
            var testEntity = new GuidIdTestEntity();

            this.guidIdRepository.Insert(testEntity);
            var resultEntity = this.guidIdRepository.Get(x => x.Id != default(Guid)).FirstOrDefault();

            Assert.NotNull(resultEntity);
        }
        public void CanInsertWithClientSideGuidId()
        {
            var testEntity = new GuidIdTestEntity
            {
                Id = Guid.NewGuid()
            };

            this.guidIdRepository.Insert(testEntity);
            var resultEntity = this.guidIdRepository.Get(x => x.Id == testEntity.Id).FirstOrDefault();

            Assert.NotNull(resultEntity);
        }
        private void InternalCanUpdateEntity(
            Action <GuidIdTestEntity> insert,
            Func <Guid, GuidIdTestEntity> getById,
            Action <Expression <Func <GuidIdTestEntity, bool> >, UpdateDefinition <GuidIdTestEntity> > update)
        {
            var testEntity = new GuidIdTestEntity
            {
                Id          = Guid.NewGuid(),
                SomeData    = 5,
                AnotherData = 10
            };

            insert(testEntity);
            var updater          = this.guidIdRepository.Updater;
            var updateDefinition = updater.Set(x => x.SomeData, 10);

            update(x => x.Id == testEntity.Id, updateDefinition);
            var resultEntity = getById(testEntity.Id);

            Assert.AreEqual(10, resultEntity.SomeData);
            Assert.AreEqual(testEntity.AnotherData, resultEntity.AnotherData);
        }
        private static void InternalCanReplaceEntity(Action <GuidIdTestEntity> insert, Func <Guid, GuidIdTestEntity> getById, Action <GuidIdTestEntity> replace)
        {
            var testEntity = new GuidIdTestEntity
            {
                Id          = Guid.NewGuid(),
                SomeData    = 10,
                AnotherData = 5
            };

            insert(testEntity);
            var replaceWith = new GuidIdTestEntity
            {
                Id          = testEntity.Id,
                SomeData    = 5,
                AnotherData = 10
            };

            replace(replaceWith);
            var resultEntity = getById(testEntity.Id);

            Assert.IsTrue(ObjectsComparer.AreEqual(replaceWith, resultEntity));
        }