Exemplo n.º 1
0
        public void TestInsertUpdateAndGetCicle()
        {
            CicleBL cicleBL = new CicleBL(connectionString);
            Cicle   cicle   = CicleHelper.CreateDummyCicle();

            cicle = cicleBL.InsertCicle(cicle);
            Assert.IsTrue(cicle.Id > 0);
            //Test get by Id
            List <Cicle> savedCicles = cicleBL.GetCicle(cicle.Id);

            Assert.IsTrue(savedCicles.Count() == 1);
            Cicle savedCicle = savedCicles[0];

            Assert.IsTrue(savedCicle.Id == cicle.Id); //Todo create custom validator to check all properties
            //Test get all
            savedCicles = cicleBL.GetCicle();
            savedCicle  = (from ticket in savedCicles where ticket.Id == savedCicle.Id select ticket).FirstOrDefault();
            Assert.IsTrue(savedCicle != null);
            //Test update
            cicle.Name   = "cicleUpdated";
            cicle.Closed = true; //Todo check other properties
            cicle        = cicleBL.UpdateCicle(cicle);
            savedCicles  = cicleBL.GetCicle(cicle.Id);
            Assert.IsTrue(savedCicles != null && savedCicles.Count() == 1);
            savedCicle = savedCicles[0];
            Assert.IsTrue(savedCicle.Name == "cicleUpdated");
            Assert.IsTrue(savedCicle.Closed);
            //Test delete
            bool result = cicleBL.DeleteCicle(savedCicle.Id);

            Assert.IsTrue(result);
            savedCicles = cicleBL.GetCicle(cicle.Id);
            Assert.IsTrue(savedCicles.Count() == 0);
        }
Exemplo n.º 2
0
        public Cicle UpdateCicle(Cicle cicle)
        {
            CicleError result = CicleError.None;

            if (string.IsNullOrEmpty(cicle.Name))
            {
                result |= CicleError.InvalidName;
            }
            if (cicle.StartDate == System.DateTime.MinValue || cicle.StartDate == System.DateTime.MaxValue)
            {
                result |= CicleError.InvalidStartDate;
            }
            if (cicle.EndDateZone1 == System.DateTime.MinValue || cicle.EndDateZone1 == System.DateTime.MaxValue)
            {
                result |= CicleError.InvalidDateZone1;
            }
            if (cicle.EndDateZone2 == System.DateTime.MinValue || cicle.EndDateZone2 == System.DateTime.MaxValue)
            {
                result |= CicleError.InvalidDateZone2;
            }
            if (cicle.AmountPerHectarea <= 0)
            {
                result |= CicleError.InvalidAmount;
            }
            if (result != CicleError.None)
            {
                throw new CicleException(result);
            }
            else
            {
                return(cicleDL.UpdateCicle(cicle));
            }
        }
Exemplo n.º 3
0
        public void TestInsertUpdateErrors()
        {
            CicleBL cicleBL = new CicleBL(connectionString);
            Cicle   cicle   = new Cicle();

            try
            {
                cicleBL.InsertCicle(cicle);
            }
            catch (CicleException exception)
            {
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidAmount));
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidDateZone1));
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidDateZone2));
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidIsClosed));
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidStartDate));
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidName));
            }
            try
            {
                cicleBL.UpdateCicle(cicle);
            }
            catch (CicleException exception)
            {
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidAmount));
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidDateZone1));
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidDateZone2));
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidIsClosed));
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidStartDate));
                Assert.IsTrue(exception.Error.HasFlag(CicleError.InvalidName));
            }
        }
Exemplo n.º 4
0
        public IHttpActionResult Add(Cicle cicle)
        {
            CicleResponse response = new CicleResponse();

            try
            {
                //cicle.UserId = CurrentUserId;
                Cicle cicleSaved = cicleBL.InsertCicle(cicle);
                response.Cicle   = cicleSaved;
                response.Success = true;
            }
            catch (CicleException ex)
            {
                response.ErrorCode    = ex.Error;
                response.ErrorMessage = "Error. " + ex.Error.ToString();
                response.Cicle        = null;
                response.Success      = false;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = "Error. " + ex.Message;
                response.Cicle        = null;
                response.Success      = false;
            }
            return(Ok(response));
        }
