Exemplo n.º 1
0
        public void HasProperty_should_pass_constant_expressions()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            Assert.DoesNotThrow(()
                                => entityProfile.HasProperty <TestEntity, int>("id", x => 10));
        }
Exemplo n.º 2
0
        public DataResponse <EntityProfile> GetUserDeviceIdById(int UserId)
        {
            DataResponse <EntityProfile> response = new DataResponse <EntityProfile>();

            try
            {
                base.DBInit();

                var query  = DBEntity.UserProfiles.Where(a => a.UserId == UserId).FirstOrDefault();
                var entity = new EntityProfile
                {
                    Id       = query.UserId.Value,
                    DeviceId = query.DeviceId
                };

                if (query != null)
                {
                    response.CreateResponse(entity, DataResponseStatus.OK);
                }
                else
                {
                    response.CreateResponse(DataResponseStatus.InternalServerError);
                }
            }
            catch (Exception ex)
            {
                response.ThrowError(ex);
            }

            finally
            {
                base.DBClose();
            }
            return(response);
        }
Exemplo n.º 3
0
        public void HasProperty_should_pass_binary_expressions()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            Assert.DoesNotThrow(() => entityProfile.HasProperty <TestEntity, int>("id", x => x.Id + x.IntValue));
            Assert.DoesNotThrow(() => entityProfile.HasProperty <TestEntity, int>("value", x => x.Id + 10));
        }
        public void Should_build_params_for_string_id()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.IntValue);
            entityProfile.HasProperty <TestEntity, string>(x => x.RecordId)
            .ThatIsPrivateKey();
            var elements = new List <TestEntity>
            {
                new TestEntity {
                    IntValue = 12, RecordId = "rec-01", SensorId = "sen-0"
                },
                new TestEntity {
                    IntValue = 13, RecordId = "rec-02", SensorId = "sen-1"
                }
            };
            var result = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(result);
            var commandResult = result.FirstOrDefault();

            Assert.NotNull(commandResult);
            Assert.NotNull(commandResult.SqlParameters);
            Assert.AreEqual(2, commandResult.SqlParameters.Count);

            Assert.IsTrue(Regex.IsMatch(commandResult.Command, DELETE_PARAM_PATTERN, RegexOptions.IgnoreCase));
        }
Exemplo n.º 5
0
        public void Should_not_put_constraint_columns_into_update_set_clause()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.Id)
            .ThatIsPrivateKey();
            entityProfile.HasPropertyAsPartOfUniqueConstraint <TestEntity, string>(x => x.RecordId);
            entityProfile.HasUniqueConstraint("business_identity");

            entityProfile.HasProperty <TestEntity, string>(x => x.SensorId);
            entityProfile.ToTable("test_entity", "custom");

            var elements = new List <TestEntity>
            {
                new TestEntity {
                    Id = 12, RecordId = "rec-01", SensorId = "sens-01", IntValue = 127
                },
            };
            var commands = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(commands);
            Assert.AreEqual(1, commands.Count);
            var commandResult = commands.First();

            Assert.NotNull(commandResult.Command);

            var upsertSetPattern = "(set\\s+\"record_id\"\\s*=\\s*(\"\\w+\".)?\"\\w+\".\"\\w+\"\\s*)|,\\s*\"record_id\"\\s*=";

            Assert.IsFalse(Regex.IsMatch(commandResult.Command, upsertSetPattern, RegexOptions.IgnoreCase));
        }
