public async Task InsertEntity(IDbConnection dbConnection) { QueryHelper.FlushCache(); Model4 entity = new Model4() { Prop1 = "ENTITY 3", Prop2 = "READONLY PROP", Prop4 = 10 }; using (var connection = dbConnection) { connection.Open(); await connection.InsertAsync(entity); Assert.Equal(3, entity.Id); entity = await connection.GetAsync <Model4>(3); Assert.NotNull(entity); Assert.Equal("ENTITY 3", entity.Prop1); Assert.Equal("DEFAULT VALUE", entity.Prop2); Assert.Equal(0, entity.Prop4); connection.Close(); } }
public void ShouldMapComplexObjectList() { var data = new Model4 { Inner = new[] { new InnerModel4 { InnerStrProp = "str1" }, null, new InnerModel4() { InnerStrProp = "str2" } } }; var target = data.Map(ObjectMapper <Model4, Dto4> .Default); target.Should().BeEquivalentTo(new Dto4() { Inner = new List <InnerDto4> { new InnerDto4 { InnerStrProp = "str1" }, null, new InnerDto4 { InnerStrProp = "str2" } } }); }
public async Task UpdateEntity(IDbConnection dbConnection) { QueryHelper.FlushCache(); Model4 entity = null; bool found = true; using (var connection = dbConnection) { connection.Open(); entity = await connection.GetAsync <Model4>(2); entity.Prop1 = "ENTITY 2 UPDATED"; entity.Prop2 = "XXX"; entity.Prop4 = 10; found = await connection.UpdateAsync(entity); entity = await connection.GetAsync <Model4>(2); connection.Close(); } Assert.True(found); Assert.NotNull(entity); Assert.Equal("ENTITY 2 UPDATED", entity.Prop1); Assert.Equal("CUSTOM VALUE", entity.Prop2); Assert.Equal(0, entity.Prop4); }
public void RedrawModel4() { for (int i = 0; i < 5; i++) { (Model4.Series[i] as ScatterSeries).Points.Clear(); } for (int i = 0; i < 4; i++) { var ser = Model4.Series[i] as ScatterSeries; ser.Points.Capacity = ReceivedPoints.Count; } for (int i = 0; i < ReceivedPoints.Count; i++) { for (int j = 0; j < 4; j++) { var ser = Model4.Series[j] as ScatterSeries; if (ReceivedPoints[i][j] != null) { var sp = new ScatterPoint(ReceivedPoints[i][j].Value.X, ReceivedPoints[i][j].Value.Y); ser.Points.Add(sp); } } } var seq = from t in ReceivedPointsTrue from v in t select new ScatterPoint(v.X, v.Y); (Model4.Series[4] as ScatterSeries).Points.AddRange(seq); Model4.InvalidatePlot(false); }
public async Task DeleteEntityByKeyTuple(IDbConnection dbConnection) { QueryHelper.FlushCache(); Model4 entity = new Model4() { Prop1 = "ENTITY 10", Prop2 = "READONLY PROP", Prop4 = 10 }; bool found = false; using (var connection = dbConnection) { connection.Open(); connection.Insert(entity); var id = entity.Id; found = await connection.DeleteAsync <Model4>(ValueTuple.Create(id)); entity = await connection.GetAsync <Model4>(id); connection.Close(); } Assert.True(found); Assert.Null(entity); }
public void FindRulesForBaseClass() { var model = new Model4(); var property = model.GetType().GetProperty(nameof(model.Text)); var rules = this.sut.GetRulesForProperty(model.GetType(), property, RuleType.Default); Assert.IsNotNull(rules); Assert.IsTrue(rules.Any()); }
public void SingleModel_Immutable_ShouldReturnCorrectValue() { //arrange var modelContainerTarget = Target.The("Model container").LocatedBy(By.ClassName("model1")); var question = UIModel.Of <Model4>(modelContainerTarget).WithCulture(CultureInfo.GetCultureInfo("en-US")); //act var actual = Answer(question); //assert var expected = new Model4("The title", 1, true); actual.Should().BeEquivalentTo(expected); }
public async Task InsertManySingleShot(IDbConnection dbConnection) { QueryHelper.FlushCache(); Model4 entity1 = new Model4() { Prop1 = "ENTITY 10" }; Model4 entity2 = new Model4() { Prop1 = "ENTITY 11" }; var entities = new List <Model4>() { { entity1 }, { entity2 } }; using (var connection = dbConnection) { connection.Open(); var all = await connection.GetAllAsync <Model4>(); var lastId = all.Last().Id; var entity1Id = lastId + 1; var entity2Id = lastId + 2; var count = await connection.InsertManyAsync(entities, insertMode : OperationMode.SingleShot); Assert.Equal(entity1Id, entity1.Id); Assert.Equal(entity2Id, entity2.Id); Assert.Equal(2, count); entity1 = await connection.GetAsync <Model4>(entity1Id); Assert.NotNull(entity1); Assert.Equal("ENTITY 10", entity1.Prop1); Assert.Equal("DEFAULT VALUE", entity1.Prop2); Assert.Equal(0, entity1.Prop4); entity2 = await connection.GetAsync <Model4>(entity2Id); Assert.NotNull(entity2); Assert.Equal("ENTITY 11", entity2.Prop1); Assert.Equal("DEFAULT VALUE", entity2.Prop2); Assert.Equal(0, entity2.Prop4); connection.Close(); } }
public async Task UpdateMany(IDbConnection dbConnection) { QueryHelper.FlushCache(); Model4 entity1 = null; Model4 entity2 = null; bool found = true; using (var connection = dbConnection) { connection.Open(); entity1 = await connection.GetAsync <Model4>(1); entity2 = await connection.GetAsync <Model4>(2); entity1.Prop1 = "ENTITY 1 UPDATED"; entity1.Prop2 = "XXX"; entity1.Prop4 = 10; entity2.Prop1 = "ENTITY 2 UPDATED"; entity2.Prop2 = "XXX"; entity2.Prop4 = 10; var entities = new List <Model4>() { { entity1 }, { entity2 } }; found = await connection.UpdateManyAsync(entities as IEnumerable <Model4>); entity1 = await connection.GetAsync <Model4>(1); entity2 = await connection.GetAsync <Model4>(2); connection.Close(); } Assert.True(found); Assert.NotNull(entity1); Assert.Equal("ENTITY 1 UPDATED", entity1.Prop1); Assert.Equal("DEFAULT VALUE", entity1.Prop2); Assert.Equal(0, entity1.Prop4); Assert.NotNull(entity2); Assert.Equal("ENTITY 2 UPDATED", entity2.Prop1); Assert.Equal("CUSTOM VALUE", entity2.Prop2); Assert.Equal(0, entity2.Prop4); }
public async Task GetNonExistingEntity(IDbConnection dbConnection) { QueryHelper.FlushCache(); Model4 entity = null; using (var connection = dbConnection) { connection.Open(); entity = await connection.GetAsync <Model4>(10); connection.Close(); } Assert.Null(entity); }
public async Task ExistsEntity(IDbConnection dbConnection) { QueryHelper.FlushCache(); bool exists = false; var key = new Model4 { Id = 1 }; using (var connection = dbConnection) { connection.Open(); exists = await connection.ExistsAsync(key); connection.Close(); } Assert.True(exists); }
public void GetGraphics() { int N = 5; if (Model4.Series.Count == N) { Model4.Series.Add(new LineSeries { Title = "t фактич траектории 1", Color = OxyColors.SkyBlue }); Model4.Series.Add(new LineSeries { Title = "t фактич траектории 2", Color = OxyColors.DarkBlue }); Model4.Series.Add(new LineSeries { Title = "t фактич траектории 3", Color = OxyColors.MediumVioletRed }); Model4.Series.Add(new LineSeries { Title = "t фактич траектории 4", Color = OxyColors.ForestGreen }); } for (int i = N; i < N + 4; i++) { (Model4.Series[i] as LineSeries).Points.Clear(); } for (int i = 0; i < N; i++) { int n = 0; for (int j = 0; j < ReceivedPoints.Count; j++) { if (ReceivedPoints[j][i].HasValue) { n++; } (Model4.Series[i + N] as LineSeries).Points.Add(new DataPoint(j, (double)n / (j + 1))); } } Model4.InvalidatePlot(false); }
public async Task GetEntityById(IDbConnection dbConnection) { QueryHelper.FlushCache(); Model4 entity = null; using (var connection = dbConnection) { connection.Open(); entity = await connection.GetAsync <Model4>(1); connection.Close(); } Assert.NotNull(entity); Assert.Equal(1, entity.Id); Assert.Equal("ENTITY 1", entity.Prop1); Assert.Equal("DEFAULT VALUE", entity.Prop2); Assert.Equal(0, entity.Prop4); }
public async Task DeleteNonExistingEntity(IDbConnection dbConnection) { QueryHelper.FlushCache(); Model4 entity = new Model4() { Id = 10 }; bool found = false; using (var connection = dbConnection) { connection.Open(); found = await connection.DeleteAsync(entity); connection.Close(); } Assert.False(found); }
public async Task DeleteMany(IDbConnection dbConnection) { QueryHelper.FlushCache(); var entities = new List <Model4>() { { new Model4() { Prop1 = "ENTITY 10" } }, { new Model4() { Prop1 = "ENTITY 11" } } }; bool found = false; Model4 entity1 = null; Model4 entity2 = null; using (var connection = dbConnection) { connection.Open(); await connection.InsertManyAsync <Model4>(entities); found = await connection.DeleteManyAsync <Model4>(entities); entity1 = await connection.GetAsync <Model4>(entities.First().Id); entity2 = await connection.GetAsync <Model4>(entities.Skip(1).First().Id); connection.Close(); } Assert.True(found); Assert.Null(entity1); Assert.Null(entity2); }
public async Task UpdateNonExistingEntity(IDbConnection dbConnection) { QueryHelper.FlushCache(); Model4 entity = new Model4(); entity.Id = 10; entity.Prop1 = "ENTITY 10"; entity.Prop2 = "XXX"; entity.Prop4 = 10; bool found = true; using (var connection = dbConnection) { connection.Open(); found = await connection.UpdateAsync(entity); connection.Close(); } Assert.False(found); }
public void AttachModelList(List <Object3D> objs) { for (int i = 0; i < objs.Count; ++i) { var ob = objs[i]; var vertColor = new Color4((float)i / objs.Count, 0, 1 - (float)i / objs.Count, 1); ob.Geometry.Colors = new HelixToolkit.Wpf.SharpDX.Core.Color4Collection(Enumerable.Repeat(vertColor, ob.Geometry.Positions.Count)); ob.Geometry.UpdateOctree(); ob.Geometry.UpdateBounds(); context.Post((o) => { var scaleTransform = new Media3D.ScaleTransform3D(15, 15, 15); var s = new MeshGeometryModel3D { Geometry = ob.Geometry, CullMode = SharpDX.Direct3D11.CullMode.Back, IsThrowingShadow = true, Transform = scaleTransform }; var diffuseMaterial = new DiffuseMaterial(); PBRMaterial pbrMaterial = null; if (ob.Material is PhongMaterialCore p) { var phong = p.ConvertToPhongMaterial(); phong.RenderEnvironmentMap = true; phong.RenderShadowMap = true; phong.RenderSpecularColorMap = false; s.Material = phong; diffuseMaterial.DiffuseColor = p.DiffuseColor; diffuseMaterial.DiffuseMap = p.DiffuseMap; pbrMaterial = new PBRMaterial() { AlbedoColor = p.DiffuseColor, AlbedoMap = p.DiffuseMap, NormalMap = p.NormalMap, RMAMap = p.SpecularColorMap, RenderShadowMap = true, RenderEnvironmentMap = true, }; } //if (ob.Transform != null && ob.Transform.Count > 0) //{ // s.Instances = ob.Transform; //} this.Model1.Add(s); Model2.Add(new MeshGeometryModel3D() { Geometry = ob.Geometry, CullMode = SharpDX.Direct3D11.CullMode.Back, IsThrowingShadow = true, Material = NormalMaterial, Transform = scaleTransform }); ModelNormalVector.Add(new MeshGeometryModel3D() { Geometry = ob.Geometry, CullMode = SharpDX.Direct3D11.CullMode.Back, IsThrowingShadow = true, Material = NormalVectorMaterial, Transform = scaleTransform }); Model3.Add(new MeshGeometryModel3D() { Geometry = ob.Geometry, CullMode = SharpDX.Direct3D11.CullMode.Back, IsThrowingShadow = true, Material = diffuseMaterial, Transform = scaleTransform }); Model4.Add(new MeshGeometryModel3D() { Geometry = ob.Geometry, CullMode = SharpDX.Direct3D11.CullMode.Back, IsThrowingShadow = true, Material = PositionMaterial, Transform = scaleTransform }); Model5.Add(new MeshGeometryModel3D() { Geometry = ob.Geometry, CullMode = SharpDX.Direct3D11.CullMode.Back, IsThrowingShadow = true, Material = VertMaterial, Transform = scaleTransform }); Model6.Add(new MeshGeometryModel3D() { Geometry = ob.Geometry, CullMode = SharpDX.Direct3D11.CullMode.Back, IsThrowingShadow = true, Material = ColorStripeMaterial, Transform = scaleTransform }); Model7.Add(new MeshGeometryModel3D { Geometry = ob.Geometry, CullMode = SharpDX.Direct3D11.CullMode.Back, IsThrowingShadow = true, Transform = scaleTransform, Material = pbrMaterial }); }, null); } }
public async Task PublishExceptionsWithHighPriority() { Registrar registrar = new Registrar(); TestHorseMq server = new TestHorseMq(); server.SendAcknowledgeFromMQ = false; await server.Initialize(); int port = server.Start(300, 300); IRouter router1 = server.Server.AddRouter("ex-route-1", RouteMethod.Distribute); IRouter router2 = server.Server.AddRouter("ex-route-2", RouteMethod.Distribute); IRouter router3 = server.Server.AddRouter("ex-route-3", RouteMethod.Distribute); router1.AddBinding(new QueueBinding("bind-1", "ex-queue-1", 0, BindingInteraction.None)); router2.AddBinding(new QueueBinding("bind-2", "ex-queue-2", 0, BindingInteraction.None)); router3.AddBinding(new QueueBinding("bind-3", "ex-queue-3", 0, BindingInteraction.None)); HmqStickyConnector producer = new HmqAbsoluteConnector(TimeSpan.FromSeconds(10)); producer.AddHost("hmq://localhost:" + port); producer.Run(); HmqStickyConnector consumer = new HmqAbsoluteConnector(TimeSpan.FromSeconds(10)); consumer.AddHost("hmq://localhost:" + port); registrar.Register(consumer); consumer.Run(); await Task.Delay(500); Assert.True(producer.IsConnected); Assert.True(consumer.IsConnected); Model4 model = new Model4(); HorseResult push1 = await producer.Bus.Queue.PushJson(model, true); Assert.Equal(HorseResultCode.Failed, push1.Code); await Task.Delay(100); Assert.Equal(1, ExceptionConsumer1.Instance.Count); Assert.Equal(0, ExceptionConsumer2.Instance.Count); Assert.Equal(0, ExceptionConsumer3.Instance.Count); HorseResult push2 = await producer.Bus.Queue.PushJson(model, true); Assert.Equal(HorseResultCode.Failed, push2.Code); await Task.Delay(100); Assert.Equal(1, ExceptionConsumer1.Instance.Count); Assert.Equal(1, ExceptionConsumer2.Instance.Count); Assert.Equal(0, ExceptionConsumer3.Instance.Count); HorseResult push3 = await producer.Bus.Queue.PushJson(model, true); Assert.Equal(HorseResultCode.Failed, push3.Code); await Task.Delay(100); Assert.Equal(1, ExceptionConsumer1.Instance.Count); Assert.Equal(1, ExceptionConsumer2.Instance.Count); Assert.Equal(1, ExceptionConsumer3.Instance.Count); Assert.Equal(3, QueueConsumer4.Instance.Count); }
public void TestCopyValue() { var m1 = new Model1 { P1 = "P1", P2 = "P2", P3 = "P3", P4 = "P4", P5 = "P5", P6 = 6, PP = "P7", P8 = new Model3 { P1 = "P3-P1" }, P9 = new List <Model4> { new Model4 { P1 = "1-P4-P1" }, new Model4 { P1 = "2-P4-P1" } }, P10 = 10 }; // Verifies that pass a null object Assert.Throws <ArgumentNullException>(() => { m1.CopyValueTo(null); }); // Verifies that set value between different type var m2 = new Model2 { P1 = -10 }; Assert.Throws <InvalidTypeConvertedException>(() => { m1.CopyValueTo(m2); }); // Verifies that successful var m3 = new Model3 { p5 = "-p5" }; m1.CopyValueTo(m3); Assert.Equal("P1", m3.P1); Assert.Equal("P2", m3.P2); Assert.Equal("P3", m3.P3); Assert.Equal("-p5", m3.p5); Assert.Equal(6, m3.P6); Assert.Null(m3.P7); // Verifies that ignore case m1.CopyValueTo(target: m3, stringComparison: StringComparison.CurrentCultureIgnoreCase); Assert.Equal("P5", m3.p5); // Verifies that ignore property m3 = new Model3(); m1.CopyValueTo(target: m3, ignorePropertyNames: new string[] { "P1", "P2" }); Assert.Null(m3.P1); Assert.Null(m3.P2); // Verifies that ignore property m3 = new Model3(); var map = new Dictionary <string, string>(); map.Add("PP", "P7"); m1.CopyValueTo(target: m3, propertyMap: map); Assert.Equal("P7", m3.P7); // Verifies that throw MultipleResultException if ignore case var m4 = new Model4(); Assert.Throws <MultipleResultException>(() => { m1.CopyValueTo(target: m4, stringComparison: StringComparison.CurrentCultureIgnoreCase); }); // Verifies that copy value type and ref type var m5 = new Model5(); m1.CopyValueTo(m5, ignoreRefType: false); Assert.True(m1.P8 == m5.P8); Assert.True(m1.P9 == m5.P9); Assert.True(m1.P10.ToString() == m5.P10.ToString()); // Verifies that ignore ref type m5 = new Model5(); m1.CopyValueTo(m5); Assert.Null(m5.P8); Assert.Null(m5.P9); Assert.Equal(0, m5.P10); // Verifies that force property names m5 = new Model5(); m1.CopyValueTo(m5, forcePropertyNames: new string[] { "P10" }); Assert.Null(m5.P8); Assert.Null(m5.P9); Assert.Equal(10, m5.P10); }
public ActionResult Example4(Model4 model) => this.View("example4.partial", model);
public DetailDao() { db = new Model4(); }