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); }
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)); } }
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)); } }
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)); }
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)); }
public CicleList() { InitializeComponent(); presenter = new CiclePresenter(this); CurrentCicle = new Cicle(); GridCicleDetails.DataContext = CurrentCicle; }
private void Start() { _collider = GetComponent <BoxCollider2D>(); _spriteRenderer = GetComponent <SpriteRenderer>(); _spriteRenderer.color = _colorOn; _selfCicle = Cicle.Dicrement; _changingStep = (_colorOn - _colorOff) / _cicleTime; }
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); }
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); } }
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)); }
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); } }
private void Work(Cicle cicle) { _spriteRenderer.color = GetChangedColor(_spriteRenderer.color, _changingStep * (int)cicle); _collider.enabled = IsHalfColor(); }
public void RaiseToPowerTest(int a, int b, int expected) { int actual = Cicle.RaiseToPower(a, b); Assert.AreEqual(expected, actual); }
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); }
public void CompareByNumbersTest(int A, int B, string expected) { string actual = Cicle.CompareByNumbers(A, B); Assert.AreEqual(expected, actual); }
public void ShowAllNumbersFissileOnATest(int a, int[] expected) { int[] actual = Cicle.ShowAllNumbersFissileOnA(a); Assert.AreEqual(expected, actual); }
public void ShowCountNumberSquareBiggerATest(int a, int expected) { int actual = Cicle.ShowCountNumberSquareBiggerA(a); Assert.AreEqual(expected, actual); }
public void ShowShowGreatestDivisorTest(int a, int expected) { int actual = Cicle.ShowGreatestDivisor(a); Assert.AreEqual(expected, actual); }
public void SumNumbersABDividedBy7Test(int a, int b, int expected) { int actual = Cicle.SumNumbersABDividedBy7(a, b); Assert.AreEqual(expected, actual); }
public void ShowNumberSeriesFibonacciTest(int a, int expected) { int actual = Cicle.ShowNumberSeriesFibonacci(a); Assert.AreEqual(expected, actual); }
public void ShowCountSumEvenGreatestObbTest(int A, int expected) { int actual = Cicle.ShowCountSumEvenGreatestObb(A); Assert.AreEqual(expected, actual); }
public void FindGCDTest(int a, int b, int expected) { int actual = Cicle.FindGCD(a, b); Assert.AreEqual(expected, actual); }
public void FindNumberFromCubeWithHalfDivisionTest(int a, int expected) { int actual = Cicle.FindNumberFromCubeWithHalfDivision(a); Assert.AreEqual(expected, actual); }
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); }
public void FindCountOddNumbersTest(int A, int expected) { int actual = Cicle.FindCountOddNumbers(A); Assert.AreEqual(expected, actual); }