Beispiel #1
0
        public void TestCreateProperties()
        {
            //Arrange
            manager.DatabaseConnection();
            property.SetDatabase(manager.GetDatabase());
            KeyId.SetKey();             //Gerar uma chave única;
            string id = KeyId.GetKey(); //Obter a chave única gerada automaticamente;

            PropertiesModel model1 = new PropertiesModel()
            {
                ID        = id,
                Size      = 40,
                Value     = "80",
                Maxlength = 50,
                Required  = false
            };

            //PropertiesModel model2 = null; //Se não existir um modelo de dados

            //Act
            string result = property.CreateProperties(model1);

            if (Convert.ToInt32(result) == 201)
            {
                Assert.Pass("Result: Properties Model with id = " + id + ", was created with success");
            }

            if (Convert.ToInt32(result) == 400)
            {
                Assert.Pass("Result: Properties Model with id = " + id + ", was not created");
            }

            Assert.Fail();
        }
        public PropertiesModel GetProperties(string id)
        {
            if (id != null)
            {
                var collection = _Database.GetCollection <PropertiesModel>("Properties");
                return(collection.Find(s => s.ID == id).FirstOrDefault());
            }

            //É gerado um modelo de dados default;
            KeyGenerates KeyId = (new KeyGenerates(8));

            KeyId.SetKey();

            return(new PropertiesModel()
            {
                ID = KeyId.GetKey(),
                Size = 0,
                Value = null,
                Maxlength = 0,
                Required = false
            });
        }