Beispiel #1
0
        public void NoClassToCreateObjectTest()
        {
            String    noClassLabel       = "No class: Test";
            NewObject newObjectStatement = new NewObject();

            Mock <ClassName> className = new Mock <ClassName>();
            QueryDTO         dto       = new QueryDTO
            {
                Result = new DTOQueryResult
                {
                    QueryResultType = ResultType.StringResult,
                    StringOutput    = noClassLabel
                },
                QueryClass = new Class
                {
                    ClassId = new ClassId {
                        Id = 1, Name = "Test"
                    },
                    Name = "Test"
                }
            };

            className.Setup(cn => cn.Execute(It.IsAny <QueryParameters>())).Returns(dto);
            newObjectStatement.Add(className.Object);

            QueryParameters parameters = new QueryParameters();
            var             result     = newObjectStatement.Execute(parameters);

            Assert.AreEqual(ResultType.StringResult, result.Result.QueryResultType);
            Assert.AreEqual(noClassLabel, result.Result.StringOutput);
        }
Beispiel #2
0
        public void CantCreateObjectOfInterfaceTest()
        {
            NewObject newObjectStatement = new NewObject();

            Mock <ClassName> className = new Mock <ClassName>();
            QueryDTO         dto       = new QueryDTO
            {
                QueryClass = new Class
                {
                    ClassId = new ClassId {
                        Id = 1, Name = "Test"
                    },
                    Name      = "Test",
                    Interface = true
                },
            };

            className.Setup(cn => cn.Execute(It.IsAny <QueryParameters>())).Returns(dto);
            newObjectStatement.Add(className.Object);

            QueryParameters parameters = new QueryParameters();
            var             result     = newObjectStatement.Execute(parameters);

            Assert.AreEqual(ResultType.StringResult, result.Result.QueryResultType);
            Assert.AreEqual(NewObject.cantCreateObjectLabel, result.Result.StringOutput);
        }
Beispiel #3
0
        public override IQueryElement VisitNew_object([NotNull] QueryGrammarParser.New_objectContext context)
        {
            NewObject newObject = new NewObject();

            IQueryElement className = Visit(context.class_name());

            newObject.Add(className);

            foreach (var element in context.object_initialization_attributes_list().object_initialization_element())
            {
                IQueryElement objectElement = Visit(element);
                newObject.Add(objectElement);
            }

            return(newObject);
        }
Beispiel #4
0
        public void AddNewObjectTest()
        {
            var databaseId = new Did {
                Dli = 1, Duid = 2
            };
            Property property1 = new Property {
                Type = Property.INT, PropertyId = new PropertyId {
                    Id = 1
                }
            };
            Property property2 = new Property {
                Type = Property.STRING, PropertyId = new PropertyId {
                    Id = 2
                }
            };
            var properties = new List <Property>()
            {
                property1, property2
            };
            Mock <IDatabaseParameters> database = new Mock <IDatabaseParameters>();

            database.Setup(d => d.Schema.ClassProperties(It.Is <Class>(cl => cl.ClassId.Id == 1))).Returns(properties);
            database.Setup(d => d.DatabaseId).Returns(databaseId);

            Mock <IStorage> storage = new Mock <IStorage>();
            Oid             oid     = null;

            storage.Setup(s => s.Save(It.Is <Did>(d => d == databaseId), It.Is <IStorable>(st => st.Properties.Keys.All(p => properties.Contains(p))))).Callback <Did, IStorable>((did, store) => oid = store.Oid);

            Mock <Action <String, MessageLevel> > log = new Mock <Action <string, MessageLevel> >();

            NewObject newObjectStatement = new NewObject();

            Mock <ClassName> className = new Mock <ClassName>();
            QueryDTO         dto       = new QueryDTO
            {
                QueryClass = new Class
                {
                    ClassId = new ClassId {
                        Id = 1, Name = "Test"
                    },
                    Name = "Test"
                }
            };

            className.Setup(cn => cn.Execute(It.IsAny <QueryParameters>())).Returns(dto);
            newObjectStatement.Add(className.Object);

            QueryParameters parameters = new QueryParameters {
                Database = database.Object, Storage = storage.Object, Log = log.Object
            };
            Mock <ObjectInitializationElement> element1 = new Mock <ObjectInitializationElement>();

            element1.Setup(e => e.Execute(It.Is <QueryParameters>(qp => qp == parameters))).Returns(new QueryDTO {
                Value = property1
            });
            newObjectStatement.Add(element1.Object);
            Mock <ObjectInitializationElement> element2 = new Mock <ObjectInitializationElement>();

            element2.Setup(e => e.Execute(It.Is <QueryParameters>(qp => qp == parameters))).Returns(new QueryDTO {
                Value = property2
            });
            newObjectStatement.Add(element2.Object);

            var result = newObjectStatement.Execute(parameters);

            Assert.AreEqual(ResultType.StringResult, result.Result.QueryResultType);
            Assert.AreEqual("New object saved with id: " + oid, result.Result.StringOutput);
        }