Exemplo n.º 6
0
        private static bool IsKeepProfile(EntityProfile dataFilter, bool isCleanProfiles)
        {
            var isIncluded = dataFilter.IsIncluded;

            if (isCleanProfiles && !isIncluded)
            {
                return(false);
            }

            var isEntityRenameFilled      = dataFilter.EntityRename.IsFilled();
            var isEntityAnnotationsFilled = dataFilter.EntityAnnotations.IsFilled();
            var isIsGenerateMetaFilled    = dataFilter.IsGenerateMeta;
            var isIsOptionsetLabelsFilled = dataFilter.IsOptionsetLabels;
            var isIsLookupLabelsFilled    = dataFilter.IsLookupLabels;
            var isValueClearModeFilled    = dataFilter.ValueClearMode != null;
            var isEnglishLabelFieldFilled = dataFilter.EnglishLabelField.IsFilled();
            var isCollectionsFilled       = dataFilter.IsBasicDataFilled;

            var isKeepFilter = isIncluded || isEntityRenameFilled || isEntityAnnotationsFilled || isIsGenerateMetaFilled ||
                               isIsOptionsetLabelsFilled || isIsLookupLabelsFilled ||
                               isValueClearModeFilled || isEnglishLabelFieldFilled ||
                               isCollectionsFilled;

            return(isKeepFilter);
        }
        public void Should_build_correct_id_property_name()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.IntValue);
            entityProfile.HasProperty <TestEntity, string>(x => x.RecordId)
            .ThatIsPrivateKey();
            var elements = new List <TestEntity>
            {
                new TestEntity {
                    IntValue = 12, RecordId = "rec-01", SensorId = "sen-0"
                },
                new TestEntity {
                    IntValue = 13, RecordId = "rec-02", SensorId = "sen-1"
                }
            };
            var result = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(result);
            var commandResult = result.FirstOrDefault();

            Assert.NotNull(commandResult);

            Assert.IsTrue(commandResult.Command.Contains("where \"record_id\" in"));
        }
Exemplo n.º 8
0
 public void NPCFactoryCreate()
 {
     ItemsFactory wfactory        = new ItemsFactory();
     NPCFactory   factory         = new NPCFactory(wfactory);
     var          creationProfile = new EntityProfile(10, EntityOccupation.Fisherman, EntityRace.None, 10);
     IEntity      entity          = factory.Create(creationProfile);
 }
        public void Should_match_insert_cmd_without_returning_clause()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.Id)
            .ThatIsPrivateKey();
            entityProfile.HasPropertyAsPartOfUniqueConstraint <TestEntity, string>(x => x.RecordId);
            entityProfile.HasUniqueConstraint("business_identity");

            entityProfile.HasProperty <TestEntity, string>(x => x.SensorId);
            entityProfile.ToTable("test_entity", "custom");

            var elements = new List <TestEntity>
            {
                new TestEntity {
                    Id = 12, RecordId = "rec-01", SensorId = "sens-01", IntValue = 127
                },
            };
            var commands = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(commands);
            Assert.AreEqual(1, commands.Count);
            var commandResult = commands.First();

            Assert.NotNull(commandResult.Command);

            // Check that the whole command still matches the upsert pattern
            Assert.IsTrue(Regex.IsMatch(commandResult.Command, UpsertConsts.UPSERT_PATTERN, RegexOptions.IgnoreCase));

            // Check that there is no returning clause in the result command
            Assert.IsFalse(commandResult.Command.Contains("returning"));
        }
Exemplo n.º 10
0
        public void Should_match_upsert_cmd_of_one_element()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(entity => entity.Id)
            .ThatIsAutoGenerated()
            .ThatIsPrivateKey();
            entityProfile.HasPropertyAsPartOfUniqueConstraint <TestEntity, string>(entity => entity.RecordId);
            entityProfile.HasPropertyAsPartOfUniqueConstraint <TestEntity, string>(entity => entity.SensorId);
            entityProfile.HasProperty <TestEntity, int>(entity => entity.IntValue);

            var elements = new List <TestEntity>
            {
                new TestEntity {
                    RecordId = "rec-01", SensorId = "sens-01", IntValue = 127
                },
            };
            var commands = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(commands);
            Assert.AreEqual(1, commands.Count);
            var commandResult = commands.First();

            Assert.NotNull(commandResult.Command);

            Assert.IsTrue(Regex.IsMatch(commandResult.Command, UpsertConsts.UPSERT_PATTERN, RegexOptions.IgnoreCase));
        }
