public override async Task Generate(ServiceClient serviceClient) { var viewModel = new SampleViewModel(); var model = new SampleModel(); model.Model = viewModel; await Write(model, "Models\\Pet.cs"); }
public override async Task Generate(ServiceClient serviceClient) { var viewModel = new SampleViewModel(); var model = new SampleModel(); model.Model = viewModel; await Write(model, Path.Combine("Models", "Pet.cs")); }
public IHttpActionResult Patch(Delta<SampleModel> delta) { // Using the Patch method on Delta<T>, will only overwrite only the properties whose value has // changed. var model = new SampleModel(); delta.Patch(model); // Using Delta doesn't invoke validation on the values that are provided, so use the Validate method // on the model object after patching to validate it. this.Validate(model); if (!ModelState.IsValid) { return BadRequest(ModelState); } var builder = new StringBuilder(); builder.AppendLine("Updated Properties:"); foreach(var property in delta.GetChangedPropertyNames()) { object value; delta.TryGetPropertyValue(property, out value); builder.AppendLine(String.Format("\t{0} : {1}", property, value)); } return Text(builder.ToString()); }
public override async Task Generate(CodeModel codeModel) { var viewModel = new SampleViewModel(); var model = new SampleModel(); model.Model = viewModel; await Write(model, Path.Combine(Settings.Instance.ModelsName, "Pet.cs")); }
public void CodeWriterWrapsComments() { var sampleModelTemplate = new SampleModel(); var sampleViewModel = new SampleViewModel(); sampleModelTemplate.Model = sampleViewModel; var output = sampleModelTemplate.ToString(); Assert.True(output.ContainsMultiline(@"/// Deserialize current type to Json object because today is Friday /// and there is a sun outside the window.")); }
public void CodeWriterWritesCRefAttribute() { var sampleModelTemplate = new SampleModel(); var sampleViewModel = new SampleViewModel(); sampleModelTemplate.Model = sampleViewModel; var output = sampleModelTemplate.ToString(); Assert.True(output.Contains("/// <exception cref=\"CloudException\">")); Assert.True(output.Contains("/// <exception cref=\"ArgumentNullException\">")); }
public void CanSerializableDateTimeOffsetField() { var model = new SampleModel { Id = 1, Date = new DateTimeOffset(2012, 6, 27, 11, 26, 04, 524, TimeSpan.FromHours(7)) }; var s = JsonSerializer.SerializeToString(model); var afterModel = JsonSerializer.DeserializeFromString<SampleModel>("{\"Id\":1,\"Date\":\"\\/Date(1340771164524+0700)\\/\"}"); Assert.AreEqual(model.Date, afterModel.Date); }
public void Can_serialize_TimeSpan_field_with_StandardTimeSpanFormat() { using (JsConfig.With(timeSpanHandler:TimeSpanHandler.StandardFormat)) { var period = TimeSpan.FromSeconds(70); var model = new SampleModel { Id = 1, TimeSpan = period }; var json = JsonSerializer.SerializeToString(model); Assert.That(json, Is.StringContaining("\"TimeSpan\":\"00:01:10\"")); } }
public void Can_serialize_TimeSpan_field_with_StandardTimeSpanFormat() { var period = TimeSpan.FromSeconds(70); JsConfig.TimeSpanHandler = JsonTimeSpanHandler.StandardFormat; var model = new SampleModel { Id = 1, TimeSpan = period }; var json = JsonSerializer.SerializeToString(model); Assert.That(json, Is.StringContaining("\"TimeSpan\":\"00:01:10\"")); JsConfig.TimeSpanHandler = JsonTimeSpanHandler.DurationFormat; //Revert so no other tests are affected }
public ActionResult TestSample() { var sampleModel = new SampleModel { Name = "Bob Jackson", CurrentDate = DateTime.Now }; _service.Add(sampleModel); _unitOfWork.Commit(); return View(); }
public void Can_serialize_TimeSpan_field() { var fromDate = new DateTime(2069, 01, 02); var toDate = new DateTime(2079, 01, 02); var period = toDate - fromDate; var model = new SampleModel { Id = 1, TimeSpan = period }; var json = JsonSerializer.SerializeToString(model); Assert.That(json, Is.StringContaining("\"TimeSpan\":\"P3652D\"")); //Behaviour of .NET's BCL classes //JsonDataContractSerializer.Instance.SerializeToString(model).Print(); //DataContractSerializer.Instance.Parse(model).Print(); Serialize(model); }
public void Can_Serializable_DateTimeOffset_Field() { var model = new SampleModel { Id = 1, Date = new DateTimeOffset(2012, 6, 27, 11, 26, 04, 524, TimeSpan.FromHours(7)) }; //Behaviour of .NET's BCL classes //JsonDataContractSerializer.Instance.SerializeToString(model).Print(); //DataContractSerializer.Instance.Parse(model).Print(); var json = JsonSerializer.SerializeToString(model); Assert.That(json, Is.StringContaining("\"TimeSpan\":\"PT0S\"")); var fromJson = json.FromJson<SampleModel>(); Assert.That(model.Date, Is.EqualTo(fromJson.Date)); Assert.That(model.TimeSpan, Is.EqualTo(fromJson.TimeSpan)); Serialize(fromJson); }
public ActionResult QueueSample() { var sampleModel = new SampleModel { Name = "Jim Carey", CurrentDate = DateTime.Now }; _service.Add(sampleModel); /*using (_unitOfWork) { _service.Add(sampleModel); }*/ return View(); }
public void CreateDocument() { const string sampleKey = "sample::1234"; var repo = new SampleModelRepository(); var model = new SampleModel { Key = sampleKey, SampleProperty = 99 }; var savedModel = repo.CreateDocument(model); Assert.AreEqual(model.SampleProperty, savedModel.SampleProperty); // validate that the created at property was set since we used the create document method Assert.IsNotNull(savedModel.CreatedAt); // cleanup after ourselves repo.RemoveDocument(sampleKey); }
//硬度参数变化时 private void sampleHardnessCombox_SelectedIndexChanged(object sender, EventArgs e) { try { //存入ini ini.IniWriteValue("样本数据", "sampleHardness", ((ComboBox)sender).SelectedItem.ToString()); if (sampleModel.sampleNo != "") { //存入json String dataJson = Util.read2File("data/" + sampleModel.sampleNo + ".json", FileMode.Open, FileAccess.Read); if (JsonSplit.IsJson(dataJson)) { sampleModel = Util.JsonToObj <SampleModel>(dataJson); sampleModel.sampleHardness = ((ComboBox)sender).SelectedItem.ToString(); sampleModel.sampleProject = ((ComboBox)sender).SelectedItem.ToString(); //获取数据 List <String> matchData = Util.getMatchData(Util.read2File("data/" + sampleModel.sampleNo + ".txt", FileMode.Open, FileAccess.Read), sampleModel.sampleHardness + @":\s+(\d+\.\d)"); sampleModel.data = matchData; setCountText(sampleModel.data.Count.ToString()); //如果当前datagridview中有数据,则重新排列gridview if (comDataManager != null) { comDataManager.resetData(Int32.Parse(sampleModel.samplePointNum), sampleModel.data); } Util.write2File("data/" + sampleModel.sampleNo + ".json", Util.ObjToJson <SampleModel>(sampleModel), System.IO.FileMode.Create, System.IO.FileAccess.Write); sampleModel.data.Clear(); System.GC.Collect(); } } } catch (Exception err) { log.Error(err.ToString()); MessageBox.Show("项目切换失败", "提示"); } }
private void samplePointNum_SelectedIndexChanged(object sender, EventArgs e) { //存入ini ini.IniWriteValue("样本数据", "samplePointNum", ((ComboBox)sender).SelectedIndex.ToString()); //存入json if (sampleModel.sampleNo != "") { String dataJson = Util.read2File("data/" + sampleModel.sampleNo + ".json", FileMode.Open, FileAccess.Read); if (JsonSplit.IsJson(dataJson)) { sampleModel = Util.JsonToObj <SampleModel>(dataJson); sampleModel.samplePointNum = ((ComboBox)sender).SelectedItem.ToString(); //如果当前datagridview中有数据,则重新排列gridview if (comDataManager != null) { comDataManager.resetData(Int32.Parse(sampleModel.samplePointNum), sampleModel.data); } Util.write2File("data/" + sampleModel.sampleNo + ".json", Util.ObjToJson <SampleModel>(sampleModel), System.IO.FileMode.Create, System.IO.FileAccess.Write); sampleModel.data.Clear(); System.GC.Collect(); } } }
public async Task ItShouldPostJson() { var sampleModel = new SampleModel(); HttpResponseMessage passthroughResponse = null; await ExecuteModeIterations(async (client, mode) => { var response = await client.PostAsJsonAsync(ApiController.JsonUri, sampleModel); response.EnsureSuccessStatusCode(); response.Headers.Remove("Date"); if (mode == HttpRecorderMode.Passthrough) { passthroughResponse = response; var result = await response.Content.ReadAsAsync <SampleModel>(); result.Name.Should().Be(sampleModel.Name); } else { response.Should().BeEquivalentTo(passthroughResponse); } }); }
// // ==================================================================================================== // public override object Execute(CPBaseClass CP) { const string designBlockName = "Tile Design Block"; try { // // -- read instanceId, guid created uniquely for this instance of the addon on a page var result = string.Empty; var settingsGuid = DesignBlockController.getSettingsGuid(CP, designBlockName, ref result); if ((string.IsNullOrEmpty(settingsGuid))) { return(result); } // // -- locate or create a data record for this guid var settings = SampleModel.createOrAddSettings(CP, settingsGuid); if ((settings == null)) { throw new ApplicationException("Could not create the design block settings record."); } // // -- translate the Db model to a view model and mustache it into the layout var viewModel = SampleViewModel.create(CP, settings); if ((viewModel == null)) { throw new ApplicationException("Could not create design block view model."); } result = Nustache.Core.Render.StringToString(Properties.Resources.SampleLayout, viewModel); // // -- if editing enabled, add the link and wrapperwrapper return(CP.Content.GetEditWrapper(result, SampleModel.tableMetadata.contentName, settings.id)); } catch (Exception ex) { CP.Site.ErrorReport(ex); return("<!-- " + designBlockName + ", Unexpected Exception -->"); } }
public void Test_ObservablePropertyAttributeRightBelowRegion_Events() { var model = new SampleModel(); (PropertyChangingEventArgs, string?)changing = default; (PropertyChangedEventArgs, string?)changed = default; model.PropertyChanging += (s, e) => { Assert.IsNull(changing.Item1); Assert.IsNull(changed.Item1); Assert.AreSame(model, s); Assert.IsNotNull(s); Assert.IsNotNull(e); changing = (e, model.Name); }; model.PropertyChanged += (s, e) => { Assert.IsNotNull(changing.Item1); Assert.IsNull(changed.Item1); Assert.AreSame(model, s); Assert.IsNotNull(s); Assert.IsNotNull(e); changed = (e, model.Name); }; model.Name = "Bob"; Assert.AreEqual(changing.Item1?.PropertyName, nameof(SampleModel.Name)); Assert.AreEqual(changing.Item2, null); Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModel.Name)); Assert.AreEqual(changed.Item2, "Bob"); }
public void Test_ObservablePropertyAttribute_Events() { var model = new SampleModel(); (PropertyChangingEventArgs, int)changing = default; (PropertyChangedEventArgs, int)changed = default; model.PropertyChanging += (s, e) => { Assert.IsNull(changing.Item1); Assert.IsNull(changed.Item1); Assert.AreSame(model, s); Assert.IsNotNull(s); Assert.IsNotNull(e); changing = (e, model.Data); }; model.PropertyChanged += (s, e) => { Assert.IsNotNull(changing.Item1); Assert.IsNull(changed.Item1); Assert.AreSame(model, s); Assert.IsNotNull(s); Assert.IsNotNull(e); changed = (e, model.Data); }; model.Data = 42; Assert.AreEqual(changing.Item1?.PropertyName, nameof(SampleModel.Data)); Assert.AreEqual(changing.Item2, 0); Assert.AreEqual(changed.Item1?.PropertyName, nameof(SampleModel.Data)); Assert.AreEqual(changed.Item2, 42); }
public void Generic_Object_MemberName() { var model = new SampleModel(); MakeSure.That(model.MemberName(i => i.Age)).Is("Age"); }
public void EnumValueInfoDropdownFor_NonNullable_WithSampleValue() { var model = new SampleModel(); model.SomeOption = TestEnum.Foo; var helper = MvcHelper.GetHtmlHelper(new ViewDataDictionary<SampleModel>(model)); var html = helper.DropDownListEnumExtendedInfoFor(x => x.SomeOption); Assert.AreEqual(@"<select name='SomeOption'><option value=""0"">Boos</option><option value=""1"" selected='selected'>Foo</option></select>", html.ToHtmlString()); Console.Out.WriteLine(html.ToHtmlString()); }
public SampleModel Test1(int param1) { var item = SampleModel.CreateSampleWithCultureInfo(); return(item); }
public IActionResult SamplePost([FromBody] SampleModel sampleModel, [FromQuery] int someId) { return(Ok($"{sampleModel.Id} => {sampleModel.Description} => {someId}")); }
public override async Task <IList <IEvent> > ProcessAction(int actionNumber) { if (actionNumber == 1) // User clicked cancel { return(new List <IEvent>() { new CancelInputDialog() }); } else if (actionNumber == 0) // user clicked submit { Logger.Info("Processing submit action in advanced modify"); var id = GetValue("Id"); var text = GetValue("Text"); var number = GetValue <int>("Number"); var date = GetValue <DateTime?>("Date"); var longText = GetValue("Long"); var category = GetDataSourceValue <SampleCategory>("Category"); if (date == null) { // Example of doing additional validation in code and returning a message // There is already a setting for mandatory check on the client side to eliminate extra network requests. // But always good to check mandatory values in code also return(new List <IEvent>() { new ShowMessage("Date is mandatory") }); } using (var session = DataService.OpenSession()) { SampleModel dbItem; if (IsNew) { dbItem = new SampleModel(); } else { dbItem = session.Get <SampleModel>(id); } dbItem.StringValue = text; dbItem.NumberValue = number; if (date != null) { dbItem.DateValue = (DateTime)date; } dbItem.Category = category; dbItem.LongTestValue = longText; DataService.SaveOrUpdate(session, dbItem); // Using saveOrUpdate adds this task to audit log //session.SaveOrUpdate(dbItem); // this won't be audited session.Flush(); } return(new List <IEvent>() { new ShowMessage("Item successfully " + (IsNew ? "added" : "modified")), new CancelInputDialog(), new ExecuteAction(MenuNumber.AdvancedView) }); } else { return(null); } }
public void GetDocument() { const string sampleKey = "sample::9999"; // setup a sample document to retrieve for the get document test var repo = new SampleModelRepository(); var model = new SampleModel { Key = sampleKey, SampleProperty = 99 }; repo.SaveDocument(model); var retrievedDocument = repo.GetDocument(sampleKey); Assert.AreEqual(sampleKey, retrievedDocument.Key); Assert.AreEqual(model.SampleProperty, retrievedDocument.SampleProperty); // cleanup after our test repo.RemoveDocument(sampleKey); }
public void UpdateWithRetry() { const string sampleKey = "sample::0000000000"; var repo = new SampleModelRepository(); repo.RemoveDocument(sampleKey); var model0 = new SampleModel { Key = sampleKey, SampleProperty = 1, }; model0 = repo.CreateDocument(model0); var model1 = repo.GetDocument(sampleKey); var model2 = repo.GetDocument(sampleKey); model1.SampleProperty = model0.SampleProperty + 1; model1 = repo.SaveDocument(model1); var count = 0; model2 = repo.UpdateDocumentWithRetry(model2, model => { count += 1; if (count == 1) { model1.SampleProperty = model1.SampleProperty + 1; repo.SaveDocument(model1); } model.SampleProperty = model.SampleProperty + 1; }); Assert.AreEqual(2, count); var model3 = repo.GetDocument(sampleKey); Assert.AreEqual(3, model1.SampleProperty); Assert.AreEqual(4, model2.SampleProperty); Assert.AreEqual(4, model3.SampleProperty); repo.RemoveDocument(sampleKey); }
public void SaveDocument() { const string sampleKey = "sample::9876"; var currentDate = DateTime.Now; var repo = new SampleModelRepository(); var model = new SampleModel { Key = sampleKey, SampleProperty = 10, CreatedAt = currentDate }; var savedModel = repo.SaveDocument(model); Assert.AreEqual(model.SampleProperty, savedModel.SampleProperty); Assert.IsNotNull(savedModel.CreatedAt); // validate that the created at property was not set by the repository since we used the save document method Assert.AreEqual(currentDate, savedModel.CreatedAt); // cleanup after ourselves repo.RemoveDocument(sampleKey); }
public string Post2([FromFormJson] SampleModel loginData, IFormFile photo) { return(null); }
public string Post([FromBody] SampleModel loginData, [FromServices] SampleService jwt) { return(jwt.JwtHelper.BuildToken("userId")); }
public void Validate_ReturnsMemberName_IfItIsDifferentFromDisplayName() { // Arrange var metadata = _metadataProvider.GetMetadataForType(typeof(SampleModel)); var model = new SampleModel(); var attribute = new Mock<TestableValidationAttribute> { CallBase = true }; attribute .Setup(p => p.IsValidPublic(It.IsAny<object>(), It.IsAny<ValidationContext>())) .Returns(new ValidationResult("Name error", new[] { "Name" })); var validator = new DataAnnotationsModelValidator( new ValidationAttributeAdapterProvider(), attribute.Object, stringLocalizer: null); var validationContext = new ModelValidationContext( actionContext: new ActionContext(), modelMetadata: metadata, metadataProvider: _metadataProvider, container: null, model: model); // Act var results = validator.Validate(validationContext); // Assert ModelValidationResult validationResult = Assert.Single(results); Assert.Equal("Name", validationResult.MemberName); }
public void TestInitialize() { model = new SampleModel(); }
public ActionResult Save(SampleModel model) { return(View("Index", model)); }
/// <summary> /// Update /// </summary> /// <param name="mObj"></param> /// <returns></returns> public void Update(SampleModel mObj) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("update Sample set "); StringBuilder sbCondition = new StringBuilder(); if (mObj.Code != null) { if (sbCondition.Length > 0) { sbCondition.Append(","); } sbCondition.AppendFormat(" Code = '{0}' ", mObj.Code); } if (mObj.TrueValue != null) { if (sbCondition.Length > 0) { sbCondition.Append(","); } sbCondition.AppendFormat(" TrueValue = '{0}' ", mObj.TrueValue); } if (mObj.SecuritySiteId != null) { if (sbCondition.Length > 0) { sbCondition.Append(","); } sbCondition.AppendFormat(" SecuritySiteId = '{0}' ", mObj.SecuritySiteId); } if (mObj.Backup1 != null) { if (sbCondition.Length > 0) { sbCondition.Append(","); } sbCondition.AppendFormat(" Backup1 = '{0}' ", mObj.Backup1); } if (mObj.Backup2 != null) { if (sbCondition.Length > 0) { sbCondition.Append(","); } sbCondition.AppendFormat(" Backup2 = '{0}' ", mObj.Backup2); } strSql.Append(sbCondition.ToString()); strSql.AppendFormat(" where [Code]='{0}'", mObj.Code); object ret = Sqlite.ExecuteNonQuery(strSql.ToString()); } catch (Exception ex) { throw ex; } finally { } }
protected override void OnNavigatedTo(NavigationEventArgs e) { Item = e.Parameter as SampleModel; }
private bool Equals(SampleModel other) { return(Id == other.Id && string.Equals(Name, other.Name) && string.Equals(Address, other.Address)); }
public void CalcTest() { Assert.AreEqual(3, SampleModel.Calc(1, 2)); }
public void UpdateDocument() { const string sampleKey = "sample::4567"; var currentDate = DateTime.Now; const int updateValue = 234; var repo = new SampleModelRepository(); var model = new SampleModel { Key = sampleKey, SampleProperty = 9, CreatedAt = currentDate }; var savedModel = repo.SaveDocument(model); savedModel.SampleProperty = updateValue; var updatedModel = repo.UpdateDocument(savedModel); // ensure the model was updated Assert.AreEqual(updateValue, updatedModel.SampleProperty); // cleanup after ourselves repo.RemoveDocument(sampleKey); }
public IActionResult MultiSelectPost(SampleModel userInput) { return(View("MultiSelectDetails", userInput)); }
/// <summary> /// 更改通道数据的采样类型 /// </summary> /// <param name="smp"></param> public void SetSamplingModel(SampleModel smp) { DataSampling.smp = smp; }
public MainWindowViewModel() { this.model = new SampleModel(); myData = new ObservableCollection <Person>(model.GenerateSampleData()); }
public IActionResult Post(SampleModel model) { return(Ok(model)); }
public void Vector3DTest() { var tolLen = model.MUDomain.Length.DefaultTolerance; var tolRad = model.MUDomain.PlaneAngle.DefaultTolerance; // length Assert.True(new Vector3D(1, 5.9, 4).Length.EqualsTol(tolLen, 7.198)); // normalized Assert.True(new Vector3D(1, 5.9, 4).Normalized().EqualsTol(Constants.NormalizedLengthTolerance, new Vector3D(0.13893, 0.81968, 0.55572))); // distance Assert.True(new Vector3D(1, 5.9, 4).Distance(new Vector3D(3, 4.3, 1.03)).EqualsTol(tolLen, 3.9218)); // dot product Assert.True(new Vector3D(5, 1, 3).DotProduct(new Vector3D(5, 4, 6)).EqualsTol(tolLen, 47)); // cross product Assert.True(new Vector3D(2, 4, 12).CrossProduct(new Vector3D(3, 6, 1)).EqualsTol(tolLen, new Vector3D(-68, 34, 0))); // angle rad Assert.True(new Vector3D(3.48412, 2.06577, 0).AngleRad(tolLen, new Vector3D(1.4325, 2.70248, 0)).EqualsTol(tolRad, 0.548)); Assert.True(new Vector3D(.231334209442139, .143270492553711) .AngleRad(Constants.NormalizedLengthTolerance, new Vector3D(-.224979639053345, -.153055667877197)) .EqualsTol(tolRad, (177.54306).ToRad())); // angle rad Assert.True(new Vector3D(3.48412, 2.06577, 0).AngleRad(tolLen, new Vector3D(-3.48412, -2.066, 0)).EqualsTol(tolRad, PI)); // angle contained Assert.True(340d.ToRad().AngleInRange(tolRad, 330d.ToRad(), 3d.ToRad())); Assert.True(0d.ToRad().AngleInRange(tolRad, 330d.ToRad(), 3d.ToRad())); // vector projection Assert.True(new Vector3D(101.546, 25.186, 1.3).Project(new Vector3D(48.362, 46.564, 5)) .EqualsTol(tolLen, new Vector3D(64.9889, 62.5728, 6.719))); // vector vers Assert.True(new Vector3D(101.546, 25.186, 1.3).Concordant(tolLen, new Vector3D(50.773, 12.593, .65))); Assert.False(new Vector3D(101.546, 25.186, 1.3).Concordant(tolLen, new Vector3D(-50.773, -12.593, .65))); // angle toward Assert.True(new Vector3D(120.317, 42.914, 0).AngleToward(tolLen, new Vector3D(28.549, 63.771, 0), Vector3D.ZAxis) .EqualsTol(MUCollection.PlaneAngle.rad.Tolerance(model), 0.80726)); Assert.False(new Vector3D(120.317, 42.914, 0).AngleToward(tolLen, new Vector3D(28.549, 63.771, 0), -Vector3D.ZAxis) .EqualsTol(MUCollection.PlaneAngle.rad.Tolerance(model), 0.80726)); Assert.True(new Vector3D(120.317, 42.914, 0).AngleToward(tolLen, new Vector3D(28.549, 63.771, 0), -Vector3D.ZAxis) .EqualsTol(MUCollection.PlaneAngle.rad.Tolerance(model), 2 * PI - 0.80726)); Assert.True(Abs( new Vector3D(-6.95, -5.1725, 0).AngleToward(1e-6, new Vector3D(6.95, 5.1725, 0), new Vector3D(0, 0, 71.89775)) - PI) < model.MUDomain.PlaneAngle.DefaultTolerance); // z-axis rotation Assert.True(new Vector3D(109.452, 38.712, 0).RotateAboutZAxis((50.0).ToRad()) .EqualsTol(tolLen, new Vector3D(40.6992, 108.7286, 0))); // arbitrary axis rotation Assert.True(new Vector3D(747.5675, 259.8335, 0).RotateAboutAxis(new Vector3D(123.151, 353.8977, 25.6), (50.0).ToRad()) .EqualsTol(tolLen, new Vector3D(524.3462, 370.9603, -462.4069))); // rotate relative Assert.True( new Vector3D(69.1831, 157.1155, 300).RotateAs(tolLen, new Vector3D(443.6913, 107.8843, 0), new Vector3D(342.7154, 239.6307, 0)) .EqualsTol(tolLen, new Vector3D(7.3989, 171.5134, 300))); // vector parallel (1-d) Assert.True(new Vector3D(1, 0, 0).IsParallelTo(tolLen, new Vector3D(-1, 0, 0))); Assert.True(new Vector3D(0, 1, 0).IsParallelTo(tolLen, new Vector3D(0, -2, 0))); Assert.True(new Vector3D(0, 0, 1).IsParallelTo(tolLen, new Vector3D(0, 0, -3))); // vector parallel (2-d) Assert.True(new Vector3D(1, 1, 0).IsParallelTo(tolLen, new Vector3D(-2, -2, 0))); Assert.False(new Vector3D(1, 1, 0).IsParallelTo(tolLen, new Vector3D(-2, 2, 0))); Assert.True(new Vector3D(1, 0, 1).IsParallelTo(tolLen, new Vector3D(-2, 0, -2))); Assert.False(new Vector3D(1, 0, 1).IsParallelTo(tolLen, new Vector3D(-2, 0, 2))); Assert.True(new Vector3D(0, 1, 1).IsParallelTo(tolLen, new Vector3D(0, -2, -2))); Assert.False(new Vector3D(0, 1, 1).IsParallelTo(tolLen, new Vector3D(0, -2, 2))); // vector parallel (3-d) Assert.True(new Vector3D(1, 1, 1).IsParallelTo(tolLen, new Vector3D(-2, -2, -2))); Assert.True(new Vector3D(253.6625, 162.6347, 150).IsParallelTo(tolLen, new Vector3D(380.4937, 243.952, 225))); // vector parallel ( tolerance checks ) { // ensure mm tolerance 1e-1 var tmpModel = new SampleModel(); var tmpTolLen = 1e-1; // Z component of first vector will be considered zero cause < 1e-1 model tolerance Assert.True(new Vector3D(10, 0, 0.05).IsParallelTo(tmpTolLen, new Vector3D(-2, 0, 0))); // Z component of first vector will be considered not-zero cause > 1e-1 model tolerance Assert.False(new Vector3D(10, 0, 0.11).IsParallelTo(tmpTolLen, new Vector3D(-2, 0, 0))); // X, Z components of first vector force internal usage of normalized tolerance 1e-4 // cause the length of the shortest vector here is < 1.5 and may represents a normalized vector // or a result of such type of operation Assert.True(new Vector3D(0.09, 0, 0.09).IsParallelTo(tmpTolLen, new Vector3D(-20, 0, -20))); } }
public void should_add_url_parameter_with_more_than_one_parameter() { var model = new SampleModel { Foo = 1, Bar = "2 with some spaces" }; var url = "~/someUrl"; var newUrl = url.AddQueryString(model, m => m.Foo).AddQueryString(model, m => m.Bar); newUrl.ShouldEqual("{0}?{1}={2}&{3}={4}".ToFormat(url, "Foo", model.Foo, "Bar", model.Bar.UrlEncoded())); }
public IActionResult SampleAction([FromBody] SampleModel data) { return(Ok("The action invoked successfully.")); }
public string Index(SampleModel data) { return("saved"); }
public void Validate_ReturnsMemberName_IfItIsDifferentFromDisplayName() { // Arrange var metadata = _metadataProvider.GetMetadataForType(typeof(SampleModel)); var model = new SampleModel(); var attribute = new Mock<ValidationAttribute> { CallBase = true }; attribute.Protected() .Setup<ValidationResult>("IsValid", ItExpr.IsAny<object>(), ItExpr.IsAny<ValidationContext>()) .Returns(new ValidationResult("Name error", new[] { "Name" })); var validator = new DataAnnotationsModelValidator(attribute.Object, stringLocalizer: null); var validationContext = new ModelValidationContext() { Metadata = metadata, Model = model, }; // Act var results = validator.Validate(validationContext); // Assert ModelValidationResult validationResult = Assert.Single(results); Assert.Equal("Name", validationResult.MemberName); }
private KeyMapping FK_SampleModel_SampleModel_FkRef(SampleModel _) { return(_.FkRef.Join(_)); }
public SampleModelParamsControl(SampleModel model) { InitializeComponent(); txtVolaShift.DataContext = model; }
public void GetMultipleDocuments() { const string model1Key = "sample::1234"; const string model2Key = "sample::5678"; const string model3Key = "sample::9876"; var repo = new SampleModelRepository(); // create the sample list document var model = new SampleModel { Key = model1Key, SampleProperty = 1 }; var model1 = new SampleModel { Key = model2Key, SampleProperty = 2 }; var model2 = new SampleModel { Key = model3Key, SampleProperty = 3 }; repo.SaveDocument(model); repo.SaveDocument(model1); repo.SaveDocument(model2); var keysToGet = new List<string> {model1Key, model2Key, model3Key}; var dictionaryOfDocs = repo.GetMultipleDocuments(keysToGet); Assert.NotNull(dictionaryOfDocs); Assert.Greater(dictionaryOfDocs.Count, 0); var dictionaryModel1 = dictionaryOfDocs[model1Key].ToString().FromJson<SampleModel>(); var dictionaryModel2 = dictionaryOfDocs[model2Key].ToString().FromJson<SampleModel>(); var dictionaryModel3 = dictionaryOfDocs[model3Key].ToString().FromJson<SampleModel>(); Assert.AreEqual(model.SampleProperty, dictionaryModel1.SampleProperty); Assert.AreEqual(model1.SampleProperty, dictionaryModel2.SampleProperty); Assert.AreEqual(model2.SampleProperty, dictionaryModel3.SampleProperty); repo.RemoveDocument(model1Key); repo.RemoveDocument(model2Key); repo.RemoveDocument(model3Key); }
public ActionResult Index(SampleModel model) => this.ModelState.IsValid ? this.RedirectToAction("Done") : (ActionResult)this.View(model);
public void CreateMap() { // Arrange var mapDefinition = new MapDefinition<SampleModel>(); mapDefinition.Map(model => model.Test1, false); var dataRecord = Substitute.For<IDataRecord>(); dataRecord.GetOrdinal("Test1").Returns(1); dataRecord.GetString(1).Returns("DB Value"); // Act var map = mapDefinition.CreateMap(); map.LoadOrdinals(dataRecord); var item = new SampleModel(); map.Load(item, dataRecord); // Assert Assert.Equal("DB Value", item.Test1); }
public ItemDetailViewModel(SampleModel item = null) { Title = item?.Text; Item = item; }
public IActionResult Create([FromForm] SampleModel sampleModel) { return(Ok(sampleModel)); }
public IHttpActionResult GetAllCustomerSearchRecords([FromBody] string name) { SampleModel obj = new SampleModel(); return(Ok(obj)); }
public void UpdateWithoutRetry() { const string sampleKey = "sample::0000000000"; var repo = new SampleModelRepository(); repo.RemoveDocument(sampleKey); var model0 = new SampleModel { Key = sampleKey, SampleProperty = 1 }; repo.CreateDocument(model0); var model1 = repo.GetDocument(sampleKey); var model2 = repo.GetDocument(sampleKey); model1.SampleProperty = model0.SampleProperty + 2; model1 = repo.SaveDocument(model1); model2.SampleProperty = model0.SampleProperty + 1; var result = repo.UpdateDocument(model2); Assert.AreEqual(3, model1.SampleProperty); Assert.AreEqual(2, result.SampleProperty); Assert.AreNotEqual(model1.CasValue, result.CasValue); repo.RemoveDocument(sampleKey); }
public void DataBind_To_Text(Placeholder control) { var model = new SampleModel { Text = "Sample Text" }; control.DataContext = model; control.SetBinding(Placeholder.TextProperty, new Binding("Text")); }
// Test method. public bool IsLovely(SampleModel other) { return(true); }
public ActionResult Api(ApiReq req) { var res = new ApiRes(); switch (req.cmd) { case "LIST": var u = new SampleModel(); res.users = u.GetUsers(); break; case "SELECT": { user users = db.users.Find(req.id); if (users == null) { res.res = "NG"; } else { res.user = users; } break; } case "UPDATE": if (!ModelState.IsValid) { res.res = "NG"; } else { db.Entry(req.user).State = EntityState.Modified; try { db.SaveChanges(); } catch (Exception e) { res.res = "NG"; res.msg = e.ToString(); } } break; case "INSERT": if (ModelState.IsValid) { db.users.Add(req.user); try { db.SaveChanges(); } catch (Exception e) { res.res = "NG"; res.msg = e.ToString(); } } break; default: res.res = "NG"; res.msg = "Bad Request"; break; } return(Json(res)); }
public void should_add_url_parameter() { var model = new SampleModel { Foo = 1, Bar = "2" }; var url = "~/someUrl"; var newUrl = url.AddQueryString(model, m => m.Foo); newUrl.ShouldEqual("{0}?{1}={2}".ToFormat(url, "Foo", model.Foo)); }