public async Task <IActionResult> PutRealPerson(int id, RealPerson realPerson) { if (id != realPerson.realPersonID) { return(BadRequest()); } db.Entry(realPerson).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RealPersonExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <RealPerson> > PostRealPerson(RealPerson realPerson) { db.RealPersons.Add(realPerson); await db.SaveChangesAsync(); return(CreatedAtAction("GetRealPerson", new { id = realPerson.realPersonID }, realPerson)); }
public void UpdatePerson_HonorNulls() { const string FIRSTNAME = "this is the new Firstname"; const string LASTNAME = "this is the new Lastname"; byte[] picture = { 1, 12, 24, 56, 111, 23, 56, 89 }; var oldPerson = new RealPerson { Firstname = FIRSTNAME, Lastname = LASTNAME, ProfilePicture = picture }; var newPerson = new RealPerson { Firstname = "", Lastname = "", ProfilePicture = null }; PersonService.UpdatePerson(newPerson, oldPerson); Assert.Equal("", oldPerson.Firstname); Assert.Equal("", oldPerson.Lastname); Assert.Equal(picture, oldPerson.ProfilePicture); }
private static User CreateUser() { using (var ctx = _factory.CreateDbContext(new string[0])) { Console.WriteLine("Username (must be an Email): "); string username; do { username = Console.ReadLine(); } while (!username.IsValidEmail()); Console.WriteLine("Password"); var password = Console.ReadLine(); var user = JwtAuthenticationService.CreateNewUser(username); JwtAuthenticationService.UpdatePassword(user, password); ctx.Users.Add(user); ctx.SaveChanges(); var person = new RealPerson { Firstname = "Mr.", Lastname = "Administrator", UserId = user.Id }; ctx.RealPeople.Add(person); ctx.SaveChanges(); return(user); } }
public void UpdatePerson_Everything() { const string FIRSTNAME = "this is the new Firstname"; const string LASTNAME = "this is the new Lastname"; byte[] picture = { 1, 12, 24, 56, 111, 23, 56, 89 }; byte[] oldPicture = { 1, 45, 66, 7, 87, 44 }; var oldPerson = new RealPerson { Firstname = "firsntafkn", Lastname = "Lastname", ProfilePicture = oldPicture }; var newPerson = new RealPerson { Firstname = FIRSTNAME, Lastname = LASTNAME, ProfilePicture = picture }; PersonService.UpdatePerson(newPerson, oldPerson); Assert.Equal(newPerson.Firstname, oldPerson.Firstname); Assert.Equal(newPerson.Lastname, oldPerson.Lastname); Assert.Equal(oldPicture, oldPerson.ProfilePicture); }
public void ToString_RaceEmpty() { //Arrange var TestPerson = new RealPerson("Henk", 10); //Act String Result = TestPerson.Race; //Assert Assert.AreEqual("Caucasian", Result); }
public void ToString_AgeEmpty() { //Arrange var TestPerson = new RealPerson("Henk"); //Act String Result = TestPerson.ToString(); //Assert Assert.AreEqual("My name is Henk and I am 30 years", Result); }
public void ToString_NameAndAgeFilled() { //Arrange var TestPerson = new RealPerson("Henk", 10); //Act String Result = TestPerson.ToString(); //Assert Assert.AreEqual("My name is Henk and I am 10 years", Result); }
public void AddYearsToAge_notNegative() { //Arrange var TestPerson = new RealPerson("Henk", 10); //Act TestPerson.AddYearsToAge(-1); int Result = TestPerson.Age; //Assert Assert.AreEqual(10, Result); }
public void AddYearsToAge_notOlderThan100() { //Arrange var TestPerson = new RealPerson("Henk", 100); //Act TestPerson.AddYearsToAge(1); int Result = TestPerson.Age; //Assert Assert.AreEqual(100, Result); }
void SortList(List <RealPerson> unsortedList) { StartPosition = new Vector3(Random.Range(0, 5), Random.Range(0, 5), 0); //min inclusive max exclusive TargetObject.transform.position = new Vector3(Random.Range(15, 25), Random.Range(15, 25), 0); for (int i = 1; i < unsortedList.Count; i++) { for (int j = 1; j < i + 1; j++) { if (unsortedList [i - j].ReturnFitness() > unsortedList [i - j + 1].ReturnFitness()) { RealPerson tempSecondTest = unsortedList [i - j + 1]; unsortedList [i - j + 1] = unsortedList [i - j]; //Substitute (i - j + 1, i - j); unsortedList [i - j] = tempSecondTest; } else { break; } } } /*for (int i = 0; i < unsortedList.Count; i++){ * //Debug.Log(unsortedList[i].ReturnFitness()); * PeopleList[i].FeedForward(); * }*/ /*for (int i = 0; i < 9; i++) { //Set amount to cut HERE * //PeopleList [i] = PeopleList [PeopleList.Count - 1 - i]; * Debug.Log(unsortedList[PeopleList.Count - 1 - i].ReturnFitness()); * Substitute(PeopleList.Count - 1 - i, i); * }*/ for (int i = 0; i < populationSize; i++) { if (i < 20) //Set amount to cut HERE //PeopleList [i] = (PeopleList [PeopleList.Count - 1 - i]); //PeopleList [i] = new RealPerson(PeopleList[PeopleList.Count - 1 - i]); //PeopleList [i] = new RealPerson(); //Debug.Log(unsortedList[PeopleList.Count - 1 - i].ReturnFitness()); { Substitute(PeopleList.Count - 1, i); //can replace with PeopleList.Count - 1 - i } //PeopleList[i].FeedForward(); //Debug.Log(unsortedList[i].ReturnFitness()); if (PeopleList[i].ReturnFitness() != 100) //can remove the perfect fitness condition { PeopleList[i].MutateNetwork(); } //PeopleList[i].SetFitness(0f); PeopleList[i].gameObject.transform.position = StartPosition; } Training = true; }
public Session Copy() { Session session = new Session(); session.TokenId = TokenId; session.ApiSessionId = ApiSessionId; session.ClientIpAddress = ClientIpAddress; session.LoginTime = LoginTime; session.LogoutTime = LogoutTime; session.RealPerson = RealPerson.Copy(); session.MyPerson = MyPerson.Copy(); return(session); }
// Use this for initialization void Start() { StartPosition = new Vector3(Random.Range(0, 5), Random.Range(0, 5), 0); //min inclusive max exclusive TargetObject = Instantiate(TargetObject, new Vector3(Random.Range(15, 25), Random.Range(15, 25), 0), Quaternion.identity); for (int i = 0; i < populationSize; i++) { RealPerson PersonToAdd = ((GameObject)Instantiate(PersonGameobject, StartPosition, Quaternion.identity)).GetComponent <RealPerson> (); PersonToAdd.RealSetup(NetworkShape, TargetObject); PeopleList.Add(PersonToAdd); } //GenerationFunction(); //SortList(PeopleList); /*for (int i = 0; i < 2; i++) { * PeopleList [i] = PeopleList [PeopleList.Count - 1 - i]; * } * for (int i = 0; i < populationSize; i++) { * Debug.Log(PeopleList[i].ReturnFitness()); * }*/ }
public async Task UpdatePerson_Success() { var user = await SetupAuthenticationAsync(); await _Context.SaveChangesAsync(); var person = new RealPerson { Firstname = Guid.NewGuid().ToString(), Lastname = Guid.NewGuid().ToString() }; var r = await _Client.PostAsync("/api/person/profile", person.ToStringContent()); r.EnsureSuccessStatusCode(); var dbPerson = await _Context.RealPeople.FirstOrDefaultAsync(x => x.UserId == user.Id); await _Context.Entry(dbPerson).ReloadAsync(); Assert.Equal(person.Firstname, dbPerson.Firstname); Assert.Equal(person.Lastname, dbPerson.Lastname); }
public virtual async Task UpdatePerson([FromBody] RealPerson person) { var currentPerson = await _personService.GetPersonForUserAsync(); await _personService.UpdatePersonAsync(person, currentPerson.Id); }
static void Main(string[] args) { #region Creational Patterns //Singleton Singleton singleton = Singleton.GetInstance(); singleton.someUsefulCode(); Separate(); //Builder Item ciastko = new ItemBuilder(0).SetName("Ciastko").SetType("Food").build(); Console.WriteLine($"{ciastko.id}. {ciastko.name}, {ciastko.type}"); Separate(); //Prototype Person person = new Person(1, 15, "John"); Person shallowCopy = (Person)person.ShallowCopy(); Person deepCopy = (Person)person.DeepCopy(); Console.WriteLine(person); Console.WriteLine(shallowCopy); Console.WriteLine(deepCopy); person.name = "Max"; person.age = 20; person.id = new IdInfo(99); Console.WriteLine(person); Console.WriteLine(shallowCopy); Console.WriteLine(deepCopy); Separate(); //AbstractFactory Car miniCar = CarFactory.CarBuilder(CarType.MINI); Car lumiCar = CarFactory.CarBuilder(CarType.LUXURY); Separate(); //FactoryPattern ShapeFactory shapeFactory = new ShapeFactory(); Shape circle = shapeFactory.GetShape("circle"); circle.print(); Separate(); //ObjectPool SomeObject so1 = Pool.GetObject(); SomeObject so2 = Pool.GetObject(); Pool.ReleaseObject(so1); SomeObject so3 = Pool.GetObject(); Console.WriteLine($"so1: {so1}"); Console.WriteLine($"so2: {so2}"); Console.WriteLine($"so3: {so3}"); Separate(); #endregion #region Structural Patterns //Adapter OldClass oldClass = new OldClass(); IWrite write = new Adapter(oldClass); write.PrintMessage(); Separate(); //Bridge Thing triangle = new Ball(new Blue()); triangle.print(); Separate(); //Composite Component leaf1 = new Leaf("leaf1"); Component leaf2 = new Leaf("leaf2"); Component leaf3 = new Leaf("leaf3"); Component branch1 = new Composite("branch1"); branch1.Add(leaf1); branch1.Add(leaf2); Component root = new Composite("root"); root.Add(branch1); root.Add(leaf3); root.Display(1); Separate(); //Decorator Weapon weapon = new BaseWeapon(); weapon.shot(); Weapon modifiedWeapon = new Stock(weapon); modifiedWeapon.shot(); Separate(); //Facade Student student = new Student(); student.StartLearning(); student.EndLearning(); Separate(); //Flyweight Particle p1 = ParticleFactory.getSmallParticle("red"); //new key Particle p2 = ParticleFactory.getSmallParticle("red"); //no new one Particle p3 = ParticleFactory.getSmallParticle("blue"); //new key Separate(); //Proxy IBank proxyBank = new ProxyBank(); proxyBank.Pay(); Separate(); #endregion #region Behavioral Patterns //ChainOfResponsibility Chain chain = new Chain(); chain.Process(5); Separate(); //Command var modifyPrice = new ModifyPrice(); var product = new Product("Brick", 200); Console.WriteLine(product); modifyPrice.SetCommandAndInvoke(new ProductCommand(product, PriceAction.Increase, 50)); Console.WriteLine(product); Separate(); //Iterator CarRepository carRepository = new CarRepository(new string[] { "Renault", "BMW", "VW" }); for (IIterator i = carRepository.GetIterator(); i.hasNext();) { Console.WriteLine($"Car: {i.next()}"); } Separate(); //Mediator Mediator mediator = new RealMediator(); APerson jhon = new RealPerson(mediator, "Jhon"); APerson max = new RealPerson(mediator, "Max"); APerson emma = new RealPerson(mediator, "Emma"); mediator.AddPerson(jhon); mediator.AddPerson(max); mediator.AddPerson(emma); jhon.Send("I'm a jhon and this is my message! "); emma.Send("henlo"); Separate(); //Memento Localization localization = new Localization("NY", 123, 111); LocalizationSnapshot snapshot = localization.CreateSnapshot(); Console.WriteLine(localization); localization.City = "Berlin"; localization.X = 999; Console.WriteLine(localization); snapshot.Restore(); Console.WriteLine(localization); Separate(); //Observer Customer james = new Customer("James"); Customer william = new Customer("William"); Customer evelyn = new Customer("Evelyn"); Shop grocery = new Shop("YourFood"); Shop DIYshop = new Shop("Tooler"); grocery.AddSubscriber(james); grocery.AddSubscriber(william); grocery.AddSubscriber(evelyn); DIYshop.AddSubscriber(james); DIYshop.AddSubscriber(william); grocery.AddMerchandise(new Merchandise("pizza", 19)); DIYshop.AddMerchandise(new Merchandise("hammer", 399)); Separate(); //State AudioPlayer ap = new AudioPlayer(); ap.ClickPlay(); ap.ClickLock(); ap.ClickPlay(); ap.ClickPlay(); ap.ClickPlay(); ap.ClickLock(); ap.NextSong(); ap.PreviousSong(); Separate(); //Strategy Calculator calculator = new Calculator(new AddingStrategy()); calculator.Calculate(5, 2); calculator.ChangeStrategy(new SubtractingStrategy()); calculator.Calculate(5, 2); Separate(); //TemplateMethod Algorithm a1 = new AlgorithmWithStep2(); a1.Execute(); Algorithm a2 = new AlgorithmWithStep2and3(); a2.Execute(); Separate(); //Visitor ElementA ea = new ElementA("ElementA"); ElementA eb = new ElementA("ElementB"); Visitor1 v1 = new Visitor1(); Visitor2 v2 = new Visitor2(); ea.Accept(v1); ea.Accept(v2); eb.Accept(v1); eb.Accept(v2); #endregion }