public void Can_read_and_write_values() { var originalBananas = new List<Banana>(); var originalBanana = new Banana(); var entity = new Banana { Id = 77, Fk = 78, TopBanana = originalBanana, LesserBananas = originalBananas }; var sidecar = CreateSidecar(CreateInternalEntry(entity)); Assert.Equal(78, sidecar[FkProperty]); Assert.Same(originalBananas, sidecar[CollectionNavigation]); Assert.Same(originalBanana, sidecar[ReferenceNavigation]); var newBananas = new List<Banana>(); var newBanana = new Banana(); sidecar[FkProperty] = 79; sidecar[CollectionNavigation] = newBananas; sidecar[ReferenceNavigation] = newBanana; Assert.Equal(79, sidecar[FkProperty]); Assert.Same(newBananas, sidecar[CollectionNavigation]); Assert.Same(newBanana, sidecar[ReferenceNavigation]); Assert.Equal(77, entity.Id); Assert.Equal(78, entity.Fk); Assert.Same(originalBananas, entity.LesserBananas); Assert.Same(originalBanana, entity.TopBanana); }
protected StateEntry CreateStateEntry(Banana entity = null) { entity = entity ?? new Banana { Id = 77 }; var configuration = TestHelpers.CreateContextConfiguration(BuildModel()); return(configuration.Services.StateEntryFactory.Create(_model.GetEntityType(typeof(Banana)), entity)); }
private static bool AgregarFrutas(SegundoParcial frm) { bool retorno = false; Manzana _manzana = new Manzana("verde", 2, "rio negro"); Banana _banana = new Banana("amarillo", 5, "ecuador"); Durazno _durazno = new Durazno("rojo", 2.5, 53); return(retorno); }
//Crear la siguiente jerarquía de clases: //Fruta-> _color:string y _peso:double (protegidos); TieneCarozo:bool (prop. s/l, abstracta); //constructor con 2 parametros y FrutaToString():string (protegido y virtual, retorna los valores de la fruta) //Manzana-> _provinciaOrigen:string (protegido); Nombre:string (prop. s/l, retornará 'Manzana'); //Reutilizar FrutaToString en ToString() (mostrar todos los valores). TieneCarozo->true //Banana-> _paisOrigen:string (protegido); Nombre:string (prop. s/l, retornará 'Banana'); //Reutilizar FrutaToString en ToString() (mostrar todos los valores). TieneCarozo->false //Durazno-> _cantPelusa:int (protegido); Nombre:string (prop. s/l, retornará 'Durazno'); //Reutilizar FrutaToString en ToString() (mostrar todos los valores). TieneCarozo->true //Crear una instancia de cada clase e inicializar los atributos del form _manzana, _banana y _durazno. private void btnPunto1_Click(object sender, EventArgs e) { this._manzana = new Manzana("verde", 2, "rio negro"); this._banana = new Banana("amarillo", 5, "ecuador"); this._durazno = new Durazno("rojo", 2.5, 53); MessageBox.Show(this._manzana.ToString()); MessageBox.Show(this._banana.ToString()); MessageBox.Show(this._durazno.ToString()); }
protected InternalEntityEntry CreateInternalEntry(Banana entity = null) { entity = entity ?? new Banana { Id = 77 }; var contextServices = TestHelpers.Instance.CreateContextServices(_model); return(contextServices.GetRequiredService <IStateManager>().GetOrCreateEntry(entity)); }
public IActionResult Going(int ToDoId, int UserId) { Banana goingTo = new Banana(); goingTo.UserId = UserId; goingTo.ToDoId = ToDoId; dbContext.Bananas.Add(goingTo); dbContext.SaveChanges(); return(RedirectToAction("Success")); }
static void Main(string[] args) { Banana banaan = new Banana(); Bigmushroom bigmushroom = new Bigmushroom(); Mushroom mushroom = new Mushroom(); banaan.Throw(); bigmushroom.Grow(); mushroom.Accelerate(); }
public void Returns_null_if_key_value_is_null() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var entity = new Banana { P1 = 7, P2 = null }; var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity); Assert.Equal(EntityKey.NullEntityKey, new SimpleEntityKeyFactory<string>().Create(type, new[] { type.GetProperty("P2") }, entry)); }
public void TestMethod1() { IFruit banana = new Banana(); var output = banana.Peel(); Console.WriteLine(output); Banana bananaTwo = new Banana(); var anotherOutput = bananaTwo.Peel(); Console.WriteLine(anotherOutput); }
public void DisableSuperSkill() { isUsingSuperFlight = false; isUsingSuperSpeed = false; isUsingSuperTime = false; // Remove the superskill trail TrailRenderer trailRenderer = gameObject.GetComponentInChildren <TrailRenderer>(); trailRenderer.enabled = false; // Reset gravity to its orignal value gameObject.GetComponent <Rigidbody2D>().gravityScale = oriGravityScale; PteraMover.DeactivateTimeFreeze(); CaveFlamePit.DeactivateTimeFreeze(); Fireball.DeactivateTimeFreeze(); DestroyByTime.DeactivateTimeFreeze(); LaserBeam.DeactivateTimeFreeze(); Saw.DeactivateTimeFreeze(); LaserTurret.DeactivateTimeFreeze(); Bat.DeactivateTimeFreeze(); SwingingBoulder[] sb = FindObjectsOfType <SwingingBoulder>(); sb[0].DeactivateTimeFreeze(); sb[1].DeactivateTimeFreeze(); sb[2].DeactivateTimeFreeze(); sb[3].DeactivateTimeFreeze(); sb[4].DeactivateTimeFreeze(); sb[5].DeactivateTimeFreeze(); sb[6].DeactivateTimeFreeze(); RockController.DeactivateTimeFreeze(); Turret.DeactivateTimeFreeze(); PlayerController[] players = FindObjectsOfType <PlayerController>(); foreach (PlayerController p in players) { p.timeFreezeActivated = false; p.GetComponent <Rigidbody2D>().isKinematic = false; p.anim.enabled = true; } GameObject[] FXs = GameObject.FindGameObjectsWithTag("FX"); foreach (GameObject fx in FXs) { fx.GetComponent <ParticleSystem>().Play(); } Arrow.DeactivateTimeFreeze(); Puma.DeactivateTimeFreeze(); Piranha.DeactivateTimeFreeze(); Cobra.DeactivateTimeFreeze(); Saw.DeactivateTimeFreeze(); Banana.DeactivateTimeFreeze(); BananaSpawn[] bs = FindObjectsOfType <BananaSpawn>(); bs[0].DeactivateTimeFreeze(); bs[1].DeactivateTimeFreeze(); bs[2].DeactivateTimeFreeze(); }
public Task PutXMLEmptyNode() => TestStatus(async(host, pipeline) => { var root = new Banana() { Name = "Unknown Banana", Flavor = "", Expiration = DateTimeOffset.Parse("2012-02-24T00:53:52.789Z") }; return(await new XmlClient(ClientDiagnostics, pipeline, host).PutEmptyChildElementAsync(root)); });
public void Constructor_ValidQuality_CorrectProperties() { const int FruitQuality = 20; const string FruitName = nameof(Banana); const string FruitColor = "Yellow"; var banana = new Banana(FruitQuality); Assert.That(banana.Quality, Is.EqualTo(FruitQuality)); Assert.That(banana.Name, Is.EqualTo(FruitName)); Assert.That(banana.Color, Is.EqualTo(FruitColor)); }
public void DeleteBanana(Banana banana) { Bananas.Remove(banana); Fruits.Remove(banana); var n = 0; foreach (Banana b in Bananas) { b.Number = n++; } }
public void CallingInterfaceMethods() { IFruit banana = new Banana(); var output = banana.Peel(); Console.WriteLine(output); Banana bananaTwo = new Banana(); var anotherOutput = bananaTwo.Peel(); Console.WriteLine(anotherOutput); }
public virtual void Ensuring_snapshot_does_nothing_for_property_that_cannot_be_stored() { var entity = new Banana { Name = "Stand", Fk = 88 }; var sidecar = CreateSidecar(CreateInternalEntry(entity)); sidecar.EnsureSnapshot(NameProperty); Assert.False(sidecar.HasValue(NameProperty)); }
public void Returns_null_if_key_value_is_null() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService<IStateManager>(); var entity = new Banana { P1 = 7, P2 = null }; var entry = stateManager.GetOrCreateEntry(entity); Assert.Equal(EntityKey.InvalidEntityKey, new SimpleEntityKeyFactory<int>(0).Create(type, new[] { type.GetProperty("P2") }, entry)); }
public void Ensuring_snapshot_does_nothing_for_property_that_cannot_be_stored() { var entity = new Banana { Id = 77, Name = "Stand", State = "Frozen" }; var sidecar = CreateSidecar(CreateStateEntry(entity)); sidecar.EnsureSnapshot(NameProperty); Assert.False(sidecar.HasValue(NameProperty)); }
private void Start() { Machine m = new Machine(); Printer1 p1 = new Printer1(); Printer2 p2 = new Printer2(); p2.PrintNum(10, p1.Printx10); p2.PrintNum(10, p1.PrintNormal); Box <Banana> b_box = new Box <Banana>(); Box <Pineapple> p_box = new Box <Pineapple>(); Box <Guava> g_box = new Box <Guava>(); Box <Apple> a_box = new Box <Apple>(); Box <Mango> m_box = new Box <Mango>(); Banana b = new Banana(b_box); Banana b2 = new Banana(b_box); Banana b3 = new Banana(b_box); Apple a = new Apple(a_box); Apple a2 = new Apple(a_box); // float total_sum = 0; // float wtf = 0; float easy_total = 0; // more easier computing easy_total += m.EasyCompute <Banana>(m.EasyGetWeight <Banana>, b_box); easy_total += m.EasyCompute <Pineapple>(m.EasyGetWeight <Pineapple>, p_box); easy_total += m.EasyCompute <Guava>(m.EasyGetWeight <Guava>, g_box); easy_total += m.EasyCompute <Apple>(m.EasyGetWeight <Apple>, a_box); easy_total += m.EasyCompute <Mango>(m.EasyGetWeight <Mango>, m_box); Debug.Log("total sum is : " + easy_total); /* * // wtf * wtf += m.real_compute<Box<Banana>,Banana>(m.ComputeWeight<Box<Banana>, Banana>,b_box); * wtf += m.real_compute<Box<Pineapple>, Pineapple>(m.ComputeWeight<Box<Pineapple>, Pineapple>, p_box); * wtf += m.real_compute<Box<Guava>, Guava>(m.ComputeWeight<Box<Guava>, Guava>, g_box); * wtf += m.real_compute<Box<Apple>, Apple>(m.ComputeWeight<Box<Apple>, Apple>, a_box); * wtf += m.real_compute<Box<Mango>, Mango>(m.ComputeWeight<Box<Mango>, Mango>, m_box); * Debug.Log("WTF is this " + wtf); * total_sum += m.ComputeWeight<Box<Banana>, Banana>(b_box); * total_sum += m.ComputeWeight<Box<Pineapple>, Pineapple>(p_box); * total_sum += m.ComputeWeight<Box<Guava>, Guava>(g_box); * total_sum += m.ComputeWeight<Box<Apple>, Apple>(a_box); * total_sum += m.ComputeWeight<Box<Mango>, Mango>(m_box); * Debug.Log(total_sum); */ //Debug.Log(b_box.GetBoxWeight()); //Debug.Log("total amount = " + m.Compute()); }
public IActionResult AddToWatchlist(int MovieId, int UserId) { ViewBag.Content = dbContext.Movies.Include(m => m.Comments).ThenInclude(c => c.Content).Where(m => m.MovieId == MovieId); Banana added = new Banana(); added.UserId = UserId; added.MovieId = MovieId; dbContext.Bananas.Add(added); dbContext.SaveChanges(); return(RedirectToAction("Browse")); }
public void ItShouldReturnTheCorrectTotalForBananaTwoForAPoundDiscountWhenInDifferentOrder() { var banana = new Banana(); var orange = new Orange(); var apple = new Apple(); CheckoutCounter.Scan(banana); CheckoutCounter.Scan(orange); CheckoutCounter.Scan(banana); CheckoutCounter.Scan(apple); Assert.That(CheckoutCounter.Total(), Is.EqualTo(1.00M + orange.GetCost() + apple.GetCost())); }
public void Returns_null_if_key_value_is_null() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var entity = new Banana { P1 = 7, P2 = null }; var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity); Assert.Equal(EntityKey.NullEntityKey, new SimpleEntityKeyFactory <string>().Create(type, new[] { type.GetProperty("P2") }, entry)); }
public ActionResult BananaDetails(int id = 0) { Banana banana = repo.GetBananaById(id); return(View(new BananaModel { TypeOfBanana = banana.TypeOfBanana, Id = banana.Id, Price = banana.Price, Quantity = banana.Quantity })); }
public void Returns_null_if_any_value_in_the_entry_properties_is_null() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var random = new Random(); var entity = new Banana { P1 = 7, P2 = null, P3 = random }; var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity); Assert.Equal(EntityKey.NullEntityKey, new CompositeEntityKeyFactory().Create(type, type.GetKey().Properties, entry)); }
public void Creates_a_new_primary_key_for_key_values_in_the_given_entry() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var entity = new Banana { P1 = 7, P2 = "Ate" }; var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity); var key = (SimpleEntityKey<int>)new SimpleEntityKeyFactory<int>().Create(type, type.GetKey().Properties, entry); Assert.Equal(7, key.Value); }
protected StateEntry CreateStateEntry(Banana entity = null) { entity = entity ?? new Banana { Name = "Stand", Fk = 88 }; var stateEntry = TestHelpers.CreateStateEntry(_model, EntityState.Added, entity); stateEntry.MarkAsTemporary(IdProperty); return(stateEntry); }
public virtual void Can_read_and_write_null() { var entity = new Banana { Name = "Stand", Fk = 88 }; var sidecar = CreateSidecar(CreateInternalEntry(entity)); sidecar[FkProperty] = null; Assert.True(sidecar.HasValue(FkProperty)); Assert.Null(sidecar[FkProperty]); Assert.Equal(88, entity.Fk); }
public void SuperTime() { // Next iteration PteraMover.ActivateTimeFreeze(); CaveFlamePit.ActivateTimeFreeze(); Fireball.ActivateTimeFreeze(); DestroyByTime.ActivateTimeFreeze(); LaserBeam.ActivateTimeFreeze(); Saw.ActivateTimeFreeze(); LaserTurret.ActivateTimeFreeze(); SwingingBoulder[] sb = FindObjectsOfType <SwingingBoulder>(); sb[0].ActivateTimeFreeze(); sb[1].ActivateTimeFreeze(); sb[2].ActivateTimeFreeze(); sb[3].ActivateTimeFreeze(); sb[4].ActivateTimeFreeze(); sb[5].ActivateTimeFreeze(); sb[6].ActivateTimeFreeze(); RockController.ActivateTimeFreeze(); Turret.ActivateTimeFreeze(); PlayerController[] players = FindObjectsOfType <PlayerController>(); foreach (PlayerController p in players) { if (p.playerNumber != playerNumber) { p.timeFreezeActivated = true; p.GetComponent <Rigidbody2D>().isKinematic = true; p.anim.enabled = false; } } GameObject[] FXs = GameObject.FindGameObjectsWithTag("FX"); foreach (GameObject fx in FXs) { fx.GetComponent <ParticleSystem>().Pause(); } Arrow.ActivateTimeFreeze(); Puma.ActivateTimeFreeze(); Piranha.ActivateTimeFreeze(); Cobra.ActivateTimeFreeze(); Saw.ActivateTimeFreeze(); Banana.ActivateTimeFreeze(); BananaSpawn[] bs = FindObjectsOfType <BananaSpawn>(); Bat.ActivateTimeFreeze(); bs[0].ActivateTimeFreeze(); bs[1].ActivateTimeFreeze(); bs[2].ActivateTimeFreeze(); // Add a trail to show the use of a super skill TrailRenderer trailRenderer = gameObject.GetComponentInChildren <TrailRenderer>(); trailRenderer.enabled = true; }
public void Returns_null_if_key_value_is_default_sentinel_even_on_nullable_property() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService <IStateManager>(); var entity = new Banana { P1 = 7, P2 = 0 }; var entry = stateManager.GetOrCreateEntry(entity); Assert.Equal(EntityKey.InvalidEntityKey, new SimpleEntityKeyFactory <int>(0).Create(type, new[] { type.GetProperty("P2") }, entry)); }
public void Returns_null_if_key_value_is_null() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var stateManager = TestHelpers.CreateContextServices(model).GetRequiredService <StateManager>(); var entity = new Banana { P1 = 7, P2 = null }; var entry = stateManager.GetOrCreateEntry(entity); Assert.Equal(EntityKey.NullEntityKey, new SimpleEntityKeyFactory <string>().Create(type, new[] { type.GetProperty("P2") }, entry)); }
public void Committing_detaches_sidecar() { var entity = new Banana { Id = 77, Name = "Stand", State = "Frozen" }; var stateEntry = CreateStateEntry(entity); var sidecar = stateEntry.AddSidecar(CreateSidecar(stateEntry)); sidecar.Commit(); Assert.Null(stateEntry.TryGetSidecar(sidecar.Name)); }
public void Creates_a_new_key_for_values_in_the_given_entry() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService<IStateManager>(); var entity = new Banana { P1 = 7 }; var entry = stateManager.GetOrCreateEntry(entity); var key = (SimpleEntityKey<int>)new SimpleEntityKeyFactory<int>(0).Create(type, type.GetPrimaryKey().Properties, entry); Assert.Equal(7, key.Value); }
public void Can_commit_values_into_state_entry() { var entity = new Banana { Id = 77, Name = "Stand", State = "Frozen" }; var sidecar = CreateSidecar(CreateStateEntry(entity)); sidecar[StateProperty] = "Thawed"; sidecar.Commit(); Assert.Equal(77, entity.Id); Assert.Equal("Thawed", entity.State); }
public virtual void Can_commit_values_into_state_entry() { var entity = new Banana { Name = "Stand", Fk = 88 }; var sidecar = CreateSidecar(CreateStateEntry(entity)); sidecar[FkProperty] = 89; sidecar.Commit(); Assert.Equal(1, entity.Id); Assert.Equal(89, entity.Fk); }
public virtual void Committing_detaches_sidecar() { var entity = new Banana { Name = "Stand", Fk = 88 }; var stateEntry = CreateStateEntry(entity); var sidecar = stateEntry.AddSidecar(CreateSidecar(stateEntry)); sidecar.Commit(); Assert.Null(stateEntry.TryGetSidecar(sidecar.Name)); }
public void Creates_a_new_key_for_CLR_defaults_of_nullable_types() { var model = BuildModel(); var type = model.FindEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService<IStateManager>(); var entity = new Banana { P1 = 7, P2 = 0 }; var entry = stateManager.GetOrCreateEntry(entity); var key = (SimpleKeyValue<int?>)new SimpleKeyValueFactory<int?>(type.FindPrimaryKey()) .Create(new[] { type.FindProperty("P2") }, entry); Assert.Equal(0, key.Value); }
public void Creates_a_new_primary_key_for_key_values_in_the_given_entry() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var random = new Random(); var entity = new Banana { P1 = 7, P2 = "Ate", P3 = random }; var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity); var key = (CompositeEntityKey)new CompositeEntityKeyFactory().Create(type, type.GetKey().Properties, entry); Assert.Equal(new object[] { 7, "Ate", random }, key.Value); }
public virtual void Can_read_and_write_null() { var entity = new Banana { Name = "Stand", Fk = 88 }; var sidecar = CreateSidecar(CreateStateEntry(entity)); sidecar[FkProperty] = null; Assert.True(sidecar.HasValue(FkProperty)); Assert.Null(sidecar[FkProperty]); Assert.Equal(88, entity.Fk); }
public void Creates_a_new_primary_key_for_key_values_in_the_given_entry() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var entity = new Banana { P1 = 7, P2 = "Ate" }; var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity); var key = (SimpleEntityKey <int>) new SimpleEntityKeyFactory <int>().Create(type, type.GetKey().Properties, entry); Assert.Equal(7, key.Value); }
public void Can_read_and_write_null() { var entity = new Banana { Id = 77, Name = "Stand", State = "Frozen" }; var sidecar = CreateSidecar(CreateStateEntry(entity)); sidecar[StateProperty] = null; Assert.True(sidecar.HasValue(StateProperty)); Assert.Null(sidecar[StateProperty]); Assert.Equal("Frozen", entity.State); }
public void Creates_a_new_key_for_non_primary_key_values_in_the_given_entry() { var model = BuildModel(); var type = model.FindEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService<IStateManager>(); var entity = new Banana { P1 = 7, P2 = 8 }; var entry = stateManager.GetOrCreateEntry(entity); var key = (SimpleKeyValue<int>)new SimpleKeyValueFactory<int>(type.FindPrimaryKey()) .Create(new[] { type.FindProperty("P2") }, entry); Assert.Equal(8, key.Value); }
public void Creates_a_new_key_from_current_value_when_value_not_yet_set_in_sidecar() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var entity = new Banana { P1 = 7, P2 = 77 }; var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity); var sidecar = new RelationshipsSnapshot(entry); var key = (SimpleEntityKey<int>)new SimpleNullableEntityKeyFactory<int, int?>().Create( type, new[] { type.GetProperty("P2") }, sidecar); Assert.Equal(77, key.Value); }
public static Collectible CreateCollectible(CollectibleType collectibleType, Vector2 position, Tile currentTile) { Collectible newCollectible = null; switch (collectibleType) { case CollectibleType.POWERUP: int randomType = RandomManager.GetRandomInt(0, 1); switch (randomType) { case 0: newCollectible = new Powerup(DespicableGame.GetTexture(DespicableGame.GameTextures.SPEEDBOOST), position, currentTile, Powerup.PowerupType.SPEEDBOOST); break; case 1: if (RandomManager.GetRandomTrueFalse(75)) { newCollectible = new Powerup(DespicableGame.GetTexture(DespicableGame.GameTextures.TOY_PISTOL), position, currentTile, Powerup.PowerupType.TOY_PISTOL); } else { newCollectible = new Powerup(DespicableGame.GetTexture(DespicableGame.GameTextures.PLAYERTRAP_COLLECTIBLE), position, currentTile, Powerup.PowerupType.PLAYERTRAP); } break; } break; case CollectibleType.GOAL: newCollectible = new Goal(DespicableGame.GetTexture(DespicableGame.GameTextures.GOAL), position, currentTile); break; case CollectibleType.TRAP: newCollectible = new Trap(DespicableGame.GetTexture(DespicableGame.GameTextures.TRAP), position, currentTile); break; case CollectibleType.SHIP: newCollectible = new Ship(DespicableGame.GetTexture(DespicableGame.GameTextures.LEVEL_EXIT), position, currentTile); break; case CollectibleType.BANANA: newCollectible = new Banana(DespicableGame.GetTexture(DespicableGame.GameTextures.BANANA), position, currentTile); break; } return newCollectible; }
public void Creates_a_new_key_from_a_sidecar_value() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var entity = new Banana { P1 = 7, P2 = "Ate" }; var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity); var sidecar = new RelationshipsSnapshot(entry); sidecar[type.GetProperty("P2")] = "Eaten"; var key = (SimpleEntityKey<string>)new SimpleEntityKeyFactory<string>().Create( type, new[] { type.GetProperty("P2") }, sidecar); Assert.Equal("Eaten", key.Value); }
public virtual void Can_read_and_write_values() { var entity = new Banana { Name = "Stand", Fk = 88 }; var sidecar = CreateSidecar(CreateInternalEntry(entity)); Assert.Equal(-1, sidecar[IdProperty]); Assert.Equal(88, sidecar[FkProperty]); sidecar[IdProperty] = 78; sidecar[FkProperty] = 89; Assert.Equal(78, sidecar[IdProperty]); Assert.Equal(89, sidecar[FkProperty]); Assert.Equal(-1, entity.Id); Assert.Equal(88, entity.Fk); }
public void Creates_a_new_key_from_a_sidecar_value() { var model = BuildModel(); var type = model.FindEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService<IStateManager>(); var entity = new Banana { P1 = 7, P2 = 77 }; var entry = stateManager.GetOrCreateEntry(entity); var sidecar = new RelationshipsSnapshot(entry); sidecar[type.FindProperty("P2")] = 78; var key = (SimpleKeyValue<int>)new SimpleKeyValueFactory<int>(type.FindPrimaryKey()) .Create(new[] { type.FindProperty("P2") }, sidecar); Assert.Equal(78, key.Value); }
public void CalculateBananaMinimum() { int _dim=2; double []_data = {5,34}; double []_reference = {1,1}; double _epsilon=1e-7; double _realEpsilon = System.Math.Sqrt(_epsilon); double _step=1000; int _itmax=1000; double diff; Banana func = new Banana(); Rosenbrock objRosenbrock = new Rosenbrock(_dim, _data, func, _step, _epsilon, _itmax); objRosenbrock.FindMinimum(); diff = NumericNet.CalcDiff(_dim,_reference,_data); Assert.IsTrue(diff<_realEpsilon); }
public void Creates_a_new_key_for_non_primary_key_values_in_the_given_entry() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService<IStateManager>(); var random = new Random(); var entity = new Banana { P5 = "Ate", P6 = random }; var entry = stateManager.GetOrCreateEntry(entity); var key = (CompositeEntityKey)new CompositeEntityKeyFactory( new object[] { null, null }) .Create(type, new[] { type.GetProperty("P6"), type.GetProperty("P5") }, entry); Assert.Equal(new object[] { random, "Ate" }, key.Value); }
public void Creates_a_new_primary_key_for_key_values_in_the_given_entry() { var model = BuildModel(); var type = model.FindEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService<IStateManager>(); var random = new Random(); var entity = new Banana { P1 = 7, P2 = "Ate", P3 = random }; var entry = stateManager.GetOrCreateEntry(entity); var key = (CompositeKeyValue)new CompositeKeyValueFactory( type.FindPrimaryKey()) .Create(type.FindPrimaryKey().Properties, entry); Assert.Equal(new object[] { 7, "Ate", random }, key.Value); }
public void Returns_null_if_any_value_in_the_entry_properties_is_null() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService<IStateManager>(); var random = new Random(); var entity = new Banana { P1 = 7, P2 = null, P3 = random }; var entry = stateManager.GetOrCreateEntry(entity); Assert.Equal( EntityKey.InvalidEntityKey, new CompositeEntityKeyFactory( new object[] { 0, null, null }) .Create(type, type.GetPrimaryKey().Properties, entry)); }
public void Creates_a_new_primary_key_for_key_values_in_the_given_entry() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService<IStateManager>(); var random = new Random(); var entity = new Banana { P1 = 7, P2 = "Ate", P3 = random }; var entry = stateManager.GetOrCreateEntry(entity); var key = (CompositeEntityKey)new CompositeEntityKeyFactory( new object[] { 0, null, null }, new IBoxedValueReader[] { new GenericBoxedValueReader<int>(), new GenericBoxedValueReader<string>(), new GenericBoxedValueReader<Random>() }) .Create(type, type.GetPrimaryKey().Properties, entry); Assert.Equal(new object[] { 7, "Ate", random }, key.Value); }
public void CalculateBananaMinimum() { int _dim=2; double []_data = {5,34}; double []_reference = {1,1}; double _epsilon=1e-7; double _realEpsilon = System.Math.Sqrt(_epsilon); //Nelder needs larger initial step double _step=2000; int _itmax=1000; double diff; Banana func = new Banana(); Nelder objNelder = new Nelder(_dim,_data,func,_step,_epsilon,_itmax);; objNelder.FindMinimum(); diff = NumericNet.CalcDiff(_dim,_reference,objNelder.Result); Assert.IsTrue(diff<_realEpsilon); }
public void Creates_a_new_key_for_values_from_a_sidecar() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var random = new Random(); var entity = new Banana { P4 = 7, P5 = "Ate", P6 = random }; var entry = new ClrStateEntry(TestHelpers.CreateContextConfiguration(model), type, entity); var sidecar = new RelationshipsSnapshot(entry); sidecar[type.GetProperty("P4")] = 77; var key = (CompositeEntityKey)new CompositeEntityKeyFactory().Create( type, new[] { type.GetProperty("P6"), type.GetProperty("P4"), type.GetProperty("P5") }, sidecar); Assert.Equal(new object[] { random, 77, "Ate" }, key.Value); }
public void IsAssignableFromTest() { // | Fruit : IFruit (abstract) // |-> Apple : Fruit, IFruit, IRedSkinned -> GrannySmith // |-> Banana : Fruit, IFruit var reference = "Insert initialization of parameter ´reference´ here"; object targetOfAssignment = new Apple(); Guard.IsAssignableFrom<Apple>(() => reference, targetOfAssignment); targetOfAssignment = new Apple(); Guard.IsAssignableFrom<GrannySmith>(() => reference, targetOfAssignment); targetOfAssignment = new Banana(); Assert.Throws<ArgumentException>(() => Guard.IsAssignableFrom<IFruit>(() => reference, targetOfAssignment)); targetOfAssignment = new AndNowToSomethingCompletelyDifferent(); Assert.Throws<ArgumentException>(() => Guard.IsAssignableFrom<Fruit>(() => reference, targetOfAssignment)); }
public void Creates_a_new_key_for_values_from_a_sidecar() { var model = BuildModel(); var type = model.GetEntityType(typeof(Banana)); var stateManager = TestHelpers.Instance.CreateContextServices(model).GetRequiredService<IStateManager>(); var random = new Random(); var entity = new Banana { P4 = 7, P5 = "Ate", P6 = random }; var entry = stateManager.GetOrCreateEntry(entity); var sidecar = new RelationshipsSnapshot(entry); sidecar[type.GetProperty("P4")] = 77; var key = (CompositeEntityKey)new CompositeEntityKeyFactory( new object[] { null, 0, null }) .Create(type, new[] { type.GetProperty("P6"), type.GetProperty("P4"), type.GetProperty("P5") }, sidecar); Assert.Equal(new object[] { random, 77, "Ate" }, key.Value); }
public void Can_check_if_value_is_stored() { var sidecar = CreateSidecar(); Assert.False(sidecar.HasValue(NameProperty)); Assert.False(sidecar.HasValue(IdProperty)); Assert.False(sidecar.HasValue(FkProperty)); Assert.False(sidecar.HasValue(CollectionNavigation)); Assert.False(sidecar.HasValue(ReferenceNavigation)); sidecar[IdProperty] = 11; sidecar[FkProperty] = 78; sidecar[CollectionNavigation] = new List<Banana>(); sidecar[ReferenceNavigation] = new Banana(); Assert.False(sidecar.HasValue(NameProperty)); Assert.True(sidecar.HasValue(IdProperty)); Assert.True(sidecar.HasValue(FkProperty)); Assert.True(sidecar.HasValue(CollectionNavigation)); Assert.True(sidecar.HasValue(ReferenceNavigation)); }
public void CanBeAssignedToTest() { // | Fruit : IFruit (abstract) // |-> Apple : Fruit, IFruit, IRedSkinned // |-> Banana : Fruit, IFruit var reference = "Insert initialization of parameter ´reference´ here"; object targetType = new Apple(); Guard.CanBeAssignedTo<Apple>(() => reference, targetType); targetType = new Apple(); Guard.CanBeAssignedTo<Fruit>(() => reference, targetType); targetType = new Apple(); Guard.CanBeAssignedTo<IRedSkinned>(() => reference, targetType); targetType = new Banana(); Assert.Throws<ArgumentException>(() => Guard.CanBeAssignedTo<IRedSkinned>(() => reference, targetType)); targetType = new AndNowToSomethingCompletelyDifferent(); Assert.Throws<ArgumentException>(() => Guard.CanBeAssignedTo<IFruit>(() => reference, targetType)); }
private void InitContents( FruitType type ) { Food item = null; byte count = (byte)Utility.RandomMinMax( 10, 30 ); for( byte i = 0; i < count; i++ ) { switch( type ) { default: case FruitType.Apples: item = new Apple(); break; case FruitType.Bananas: item = new Banana(); break; case FruitType.Bread: item = new BreadLoaf(); break; case FruitType.Gourds: item = new Gourd(); break; case FruitType.Grapes: item = new Grapes(); break; case FruitType.Lemons: item = new Lemon(); break; case FruitType.Tomatoes: item = new Tomato(); break; case FruitType.Vegetables1: case FruitType.Vegetables2: case FruitType.Vegetables3: { switch( Utility.Random( 4 ) ) { case 0: item = new Carrot(); break; case 1: item = new Onion(); break; case 2: item = new Pumpkin(); break; case 3: item = new Gourd(); break; } break; } } if( item != null ) DropItem( item ); } }
protected InternalEntityEntry CreateInternalEntry(Banana entity = null) { entity = entity ?? new Banana { Name = "Stand", Fk = 88 }; var customServices = new ServiceCollection() .AddScoped<IValueGeneratorSelector, TestInMemoryValueGeneratorSelector>(); var entry = TestHelpers.Instance.CreateContextServices(customServices, _model) .GetRequiredService<IStateManager>() .GetOrCreateEntry(entity); entry.SetEntityState(EntityState.Added); return entry; }
public virtual void Committing_detaches_sidecar() { var entity = new Banana { Name = "Stand", Fk = 88 }; var entry = CreateInternalEntry(entity); var sidecar = entry.AddSidecar(CreateSidecar(entry)); sidecar.Commit(); Assert.Null(entry.TryGetSidecar(sidecar.Name)); }
public virtual void Can_commit_values_into_state_entry() { var entity = new Banana { Name = "Stand", Fk = 88 }; var sidecar = CreateSidecar(CreateInternalEntry(entity)); sidecar[FkProperty] = 89; sidecar.Commit(); Assert.Equal(-1, entity.Id); Assert.Equal(89, entity.Fk); }