我有一个表DEAL和一个表DEAL_TYPE.我想映射这段代码:
public class Deal {
DealType type;
}
public enum DealType {
BASE("Base"), EXTRA("Extra");
}
Run Code Online (Sandbox Code Playgroud)
问题是数据已存在于数据库中.而且我很难将类映射到数据库.
数据库看起来像这样:
TABLE DEAL {
Long id;
Long typeId;
}
TABLE DEAL_TYPE {
Long id;
String text;
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用简单的@OneToMany关系从交易到交易类型,但我更喜欢使用枚举.这可能吗?
我几乎使用EnumType.ORDINAL类型工作.但不幸的是,我的交易类型表中的ID不是顺序的,并且不是从1开始.
有什么建议?
我正在尝试用2个构造函数对一个类进行单元测试.每个构造函数都有多个参数来设置公共属性.我的问题是,我应该只有2个单元测试和多个断言来检查每个属性是否已设置或每个构造函数的每个参数的测试?
Public Person(string name, string phone, string birthday)
{
name = name;
phone = phone;
birthday = birthday;
}
Public Person(string name) : this(name, null, null)
{}
Run Code Online (Sandbox Code Playgroud) 有没有办法根据字符生成单词并检查域是否存在此单词(ping)?
我想要做的是根据一些字符生成单词,例如"abcdefgh",然后ping generateword.com以检查它是否存在.
我有两个单选按钮
<input type="radio" name="rush" value="yes" />
<input type="radio" name="rush" value="no" checked="checked" />
Run Code Online (Sandbox Code Playgroud)
我想要做的是当单击表单提交按钮时,检查是否选择了"是".
如果是,则显示一个javascript确认对话框
我已经走到了这一步,但我被卡住了,任何帮助都会受到赞赏.
$("form.shipping").submit(function() {
if($("input[name='rush']".attr("value") === "yes")
{
if (confirm("Rush orders are subject to an upcharge. (Just wanted to make sure you read the note). Is this ok?"))
{
return true;
}
else
{
return false;
}
}
});
Run Code Online (Sandbox Code Playgroud) 我在用:
if (RadioButtonList_VolunteerType.SelectedItem != null)
Run Code Online (Sandbox Code Playgroud)
或怎么样:
if (RadioButtonList_VolunteerType.Index >= 0)
Run Code Online (Sandbox Code Playgroud)
或者怎么样(根据Andrew Hare的回答):
if (RadioButtonList_VolunteerType.Index > -1)
Run Code Online (Sandbox Code Playgroud)
对于那些可能阅读此问题的人,以下不是有效的方法.正如Keltex指出的那样,所选值可能是一个空字符串.
if (string.IsNullOrEmpty(RadioButtonList_VolunteerType.SelectedValue))
Run Code Online (Sandbox Code Playgroud) 我使用AJAX Control Toolkit Accordion,LinkButton和TextBox创建了一个简单的用户控件,如下所示:
TestControl.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestControl.ascx.cs" Inherits="TestControl" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<cc1:Accordion ID="Accordion1" runat="server">
<Panes></Panes>
<HeaderTemplate>
<div><%# Container.DataItem %></div>
</HeaderTemplate>
<ContentTemplate>
<div>
<asp:TextBox ID="textBox" Text='<%# Container.DataItem %>' runat="server"></asp:TextBox>
<asp:LinkButton Text="Update" CommandName="Update" CommandArgument='<%# Container.DataItem %>' OnCommand="LinkButton_Command" runat="server"></asp:LinkButton>
</div>
</ContentTemplate>
</cc1:Accordion>
Run Code Online (Sandbox Code Playgroud)
和TestControl.ascx.cx:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class TestControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Accordion1.DataSource = new string[] { "one", "two", …Run Code Online (Sandbox Code Playgroud) 首先,我希望基于上下文的存储在整个框架中保持一致!
话虽如此,我正在寻找一种优雅的解决方案,使这些属性在ASP.NET,WCF和任何其他多线程.NET代码中都是安全的.这些属性位于一些低级跟踪帮助程序中(如果您想知道它们为什么是内部的,则通过方法公开).
我宁愿不依赖于不需要的程序集(如System.Web等).我不想要求使用此代码的任何人配置任何东西.我只是想让它起作用;)虽然这可能太高了一个订单......
任何人都有任何诡计?(我看过Spring的实现)
internal static string CurrentInstance
{
get
{
return CallContext.LogicalGetData(currentInstanceSlotName) as string;
}
set
{
CallContext.LogicalSetData(currentInstanceSlotName, value);
}
}
internal static Stack<ActivityState> AmbientActivityId
{
get
{
Stack<ActivityState> stack = CallContext.LogicalGetData(ambientActivityStateSlotName) as Stack<ActivityState>;
if (stack == null)
{
stack = new Stack<ActivityState>();
CallContext.LogicalSetData(ambientActivityStateSlotName, stack);
}
return stack;
}
}
Run Code Online (Sandbox Code Playgroud)
更新
安全我不是说同步.背景在这个问题上这里
我注意到某些命令导致LINQtoSQL连接到数据库并下载作为查询一部分的记录,例如.ToArray().
命令.Cast()是否会导致查询执行(以后如何判断这些事情?).例如...
IRevision<T> current = context.GetTable(typeof(T))
.Cast<IRevision<T>>()
.SingleOrDefault(o => o.ID == recordId);
Run Code Online (Sandbox Code Playgroud)
我知道.GetTable有一个命令允许你指定泛型类型,但由于奇怪和无法解释的原因,它不能在这种情况下使用.
我正在PropertyGrid通过实现自定义对象类型的显示方式ICustomTypeDescriptor.我允许用户创建自己的自定义属性,这些属性存储在单个键和值字典中.我能够PropertyDescriptors为这些值创建所有值并在属性网格中查看它们.但是,我还想显示所有默认属性,如果PropertyGrid通过反射填充而不是覆盖ICustomTypeDescriptor.GetProperties方法,则会显示这些属性.
现在我知道如何获取对象的类型,然后GetProperties(),但这会返回一个PropertyInfonot 数组ProperyDescriptor.那么如何PropertyInfo将该类型的对象转换为PropertyDescriptor对象以包含到我的集合中PropertyDescriptors?
//gets the local intrinsic properties of the object
Type thisType = this.GetType();
PropertyInfo[] thisProps = thisType.GetProperties();
//this line obviously doesn't work because the propertydescriptor
//collection needs an array of PropertyDescriptors not PropertyInfo
PropertyDescriptorCollection propCOl =
new PropertyDescriptorCollection(thisProps);
Run Code Online (Sandbox Code Playgroud) 我想问一下你对大型数据库进行单元测试的建议.
我想为一个主要在T-SQL中实现的应用程序编写单元测试,因此不能选择模拟数据库.数据库非常大(大约10GB),因此在测试运行后恢复数据库实际上也是不可能的.
该应用程序的目的是管理信用协议申请的处理.有特定角色的用户可以更改agreement对象的状态,我的工作是测试此过程的一部分.
我正在考虑两种方法:
创建符合特定条件的协议,然后测试协议状态的更改(例如,从在某个办公室等待到在此特定办公室处理的过渡).协议将在应用程序本身中创建,它们将成为我的测试用例.所有测试都将在执行这些测试后回滚的事务中.
好处这种方法的优点是非常简单的测试.可以很容易地描述预期的数据,因为我确切地知道在转换之后对象应该是什么样子.
缺点缺点是数据库不能以破坏测试的方式改变.测试用例中使用的用户和协议必须始终相同,如果需要更改数据库,则必须重复准备过程.
在单元测试中创建协议.以编程方式创建符合特定条件的协议.用于创建协议的数据将随机选择.此外,将随机创建将更改协议状态的用户.
好处这种方法的优点是易于对对象进行更改,并且能够在具有不同数据的数据库上运行测试.
缺点两个对象(协议和用户)都有很多字段和相关数据,我担心实现这些对象的创建需要一些时间(我也害怕这些对象可能包含一些错误,因为创建方法会相当很难实现没有错误).
您如何看待这两种方法?
任何Stack Overflow读者都认为按照第二种方法描述创建对象是否值得?
这里有没有人有创建此类测试的经验?
c# ×4
.net ×2
asp.net ×2
unit-testing ×2
validation ×2
constructor ×1
database ×1
enums ×1
hibernate ×1
httpcontext ×1
java ×1
jquery ×1
linq ×1
linq-to-sql ×1
nunit ×1
orm ×1
ping ×1
propertygrid ×1
propertyinfo ×1
python ×1
radio-button ×1
records ×1
tdd ×1
webforms ×1