Exemplo n.º 11
0
        public void HasProperty_should_not_pass_constant_expressions_without_column()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));
            var ex            = Assert.Throws <ArgumentException>(() => entityProfile.HasProperty <TestEntity, int>(x => 10));

            Assert.AreEqual("column", ex.ParamName);
        }
        public void Should_set_date_column_types()
        {
            var entityProfile   = new EntityProfile(typeof(EntityWithDateTime));
            var propertyProfile = entityProfile.HasProperty <EntityWithDateTime, Date>(x => x.Date);

            Assert.AreEqual(NpgsqlDbType.Date, propertyProfile.DbColumnType);
        }
        public void Should_return_true_given_nullable_double_member()
        {
            var entityProfile = new EntityProfile(typeof(EntityWithNullableProperty));
            var propInfo      = entityProfile.HasProperty <EntityWithNullableProperty, double?>(entity => entity.NullableDouble);

            Assert.IsFalse(propInfo.IsDynamicallyInvoked());
        }
Exemplo n.º 14
0
        public async Task SetUp()
        {
            _entityProfile = new UpsertEntityProfile(1);
            var truncateTableCmd   = $"truncate {_entityProfile.TableName};";
            var resetIdSequenceCmd = "ALTER SEQUENCE \"unit_tests\".\"entity_with_unique_columns_id_seq\" RESTART WITH 1;";

            using (var connection = new NpgsqlConnection(_configuration.ConnectionString))
                using (var command = new NpgsqlCommand($"{truncateTableCmd}{resetIdSequenceCmd}", connection))
                {
                    await connection.OpenAsync();

                    await command.ExecuteNonQueryAsync();
                }

            var bulkServiceOptions = new BulkServiceOptions
            {
                FailureStrategy = FailureStrategies.StopEverything
            };

            bulkServiceOptions.AddEntityProfile <TestEntity>(_entityProfile);

            var insertCommandBuilder = new InsertSqlCommandBuilder(NullLoggerFactory.Instance);
            var deleteCommandBuilder = new SimpleDeleteSqlCommandBuilder(NullLoggerFactory.Instance);
            var updateCommandBuilder = new UpdateSqlCommandBuilder(NullLoggerFactory.Instance);
            var upsertCommandBuilder = new UpsertSqlCommandBuilder(NullLoggerFactory.Instance);

            _testService = new NpgsqlCommandsBulkService(
                bulkServiceOptions,
                NullLoggerFactory.Instance,
                insertCommandBuilder,
                updateCommandBuilder,
                deleteCommandBuilder,
                upsertCommandBuilder);
        }
Exemplo n.º 15
0
        public ModelViewProfile Insert(ModelViewProfile model)
        {
            var objRepository = new RepositoryProfile();

            model.Status = true;
            if (objRepository.GetAll().Where(p => p.Profile.ToUpper() == model.Profile.ToUpper()) != null)
            {
                throw new Exception("Duplicate");
            }

            EntityProfile data = new EntityProfile()
            {
                ProfileID   = model.ProfileID,
                Profile     = model.Profile,
                Description = model.Description,
                Status      = model.Status
            };



            data            = new RepositoryProfile().Insert(data);
            model.ProfileID = data.ProfileID;

            new BusinessPermission().Set(model.ProfileID, null);

            return(model);
        }
        public void Should_return_two_parameters_for_id_and_value()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.Id)
            .ThatIsPrivateKey();
            entityProfile.HasProperty <TestEntity, int>(x => x.IntValue)
            .ThatIsPrivateKey();

            var elements = new List <TestEntity>
            {
                new TestEntity {
                    Id = 10, RecordId = "rec-01", SensorId = "sens-02", IntValue = 12
                }
            };
            var commands = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(commands);
            Assert.AreEqual(1, commands.Count);
            var commandResult = commands.First();

            Assert.NotNull(commandResult.Command);
            Assert.NotNull(commandResult.SqlParameters);

            Assert.AreEqual(0, commandResult.SqlParameters.Count);
        }