Exemplo n.º 5
0
        public IHttpActionResult Update(Cicle cicle)
        {
            CicleResponse response = new CicleResponse();

            try
            {
                Cicle cicleSaved = cicleBL.UpdateCicle(cicle);
                response.Cicle   = cicleSaved;
                response.Success = true;
            }
            catch (CicleException ex)
            {
                response.ErrorCode    = ex.Error;
                response.ErrorMessage = "Error. " + ex.Error.ToString();
                response.Cicle        = null;
                response.Success      = false;
            }
            catch (Exception ex)
            {
                response.ErrorMessage = "Error. " + ex.Message;
                response.Cicle        = null;
                response.Success      = false;
            }
            return(Ok(response));
        }
Exemplo n.º 6
0
 public CicleList()
 {
     InitializeComponent();
     presenter    = new CiclePresenter(this);
     CurrentCicle = new Cicle();
     GridCicleDetails.DataContext = CurrentCicle;
 }
Exemplo n.º 7
0
 private void Start()
 {
     _collider             = GetComponent <BoxCollider2D>();
     _spriteRenderer       = GetComponent <SpriteRenderer>();
     _spriteRenderer.color = _colorOn;
     _selfCicle            = Cicle.Dicrement;
     _changingStep         = (_colorOn - _colorOff) / _cicleTime;
 }
Exemplo n.º 8
0
        public static Cicle CreateDummyCicle()
        {
            Cicle cicle = new Cicle();

            cicle.AmountPerHectarea = 5;
            cicle.Closed            = false;
            cicle.EndDateZone1      = DateTime.Now;
            cicle.EndDateZone2      = DateTime.Now;
            cicle.Name      = "TestCicle";
            cicle.StartDate = DateTime.Now;
            return(cicle);
        }
Exemplo n.º 9
0
    private Color GetChangedColor(Color color, Color step)
    {
        Color changedColor = color + step * Time.deltaTime;

        if (changedColor.r < _colorOff.r)
        {
            _selfCicle = Cicle.Increment;
            return(_colorOff);
        }
        else if (changedColor.r > _colorOn.r)
        {
            _selfCicle = Cicle.Dicrement;
            return(_colorOn);
        }
        else
        {
            return(changedColor);
        }
    }
Exemplo n.º 10
0
        public void TestInsertUpdateErrors()
        {
            Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3");
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            //Test insert
            Cicle  cicle      = new Cicle();
            string jsonTicket = javaScriptSerializer.Serialize(cicle);
            //Post add ticket
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(baseUrl);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token);
            //Test insert
            HttpResponseMessage response = client.PostAsJsonAsync(insertAction, cicle).Result;

            Assert.IsTrue(response.IsSuccessStatusCode);
            CicleResponse cicleResponse = response.Content.ReadAsAsync <CicleResponse>().Result;

            Assert.IsFalse(cicleResponse.Success);
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidAmount));
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidDateZone1));
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidDateZone2));
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidIsClosed));
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidStartDate));
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidName));


            //Test update
            response = client.PostAsJsonAsync(updateAction, cicle).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            cicleResponse = response.Content.ReadAsAsync <CicleResponse>().Result;
            Assert.IsFalse(cicleResponse.Success);
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidAmount));
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidDateZone1));
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidDateZone2));
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidIsClosed));
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidStartDate));
            Assert.IsTrue(cicleResponse.ErrorCode.HasFlag(CicleError.InvalidName));
        }
Exemplo n.º 11
0
 public Cicle UpdateCicle(Cicle cicle)
 {
     using (SqlCommand command = new SqlCommand())
     {
         using (SqlConnection connection = new SqlConnection())
         {
             connection.ConnectionString = ConnectionString;
             command.Connection          = connection;
             command.CommandText         = "spUpsertCicle";
             command.CommandType         = CommandType.StoredProcedure;
             foreach (PropertyInfo prop in (from x in cicle.GetType().GetProperties() where !excludedPropertiesInUpdate.Contains(x.Name) select x).ToArray())
             {
                 command.Parameters.AddWithValue("@" + prop.Name, prop.GetValue(cicle));
             }
             connection.Open();
             object cicleId = command.ExecuteScalar();
             cicle.Id = int.Parse(cicleId.ToString());
             connection.Close();
         }
         return(cicle);
     }
 }
