public void test_Create_PrimaryKey_AutoIncrement()
        {
            var c = new CreateQuery
            {
                Table   = "TestTable",
                Columns =
                {
                    new Column
                    {
                        Name       = "Column1",
                        Type       = typeof(int),
                        Attributes = ColumnAttributes.PrimaryKey | ColumnAttributes.AutoIncrement
                    },
                    new Column
                    {
                        Name = "Column2",
                        Type = typeof(bool)
                    },
                    new Column
                    {
                        Name = "Column3",
                        Type = typeof(string)
                    }
                }
            };

            Assert.AreEqual("CREATE TABLE TestTable ( Column1 INTEGER PRIMARY KEY AUTOINCREMENT, Column2 INTEGER, Column3 TEXT );", c.ToString());
        }
        public void test_Create_Unique()
        {
            var c = new CreateQuery
            {
                Table   = "TestTable",
                Columns =
                {
                    new Column
                    {
                        Name       = "Column1",
                        Type       = typeof(int),
                        Attributes = ColumnAttributes.Unique
                    },
                    new Column
                    {
                        Name = "Column2",
                        Type = typeof(bool)
                    },
                    new Column
                    {
                        Name = "Column3",
                        Type = typeof(string)
                    }
                }
            };

            Assert.AreEqual("CREATE TABLE TestTable ( Column1 INTEGER UNIQUE, Column2 INTEGER, Column3 TEXT );", c.ToString());
        }
        public void CreateQueryTest(Common.Enums.FhirVersion fhirVersion, string resourceName, string resourceId)
        {
            //Setup
            var IOperationOutcomeSupportMock = IOperationOutcomeSupport_MockFactory.Get();
            var IFhirResourceNameSupportMock = IFhirResourceNameSupport_MockFactory.Get(resourceName);
            var IFhirResourceIdSupportMock   = IFhirResourceIdSupport_MockFactory.Get(resourceId);

            FhirUriFactory FhirUriFactory = GetFhirUriFactory(resourceName);

            ValidateQueryService ValidateQueryService = new ValidateQueryService(IOperationOutcomeSupportMock.Object, IFhirResourceNameSupportMock.Object, IFhirResourceIdSupportMock.Object, FhirUriFactory);

            var CreateQuery = new CreateQuery(
                HttpVerb.POST,
                fhirVersion,
                new Uri($"{TestData.BaseUrlServer}/{resourceName}"),
                new Dictionary <string, Microsoft.Extensions.Primitives.StringValues>(), //RequestQuery
                new Dictionary <string, Microsoft.Extensions.Primitives.StringValues>(), //Headers
                resourceName,
                new Common.FhirTools.FhirResource(fhirVersion));

            //Act
            bool Result = ValidateQueryService.IsValid(CreateQuery, out Common.FhirTools.FhirResource? IsNotValidOperationOutCome);

            //Assert
            Assert.True(Result);
            Assert.Null(IsNotValidOperationOutCome);
        }
        public void test_Create_PrimaryKey_NotNull()
        {
            var c = new CreateQuery
            {
                Table   = "TestTable",
                Columns =
                {
                    new Column
                    {
                        Name       = "Column1",
                        Type       = typeof(int),
                        Attributes = ColumnAttributes.NotNull
                    },
                    new Column
                    {
                        Name = "Column2",
                        Type = typeof(bool)
                    },
                    new Column
                    {
                        Name = "Column3",
                        Type = typeof(string)
                    }
                }
            };

            Assert.AreEqual("CREATE TABLE TestTable ( Column1 INTEGER NOT NULL, Column2 INTEGER, Column3 TEXT );", c.ToString());
        }
 private string GenerateCreateQuery(CreateQuery createQuery)
 {
     return($@"{{ ""settings"": {{ 
         ""number_of_shards"": {createQuery.NumberOfShards}, 
         ""number_of_replicas"": {createQuery.NumberOfReplicas},
         ""{createQuery.TypeName}"": {{ ""_all"": {EscapeValue(createQuery.AllFieldEnabled)}, 
         {string.Join(",", createQuery.Mapping.Select(m => $@"""{m.Name}"" : {{ 
             ""type"": ""{m.FieldDataType.Name}"" 
             {(m.Analyzer != null ? $@",""analyzer"": ""{m.Analyzer.Name}""" : "")} }}"))} }} }} }}");
 }
Exemple #6
0
        public void TestGenerateCreateNoWhere()
        {
            var         schemeName    = TestingTools.RandomString;
            var         tableName     = TestingTools.RandomString;
            var         propertyName  = TestingTools.RandomString;
            var         propertyValue = TestingTools.RandomString;
            CreateQuery query         = new CreateQuery(schemeName, tableName);

            query.AddPropertyValue(propertyName, propertyValue);

            var result = query.Build();

            var expected = String.Format("INSERT INTO \"{0}\".\"{1}\"(\"{2}\") VALUES('{3}') RETURNING \"{0}\".\"{1}\".\"ID\"; ",
                                         schemeName, tableName, propertyName, propertyValue);

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result);
        }
Exemple #7
0
        public void UpdateConnection(DMSource DataObject, ConnectionDataMap connection, int id)
        {
            CreateQuery query = new CreateQuery(connection.SchemaName, connection.TableName);

            query.AddPropertyValue(connection.ParentID, DataObject.ID);
            query.AddPropertyValue(connection.ChildID, id);

            var cmd = db.GetCommand(query.Build());

            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    DataObject.AddConnection(connection.DataType, id, Convert.ToInt32(reader.GetString(0)));
                    return;
                }
            }
        }
Exemple #8
0
        public void CreateObject(DMSource DataObject)
        {
            CreateQuery query = new CreateQuery(TABLE.SchemaName, TABLE.TableName);

            foreach (var entry in DATA_MAP.DataColumns)
            {
                query.AddPropertyValue(entry.Key.ColumnName, entry.Value.GetValue(DataObject));
            }

            var cmd = db.GetCommand(query.Build());

            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    DataObject.ID = Convert.ToInt32(reader.GetString(0));
                    return;
                }
            }
        }
Exemple #9
0
        public ActionResult Create(CreateQuery query)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToAction("Index"));
            }

            var centro = SesionUsuario.Centro;

            if (string.IsNullOrEmpty(query.Aula) || centro.ListaAulas.Length == 0 || !centro.ListaAulas.Contains(query.Aula))
            {
                ViewBag.MensajeError = "Aula no válida.";
            }
            else if (string.IsNullOrWhiteSpace(query.Asunto))
            {
                ViewBag.MensajeError = "Asunto no puede estar vacio.";
            }
            else
            {
                Incidencia incidencia = new Incidencia()
                {
                    Timestamp  = DateTime.UtcNow,
                    Asunto     = query.Asunto,
                    Comentario = query.Comentario,
                    Aula       = query.Aula,
                    Equipo     = query.Equipo,
                    Cerrada    = false,
                    CentroId   = centro.IdCentro
                };
                contexto.Incidencias.Add(incidencia);
                contexto.SaveChanges();
                ViewBag.MensajeOk = "La incidendia ha sido enviada correctamente.";
            }

            return(Create());
        }
Exemple #10
0
 public void Setup()
 {
     CreateQuery = new CreateQuery();
 }
Exemple #11
0
 public async Task <IActionResult> Create([FromBody] CreateQuery query)
 {
     query.UserId = UserId;
     return(new OkObjectResult(await mediator.Send(query)));
 }