Exemplo n.º 17
0
        public void Should_match_constraint_name_in_on_conflict_clause()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.Id)
            .ThatIsPrivateKey();
            entityProfile.HasPropertyAsPartOfUniqueConstraint <TestEntity, string>(x => x.RecordId);
            entityProfile.HasUniqueConstraint("business_identity");

            entityProfile.HasProperty <TestEntity, string>(x => x.SensorId);
            entityProfile.ToTable("test_entity", "custom");

            var elements = new List <TestEntity>
            {
                new TestEntity {
                    Id = 12, RecordId = "rec-01", SensorId = "sens-01", IntValue = 127
                },
            };
            var commands = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(commands);
            Assert.AreEqual(1, commands.Count);
            var commandResult = commands.First();

            Assert.NotNull(commandResult.Command);

            var onConflictClausePattern = "on\\s+conflict\\s+(\\(\\s*\"\\w+\"\\s*\\)|on\\s+constraint\\s+\"\\w+\")";

            Assert.IsTrue(Regex.IsMatch(commandResult.Command, onConflictClausePattern, RegexOptions.IgnoreCase));
        }
        public void Should_return_true_given_double_member()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));
            var propInfo      = entityProfile.HasProperty <TestEntity, double>(entity => entity.DoubleValue);

            Assert.IsFalse(propInfo.IsDynamicallyInvoked());
        }
        public void Should_return_true_given_string_member()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));
            var propInfo      = entityProfile.HasProperty <TestEntity, string>(entity => entity.RecordId);

            Assert.IsTrue(propInfo.IsDynamicallyInvoked());
        }
        public void Should_return_true_given_date_member()
        {
            var entityProfile = new EntityProfile(typeof(EntityWithDateTime));
            var propInfo      = entityProfile.HasProperty <EntityWithDateTime, Date>("date", entity => entity.Date);

            Assert.IsTrue(propInfo.IsDynamicallyInvoked());
        }
        public void Should_return_true_given_simple_enum_member()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));
            var propInfo      = entityProfile.HasProperty <TestEntity, SomeEnum>(entity => entity.Enumeration);

            Assert.IsFalse(propInfo.IsDynamicallyInvoked());
        }
        public void Should_return_true_given_converted_enum()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));
            var propInfo      = entityProfile.HasProperty <TestEntity, int?>(entity => (int?)entity.Enumeration);

            Assert.IsTrue(propInfo.IsDynamicallyInvoked());
        }
        public void Should_match_delete_cmd_without_returning_clause()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.Id)
            .ThatIsPrivateKey();
            entityProfile.HasProperty <TestEntity, string>(x => x.RecordId);
            entityProfile.HasProperty <TestEntity, string>(x => x.SensorId);
            entityProfile.ToTable("test_entity", "custom");

            var elements = new List <TestEntity>
            {
                new TestEntity {
                    Id = 12, RecordId = "rec-01", SensorId = "sens-01", IntValue = 127
                },
            };
            var commands = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(commands);
            Assert.AreEqual(1, commands.Count);
            var commandResult = commands.First();

            Assert.NotNull(commandResult.Command);

            Assert.IsTrue(Regex.IsMatch(commandResult.Command, DELETE_PATTERN, RegexOptions.IgnoreCase));
        }