Exemplo n.º 12
0
 private void Work(Cicle cicle)
 {
     _spriteRenderer.color = GetChangedColor(_spriteRenderer.color, _changingStep * (int)cicle);
     _collider.enabled     = IsHalfColor();
 }
Exemplo n.º 13
0
        public void RaiseToPowerTest(int a, int b, int expected)
        {
            int actual = Cicle.RaiseToPower(a, b);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 14
0
    void Awake()
    {
        terrain = GameObject.FindGameObjectWithTag("Terrain").GetComponent <Terrain>();
        var length = terrain.terrainData.heightmapResolution;
        var height = terrain.terrainData.heightmapHeight;

        //heightMapGenerator = new GenerateHeightMap(length, length);

        SetTextures();

        var regions = new List <RegionBase>()
        {
            new Desert(length, height, Corners.TopRight), new Mountains(length, height, Corners.TopLeft), new Desert(length, height, Corners.BottomLeft), new Desert(length, height, Corners.BottomRight)
        };

        var map = new float[length, length];



        if (useSingleMap)
        {
            var currentMap = regions.First((r) => r.Corner == Corners.TopLeft).GetMap();
            Copy(RotateArrayRight(RotateArrayRight(currentMap)), ref map, Corners.TopRight);
            Copy(RotateArrayLeft(currentMap), ref map, Corners.TopLeft);
            Copy(RotateArrayRight(currentMap), ref map, Corners.BottomRight);
            Copy(currentMap, ref map, Corners.BottomLeft);
        }
        else
        {
            foreach (var r in regions)
            {
                var currentMap = r.GetMap();
                switch (r.Corner)
                {
                case Corners.BottomLeft:
                    Copy(currentMap, ref map, Corners.BottomLeft);
                    break;

                case Corners.BottomRight:
                    Copy(RotateArrayRight(currentMap), ref map, Corners.BottomRight);
                    break;

                case Corners.TopLeft:
                    Copy(RotateArrayLeft(currentMap), ref map, Corners.TopLeft);
                    break;

                default:
                    Copy(RotateArrayRight(RotateArrayRight(currentMap)), ref map, Corners.TopRight);
                    break;
                }
            }
        }


        terrain.terrainData.SetHeights(0, 0, map);

        //TopLeft


        Grasslands = new Cicle(2 * (regions.First().GrassLandsRadius / terrain.terrainData.heightmapResolution) * terrain.terrainData.size.x, new Vector2(terrain.terrainData.size.x * .5f, terrain.terrainData.size.z * .5f));

        var mapAlignment = new Dictionary <Corners, Regions>();

        foreach (var r in regions)
        {
            mapAlignment.Add(r.Corner, (Regions)Enum.Parse(typeof(Regions), r.GetType().Name.ToString()));
        }

        var manager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <Manager>();

        manager.MapAlignment = mapAlignment;

        var maxHeight = -1f;

        for (int j = 0; j < map.GetLength(1); j++)
        {
            for (int i = 0; i < map.GetLength(0); i++)
            {
                if (map[j, i] > maxHeight)
                {
                    maxHeight = map[j, i];
                }
            }
        }

        var terrainMap = regions.First().GetTerrainMap(terrain.terrainData);

        regions.First().SetGrasslands(ref terrainMap);
        foreach (var region in regions)
        {
            region.AssignTextures(mapAlignment.Keys.First(k => mapAlignment[k] == region.Region), ref terrainMap);
        }

        terrain.terrainData.SetAlphamaps(0, 0, terrainMap);
    }
Exemplo n.º 15
0
        public void CompareByNumbersTest(int A, int B, string expected)
        {
            string actual = Cicle.CompareByNumbers(A, B);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 16
0
 public void ShowAllNumbersFissileOnATest(int a, int[] expected)
 {
     int[] actual = Cicle.ShowAllNumbersFissileOnA(a);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 17
0
        public void ShowCountNumberSquareBiggerATest(int a, int expected)
        {
            int actual = Cicle.ShowCountNumberSquareBiggerA(a);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 18
0
        public void ShowShowGreatestDivisorTest(int a, int expected)
        {
            int actual = Cicle.ShowGreatestDivisor(a);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 19
0
        public void SumNumbersABDividedBy7Test(int a, int b, int expected)
        {
            int actual = Cicle.SumNumbersABDividedBy7(a, b);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 20
0
        public void ShowNumberSeriesFibonacciTest(int a, int expected)
        {
            int actual = Cicle.ShowNumberSeriesFibonacci(a);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 21
0
        public void ShowCountSumEvenGreatestObbTest(int A, int expected)
        {
            int actual = Cicle.ShowCountSumEvenGreatestObb(A);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 22
0
        public void FindGCDTest(int a, int b, int expected)
        {
            int actual = Cicle.FindGCD(a, b);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 23
0
        public void FindNumberFromCubeWithHalfDivisionTest(int a, int expected)
        {
            int actual = Cicle.FindNumberFromCubeWithHalfDivision(a);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 24
0
        public void TestInsertUpdateAndGetCicle()
        {
            //Get token
            Token token = TokenHelper.GetToken(baseUrl, "Melvin3", "MelvinPass3");
            JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
            //Test insert
            Cicle  cicle      = CicleHelper.CreateDummyCicle();
            string jsonTicket = javaScriptSerializer.Serialize(cicle);
            //Post add ticket
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(baseUrl);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token);
            HttpResponseMessage response = client.PostAsJsonAsync(insertAction, cicle).Result;

            Assert.IsTrue(response.IsSuccessStatusCode);
            CicleResponse cicleResponse = response.Content.ReadAsAsync <CicleResponse>().Result;

            Assert.IsTrue(cicleResponse.Success);
            Assert.IsTrue(cicleResponse != null);
            Assert.IsTrue(cicleResponse.Cicle.Id > 0);
            //get by id
            string getByIdUrl = string.Format("{0}?id={1}", getByIdAction, cicleResponse.Cicle.Id.ToString());

            response = client.GetAsync(getByIdUrl).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            GetCicleResponse getCicleResponse = response.Content.ReadAsAsync <GetCicleResponse>().Result;

            Assert.IsTrue(getCicleResponse.Success);
            Assert.IsTrue(getCicleResponse.Cicles.Count == 1);
            Assert.IsTrue(getCicleResponse.Cicles.ElementAt(0).Id == cicleResponse.Cicle.Id);
            //get all
            response = client.GetAsync(getAllAction).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            getCicleResponse = response.Content.ReadAsAsync <GetCicleResponse>().Result;
            Assert.IsTrue(getCicleResponse.Success);
            Cicle cicleFound = (from aCicle in getCicleResponse.Cicles where aCicle.Id == cicleResponse.Cicle.Id select aCicle).FirstOrDefault();

            Assert.IsTrue(cicleFound != null);
            //test update
            cicle.Id   = cicleResponse.Cicle.Id;
            cicle.Name = "CicleNameUpdated";
            cicle.AmountPerHectarea = 2;
            response = client.PostAsJsonAsync(updateAction, cicle).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            cicleResponse = response.Content.ReadAsAsync <CicleResponse>().Result;
            Assert.IsTrue(cicleResponse.Success);
            //Get ticket again and check it was updated
            response = client.GetAsync(getByIdUrl).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            getCicleResponse = response.Content.ReadAsAsync <GetCicleResponse>().Result;
            Assert.IsTrue(getCicleResponse.Success);
            Assert.IsTrue(getCicleResponse.Cicles.Count == 1);
            Assert.IsTrue(getCicleResponse.Cicles.ElementAt(0).AmountPerHectarea == 2);
            Assert.IsTrue(getCicleResponse.Cicles.ElementAt(0).Name == "CicleNameUpdated");
            //test delete
            response = client.PostAsJsonAsync(deleteAction, new IdModel(cicleResponse.Cicle.Id)).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            cicleResponse = response.Content.ReadAsAsync <CicleResponse>().Result;
            Assert.IsTrue(cicleResponse.Success);
            //Get ticket again and check it is not found
            response = client.GetAsync(getByIdUrl).Result;
            Assert.IsTrue(response.IsSuccessStatusCode);
            getCicleResponse = response.Content.ReadAsAsync <GetCicleResponse>().Result;
            Assert.IsTrue(getCicleResponse.Success);
            Assert.IsTrue(getCicleResponse.Cicles.Count == 0);
        }
Exemplo n.º 25
0
        public void FindCountOddNumbersTest(int A, int expected)
        {
            int actual = Cicle.FindCountOddNumbers(A);

            Assert.AreEqual(expected, actual);
        }