public void CultureUpdateTest() { GXLanguage item = new GXLanguage() { Id = "fi", EnglishName = "Finland", }; GXUpdateArgs args = GXUpdateArgs.Update(item); args.Exclude <GXLanguage>(e => e.EnglishName); Assert.AreEqual("Mikko", args.ToString()); }
public void UpdateUserTest() { GXUser user = new GXUser(); user.Id = "1"; user.UserName = "******"; GXUpdateArgs arg2 = GXUpdateArgs.Update(user); arg2.Exclude <GXUser>(q => new { q.PasswordHash, q.SecurityStamp, q.CreationTime }); Assert.AreEqual("UPDATE [GXUser] SET [UserName] = 'Gurux', [NormalizedUserName] = NULL, [Email] = NULL, [NormalizedEmail] = NULL, [EmailConfirmed] = 0, [ConcurrencyStamp] = NULL, [PhoneNumber] = NULL, [PhoneNumberConfirmed] = 0, [TwoFactorEnabled] = 0, [LockoutEnd] = '00010101 00:00:00 +00:00', [LockoutEnabled] = 0, [AccessFailedCount] = 0, [Updated] = '00010101 00:00:00', [Detected] = '00010101 00:00:00', [Removed] = '00010101 00:00:00', [DateOfBirth] = NULL WHERE [ID] = '1'", arg2.ToString()); }
public void ExcludeUpdateTest() { string format = "yyyy-MM-dd HH:mm:ss"; DateTime dt = DateTime.ParseExact("2014-01-02 00:00:00", format, CultureInfo.CurrentCulture); TestClass t = new TestClass(); t.Id = 2; t.Time = DateTime.SpecifyKind(new DateTime(2014, 1, 2), DateTimeKind.Utc); GXUpdateArgs args = GXUpdateArgs.Update(t, x => new { x.Id, x.Guid, x.Time }); args.Exclude <TestClass>(x => new { x.Text, x.Text2, x.Text3, x.Text4, x.BooleanTest, x.IntTest, x.DoubleTest, x.FloatTest, x.Span, x.Object, x.Status }); Assert.AreEqual("UPDATE TestClass SET `ID` = 2, `Guid` = '00000000000000000000000000000000', `Time` = '" + dt.ToString(format) + "' WHERE `ID` = 2", args.ToString()); }
public void UpdateConfigurationTest() { List <GXConfigurationValue> list = new List <GXConfigurationValue>(); list.Add(new GXConfigurationValue() { Id = Guid.NewGuid(), Name = "SiteName", }); list.Add(new GXConfigurationValue() { Id = Guid.NewGuid(), Name = "Email", }); list.Add(new GXConfigurationValue() { Id = Guid.NewGuid(), Name = "Slogan", }); // GXInsertArgs insert = GXInsertArgs.InsertRange(list, c => new { c.Id, c.Generation }); GXUpdateArgs args = GXUpdateArgs.UpdateRange(list); args.Exclude <GXConfigurationValue>(e => e.Group); Assert.AreEqual("Mikko", args.ToString()); }
public ActionResult <UpdateDeviceResponse> Post(UpdateDevice request) { bool newDevice = request.Device.Id == 0; if (newDevice && request.Device.TemplateId == 0) { return(BadRequest("Device template ID is unknown.")); } if (request.Device.DeviceSystemTitle != null) { request.Device.DeviceSystemTitle = request.Device.DeviceSystemTitle.Replace(" ", ""); } if (request.Device.AuthenticationKey != null) { request.Device.AuthenticationKey = request.Device.AuthenticationKey.Replace(" ", ""); } if (request.Device.BlockCipherKey != null) { request.Device.BlockCipherKey = request.Device.BlockCipherKey.Replace(" ", ""); } if (newDevice) { DateTime now = DateTime.Now; request.Device.Generation = now; //Add new DC. List <GXObject> tmp = request.Device.Objects; request.Device.Objects = null; request.Device.Generation = now; host.Connection.Insert(GXInsertArgs.Insert(request.Device)); //Add default objects. GXSelectArgs arg = GXSelectArgs.SelectAll <GXObjectTemplate>(q => q.DeviceTemplateId == request.Device.TemplateId && q.Removed == DateTime.MinValue); arg.Columns.Add <GXAttributeTemplate>(); arg.Joins.AddLeftJoin <GXObjectTemplate, GXAttributeTemplate>(o => o.Id, a => a.ObjectTemplateId); arg.Where.And <GXAttributeTemplate>(q => q.Removed == DateTime.MinValue); List <GXObjectTemplate> l = host.Connection.Select <GXObjectTemplate>(arg); foreach (GXObjectTemplate it in l) { GXObject obj = new GXObject() { TemplateId = it.Id, Generation = now, DeviceId = request.Device.Id, ObjectType = it.ObjectType, Name = it.Name, LogicalName = it.LogicalName, ShortName = it.ShortName, Version = it.Version, }; host.Connection.Insert(GXInsertArgs.Insert(obj)); foreach (GXAttributeTemplate ait in it.Attributes) { GXAttribute a = new GXAttribute(); a.ObjectId = obj.Id; a.Index = ait.Index; a.TemplateId = ait.Id; a.AccessLevel = ait.AccessLevel; a.DataType = ait.DataType; a.UIDataType = ait.UIDataType; a.Generation = now; a.ExpirationTime = ait.ExpirationTime; obj.Attributes.Add(a); } ; host.Connection.Insert(GXInsertArgs.InsertRange(obj.Attributes)); } host.SetChange(TargetType.ObjectTemplate, DateTime.Now); } else { request.Device.Updated = DateTime.Now; GXUpdateArgs arg = GXUpdateArgs.Update(request.Device); //Device template ID is not updated. arg.Exclude <GXDevice>(q => q.TemplateId); host.Connection.Update(arg); host.SetChange(TargetType.DeviceTemplate, DateTime.Now); } return(new UpdateDeviceResponse() { DeviceId = request.Device.Id }); }