Exemplo n.º 24
0
        public void HasProperty_should_pass_nullable_properties()
        {
            var entityProfile = new EntityProfile(typeof(EntityWithNullableProperty));

            Assert.DoesNotThrow(() => entityProfile.HasProperty <EntityWithNullableProperty, bool?>
                                    ("value", x => x.NullableBool));
        }
        public void Should_put_all_private_keys_into_where_clause()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.Id)
            .ThatIsPrivateKey();
            entityProfile.HasProperty <TestEntity, string>(x => x.RecordId)
            .ThatIsPrivateKey();
            var elements = new List <TestEntity>
            {
                new TestEntity {
                    Id = 12, RecordId = "rec-01", SensorId = "sen-0"
                }
            };
            var commands = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(commands);
            Assert.AreEqual(1, commands.Count);
            var commandResult = commands.First();

            Assert.NotNull(commandResult.Command);

            // pattern should match "id" whatever builder put the "id" column in any order where "id" = @param1;  or where ""value"=@param1, "id"=@param2;
            var pattern = "where\\s+(\"id\"\\s*=\\s*\\d+|\\s*\"record_id\"\\s*=\\s*@param_record_id_\\d+)\\s*(and\\s*\"id\"\\s*=\\s*\\d+|\\s+and\\s*\"record_id\"\\s*=\\s*@param_record_id_\\d+)";

            Assert.IsTrue(Regex.IsMatch(commandResult.Command, pattern, RegexOptions.IgnoreCase));
        }
        public void Should_not_include_after_insert_columns_into_update_returning_clause()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.Id)
            .ThatIsPrivateKey()
            .MustBeUpdatedAfterInsert();
            var elements = new List <TestEntity>
            {
                new TestEntity {
                    RecordId = "rec-01"
                }
            };
            var commands = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(commands);
            Assert.AreEqual(1, commands.Count);
            var commandResult = commands.First();

            Assert.NotNull(commandResult.Command);

            // pattern should match "id" whatever builder put the "id" column returning "id";  or returning ""value", "id";
            var pattern = @"returning\s+(""\w+""\s*,\s*)*""id""";

            Assert.IsFalse(Regex.IsMatch(commandResult.Command, pattern, RegexOptions.IgnoreCase));
        }
        public void Should_not_put_column_that_was_not_mapped()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.Id)
            .ThatIsPrivateKey();
            entityProfile.HasProperty <TestEntity, string>(x => x.RecordId);
            entityProfile.ToTable("test_entity", "custom");

            var elements = new List <TestEntity>
            {
                new TestEntity {
                    Id = 12, RecordId = "rec-01", SensorId = "sens-01", IntValue = 127
                },
            };
            var commands = _testService.Generate(elements, entityProfile, CancellationToken.None);

            Assert.NotNull(commands);
            Assert.AreEqual(1, commands.Count);
            var commandResult = commands.First();

            Assert.NotNull(commandResult.Command);

            Assert.IsFalse(commandResult.Command.Contains("sensor_id"));
        }
Exemplo n.º 28
0
        public void HasProperty_should_not_pass_duplicates()
        {
            var i             = Math.Round((decimal)5 / 2, MidpointRounding.ToPositiveInfinity);
            var entityProfile = new EntityProfile(typeof(TestEntity));

            Assert.DoesNotThrow(() => entityProfile.HasProperty <TestEntity, int>(x => x.Id));
            Assert.Throws <TypeMappingException>(() => entityProfile.HasProperty <TestEntity, int>(x => x.Id));
        }
        public void Should_throw_exception_for_empty_elements()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.Id).ThatIsPrivateKey();
            entityProfile.ToTable("test_entity", "custom");
            var elements = new List <TestEntity>();

            Assert.Throws <ArgumentException>(() => _testService.Generate(elements, entityProfile, CancellationToken.None));
        }
        public void Upsert_should_not_pass_entities_without_unique_constraint()
        {
            var entityProfile = new EntityProfile(typeof(TestEntity));

            entityProfile.HasProperty <TestEntity, int>(x => x.Id);
            entityProfile.ToTable("test_entity", "custom");
            var elements = new List <TestEntity>();

            Assert.Throws <ArgumentException>(() => _testService.Generate(elements, entityProfile, CancellationToken.None));
        }