public async Task TryUpdateModel_SettableArrayModel_WithPrefix_GetsBound() { // Arrange var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { request.QueryString = QueryString.Create("prefix.Address[0].Street", "SomeStreet"); }); var modelState = new ModelStateDictionary(); var model = new Person4(); // Act var result = await TryUpdateModel(model, "prefix", operationContext, modelState); // Assert Assert.True(result); // Model Assert.NotNull(model.Address); Assert.Equal(1, model.Address.Count()); Assert.Equal("SomeStreet", model.Address[0].Street); // ModelState Assert.True(modelState.IsValid); Assert.Equal(1, modelState.Keys.Count); var key = Assert.Single(modelState.Keys, k => k == "prefix.Address[0].Street"); Assert.NotNull(modelState[key].Value); Assert.Equal("SomeStreet", modelState[key].Value.AttemptedValue); Assert.Equal("SomeStreet", modelState[key].Value.RawValue); Assert.Empty(modelState[key].Errors); Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); }
/// <summary> /// Run the application. /// </summary> public override BoolMessageItem Execute() { Console.WriteLine("===================================================="); Console.WriteLine("Entity "); // Example 1 : Using Entity base class. IEntity entity = new Person() { Name = "kishore" }; Console.WriteLine("Id, Persistant and Audit fields."); Console.WriteLine("These fields are set by EntityService if using CommonLibrary Entity-Model Services."); Console.WriteLine("Id ", entity.Id); Console.WriteLine("IsPersistant ", entity.IsPersistant()); Console.WriteLine("CreateDate ", entity.CreateDate); Console.WriteLine("CreateUser ", entity.CreateUser); Console.WriteLine("UpdateDate ", entity.UpdateDate); Console.WriteLine("UpdateUser ", entity.UpdateUser); Console.WriteLine("UpdateComment ", entity.UpdateComment); // Example 2 : Using Entity<T> generic base class to get the parameterless CRUD methods. // 1st initialize the repositories. EntityRegistration.Register <Person2>(new RepositoryInMemory <Person2>("Id"), false); var p2 = new Person2() { Name = "kishore" }; p2.Create(); p2.Name = "updated"; p2.Update(); p2.GetAll(); p2.Save(); p2.Delete(); // Example 3 : Implement IEntityVersionable to get versioning on the entities. // Wrap the real repository w/ the RepositoryVersionable decorator to get versioning behaviour. EntityRegistration.Register <Person3>(new RepositoryVersioned <Person3>(new RepositoryInMemory <Person3>("Id,Version,VersionRefId")), false); var p3 = new Person3(); p3.Create(); p3.Name = "updated"; p3.Update(); p3.GetAll(); var p4 = new Person4(); p4.Name = "kishore"; p4.Phone = "111-111-1111"; p4.RegisterDate = DateTime.Today; p4.About = "artist"; p4.Age = 30; p4.Email = "*****@*****.**"; bool isValid = p4.IsValid; return(BoolMessageItem.True); }
// change to Main to run. public static void none(string[] args) { var john = new Person4(new[] { "John", "Smith" }, new Address4("London Road", 123)); //var jane = john.DeepCopy(); var jane = john.DeepCopyXml(); jane.names[0] = "Jane"; jane.address.houseNumber = 321; Console.WriteLine(john); Console.WriteLine(jane); }
public async Task TryUpdateModel_SettableArrayModel_WithPrefix_OverwritesArray() { // Arrange var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { request.QueryString = QueryString.Create("prefix.Address[0].Street", "SomeStreet"); }); var modelState = new ModelStateDictionary(); var model = new Person4 { Address = new Address[] { new Address { Street = "Old street", City = "Toronto", }, }, }; var collection = model.Address; // Act var result = await TryUpdateModel(model, "prefix", operationContext, modelState); // Assert Assert.True(result); // Model Assert.NotNull(model.Address); Assert.NotSame(collection, model.Address); Assert.Equal(1, model.Address.Length); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); // ModelState Assert.True(modelState.IsValid); var entry = Assert.Single(modelState); Assert.Equal("prefix.Address[0].Street", entry.Key); var state = entry.Value; Assert.NotNull(state.Value); Assert.Equal("SomeStreet", state.Value.AttemptedValue); Assert.Equal("SomeStreet", state.Value.RawValue); Assert.Empty(state.Errors); Assert.Equal(ModelValidationState.Valid, state.ValidationState); }
public async Task ActionParameter_SettableArrayModel_EmptyPrefix_GetsBound() { // Arrange var argumentBinder = ModelBindingTestHelper.GetArgumentBinder(); var parameter = new ParameterDescriptor() { Name = "prefix", ParameterType = typeof(Person4) }; var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { request.QueryString = QueryString.Create("Address[0].Street", "SomeStreet"); }); var modelState = new ModelStateDictionary(); var model = new Person4(); // Act var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext); // Assert Assert.NotNull(modelBindingResult); Assert.True(modelBindingResult.IsModelSet); // Model Assert.NotNull(modelBindingResult.Model); var boundModel = Assert.IsType <Person4>(modelBindingResult.Model); Assert.NotNull(boundModel.Address); Assert.Equal(1, boundModel.Address.Count()); Assert.Equal("SomeStreet", boundModel.Address[0].Street); // ModelState Assert.True(modelState.IsValid); Assert.Equal(1, modelState.Keys.Count); var key = Assert.Single(modelState.Keys, k => k == "Address[0].Street"); Assert.NotNull(modelState[key].Value); Assert.Equal("SomeStreet", modelState[key].Value.AttemptedValue); Assert.Equal("SomeStreet", modelState[key].Value.RawValue); Assert.Empty(modelState[key].Errors); Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState); }
public async Task TryUpdateModel_SettableArrayModel_EmptyPrefix_CreatesArray() { // Arrange var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { request.QueryString = QueryString.Create("Address[0].Street", "SomeStreet"); }); var modelState = new ModelStateDictionary(); var model = new Person4(); // Act var result = await TryUpdateModel(model, string.Empty, operationContext, modelState); // Assert Assert.True(result); // Model Assert.NotNull(model.Address); Assert.Equal(1, model.Address.Length); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); // ModelState Assert.True(modelState.IsValid); var entry = Assert.Single(modelState); Assert.Equal("Address[0].Street", entry.Key); var state = entry.Value; Assert.NotNull(state.Value); Assert.Equal("SomeStreet", state.Value.AttemptedValue); Assert.Equal("SomeStreet", state.Value.RawValue); Assert.Empty(state.Errors); Assert.Equal(ModelValidationState.Valid, state.ValidationState); }
public async Task TryUpdateModel_SettableArrayModel_WithPrefix_CreatesArray() { // Arrange var testContext = ModelBindingTestHelper.GetTestContext(request => { request.QueryString = QueryString.Create("prefix.Address[0].Street", "SomeStreet"); }); var modelState = testContext.ModelState; var model = new Person4(); // Act var result = await TryUpdateModelAsync(model, "prefix", testContext); // Assert Assert.True(result); // Model Assert.NotNull(model.Address); Assert.Single(model.Address); Assert.Equal("SomeStreet", model.Address[0].Street); Assert.Null(model.Address[0].City); // ModelState Assert.True(modelState.IsValid); var entry = Assert.Single(modelState); Assert.Equal("prefix.Address[0].Street", entry.Key); var state = entry.Value; Assert.Equal("SomeStreet", state.AttemptedValue); Assert.Equal("SomeStreet", state.RawValue); Assert.Empty(state.Errors); Assert.Equal(ModelValidationState.Valid, state.ValidationState); }
public static void Main(string[] args) { /* * OBJECT ORIENTED PROGRAMMING - NESNE TABANLI PROGRAMLAMA * * CLASS : Yapmak istediğimiz işlemleri gruplara ayırıp daha düzenli ve profesyonel kodlar yazabilmek için kullanılan yapıdır. * PARENT / SUPER CLASS : Miras veren class' dır. * CHILD / SUB CLASS : Miras veren class' dır. * * ERİŞİM BELİRLEYİCİLER : Class veya instancelara nasıl erişebileceğimizi belirlerler. * * I) public : Her yerden erişim sağlanır. * II) private : Sadece tanımlandığı sınıfta erişim sağlanır. * III) internal : Sadece tanımlandığı projede erişim sağlanır. * IV) protected : Sadece tanımlandığı sınıfta veya mirasçı sınıfta erişim sağlanır. * V) protected internal : protected' dan farkı tanımlamanın aynı projede olmasına gerek yoktur. * VI) private protected : Sadece kendinden türetilmiş nesneler üzerinden kullanılabilir. * * Not : Eğer bir üye üzerinde yapılan değişiklik başka yapıları da etkiliyorsa veya zarar veriyorsa, o üye private tanımlanmalıdır, * Not : Private verilerin değerlerini alan ve ayarlayan metotlar public olmalıdır. */ //------------------------------------------------------------------------------------------------ CLASS ÇAĞRILDIĞI KISIM ------------------------------------------------------------------------------------------------- // KONU 1 : FIELD TANIMLAMA // INSTANCE : Bir class' dan üretilen nesnedir. Person p1 = new Person(); p1._Name = "Ali"; p1._Surname = "YILDIRIM"; p1._Age = 35; p1._Gender = 'e'; //Console.WriteLine($"{p1._Name} {p1._Surname} {p1._Age} {p1._Gender}"); //-------------------------------------------------------------------------------------------------------------------------------------------------------- // KONU 2 : ENCAPSULATION (KAPSÜLLEME) Person2 p2 = new Person2 { Name = "Ayşe", Surname = "KARATAŞ", Age = 15, Gender = 'k' }; // Üstte yazdığımız şekil dışında bu şekildede yazabiliriz. //Console.WriteLine($"{p2._Name} {p2._Surname} {p2._Age} {p2._Gender}"); //-------------------------------------------------------------------------------------------------------------------------------------------------------- // KONU 3 : INHERITANCE (KALITIM / MİRASLAMA) Person3 p3 = new Person3(); p3.Name = "Mehmet"; p3.Surname = "ATEŞ"; p3.FullName(p3.Name, p3.Surname); p3.Greetings(); //Console.WriteLine($"{p3.Name} {p3.Surname}"); Person4 p4 = new Person4(); p1._Name = "Tuana"; p1._Surname = "DEMİR"; p4.Age = 22; p4.FullName(p4.Name, p4.Surname); p4.Greetings(); //Console.WriteLine($"{p4.Name} {p4.Surname} {p4.Age}"); //-------------------------------------------------------------------------------------------------------------------------------------------------------- // KONU 4 : INHERITANCE (KALITIM / MİRASLAMA) Person5 p5 = new Person5(); p5.Greetings(); Person6 p6 = new Person6(); p6.Greetings(); //-------------------------------------------------------------------------------------------------------------------------------------------------------- // KONU 5 : ABSTRACT CLASS //Person7 p7 = new Person7(); >>> Abstract class' dan intance oluşturulamaz. Person8 p8 = new Person8(); p8.Greetings(); p8.GreetingsTR(); //-------------------------------------------------------------------------------------------------------------------------------------------------------- // KONU 6 : CONSTRUCTOR VE DESTRUCTOR METOTLAR Tructor tructor = new Tructor(); // Class' dan instance ürettiğim için constructor metodum otomatik çalışacak. string Name = "Gözde"; // Overload constructor metodum için parametre oluşturdum. Tructor tructor2 = new Tructor(Name); // Class' dan instance ürettiğim ve parametre oluşturduğum için overload constructor metodum otomatik çalışacak. }