所以我的代码中有一些SMTP内容,我正在尝试对该方法进行单元测试.
所以我一直在尝试使用Mockup MailMessage但它似乎永远不会起作用.我认为没有一种方法是虚拟的或抽象的,所以我不能用moq来模拟它:(.
所以我想我必须手工完成,这就是我被困住的地方.
*手动我的意思是使用界面和包装器,但让moq仍然模拟界面.
我不知道如何编写我的接口和我的Wrapper(一个将实现具有实际MailMessage代码的接口的类,因此当我的真实代码运行时它实际上完成了它需要做的事情).
所以首先我不确定如何设置我的界面.让我们来看看我必须模拟的其中一个字段.
MailMessage mail = new MailMessage();
mail.To.Add("test@hotmail.com");
Run Code Online (Sandbox Code Playgroud)
所以这是我要假装的第一件事.
所以看着它我知道"To"是一个属性,通过命中F12而不是"To"它需要我这一行:
public MailAddressCollection To { get; }
Run Code Online (Sandbox Code Playgroud)
所以它是MailAddressCollection属性.但有些我怎么被允许进一步做"添加".
所以现在我的问题是在我的界面中我做了什么?
我要做房产吗?该属性应该是MailAddressCollection吗?
或者我应该有一个像这样的方法?
void MailAddressCollection To(string email);
or
void string To.Add(string email);
Run Code Online (Sandbox Code Playgroud)
那我的包装怎么样?
所以你可以看到我很困惑.因为有这么多.我猜我只是模拟我正在使用的那些.
编辑代码
我想在真正意义上我只需要测试更多异常,但我想测试以确保一切都被发送然后它将得到响应=成功.
string response = null;
try
{
MembershipUser userName = Membership.GetUser(user);
string newPassword = userName.ResetPassword(securityAnswer);
MailMessage mail = new MailMessage();
mail.To.Add(userName.Email);
mail.From = new MailAddress(ConfigurationManager.AppSettings["FROMEMAIL"]);
mail.Subject = "Password Reset";
string body = userName + " Your Password has been reset. Your new temporary …Run Code Online (Sandbox Code Playgroud) 我正在使用C#并使用SqlBulkCopy.我有一个问题.我需要将质量插入到一个表中然后将另一个质量插入到另一个表中.
这2个具有PK/FK关系.
Table A
Field1 -PK auto incrementing (easy to do SqlBulkCopy as straight forward)
Table B
Field1 -PK/FK - This field makes the relationship and is also the PK of this table. It is not auto incrementing and needs to have the same id as to the row in Table A.
Run Code Online (Sandbox Code Playgroud)
所以这些表有一对一的关系,但我不确定如何取回质量插入所做的所有PK Id,因为我需要它们用于表B.
编辑
我可以这样做吗?
SELECT *
FROM Product
WHERE NOT EXISTS (SELECT * FROM ProductReview WHERE Product.ProductId = ProductReview.ProductId AND Product.Qty = NULL AND Product.ProductName != 'Ipad')
Run Code Online (Sandbox Code Playgroud)
这应该找到刚刚插入sql批量副本的所有行.我不确定如何从中获取结果,然后从SP进行质量插入. …
我试图用这个来弄清楚颜色是浅还是暗
现在.它需要一个int
float calcLuminance(int rgb)
{
int r = (rgb & 0xff0000) >> 16;
int g = (rgb & 0xff00) >> 8;
int b = (rgb & 0xff);
return (r*0.299f + g*0.587f + b*0.114f) / 256;
}
Run Code Online (Sandbox Code Playgroud)
我有一个十六进制颜色.
我试着这样做
var color = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");
int rgb = color.R + color.G + color.B;
var a = calcLuminance(rgb);
Run Code Online (Sandbox Code Playgroud)
我得到0.11725我认为它必须在0-256之间或类似的东西.
我究竟做错了什么?我一定要隐蔽R到int?还是我离开了?
我想知道如何在使用selenium时禁用javascript,以便我可以测试服务器端验证.
我找到了这篇文章,但我不知道该怎么做.就像我制作这个javascript文件那么?
http://thom.org.uk/2006/03/12/disabling-javascript-from-selenium/
我现在正在使用asp.net mvc并想知道使用内置的Json或Json.Net更好的选择我不确定一个人是否优于另一个.
此外,如果我选择沿着Json.Net的路线走,那么我应该选择稳定版还是beta 4?我不确定贝塔是多么不稳定.
我正在使用asp.net mvc 3并且我一直收到此错误,因为我没有使用模板,所以我不理解它.
我在局部视野中有这个
@model ViewModels.FormViewModel
<div="tabs-1">
@Html.TextBoxFor(x => x.Due.ToShortDateString())
</div>
Run Code Online (Sandbox Code Playgroud)
在我的viewmodel中
public class FormViewModel
{
public DateTime Due { get; set; }
public FormViewModel()
{
DueDate = DateTime.UtcNow;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
模板只能用于字段访问,属性访问,单维数组索引或单参数自定义索引器表达式.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.InvalidOperationException:模板只能用于字段访问,属性访问,单维数组索引或单参数自定义索引器表达式.
我有一个像这样的部分观点
<%= Html.DropDownListFor(m => m.SelectedProductName, Model.ProductList, "Select a Product") %>
Run Code Online (Sandbox Code Playgroud)
现在,您可以创建新产品并编辑现有产品.编辑和创建都使用相同的表单.加载时,创建位于主页面上.编辑在jQuery UI模型对话框中弹出,并呈现新的局部视图.
因此,就页面而言,我有2个具有相同"id"的下拉框,这是不好的,因为它们应该是唯一的.那么我该如何更改ID呢?因此,当编辑加载时,它的id可能是"editSelectedProductName"?
我试图在视图模型中执行此操作
public string SelectedProductName{ get; set; }
ViewModelConstructor()
{
SelectedProductName = "EditSelectedProductName";
}
Run Code Online (Sandbox Code Playgroud)
但它似乎并不关心并继续使用"SelectedProductName"作为产品名称
我认为jquery中有一些东西允许你通过链条向后走.
我想做这个:
var a = $(this).parent().addClass('test').goBackToParent().children('selectorHere').text()
Run Code Online (Sandbox Code Playgroud)
我想获取我拥有的对象的父级并为其添加类名.一旦我这样做,我想通过它的孩子,找到一个匹配我的选择器并获得其文本的孩子.
我可以这样做,还是我必须这样做:
$(this).parent().addClass('test');
var a = $(this).parent().children('selectorHere').text()
Run Code Online (Sandbox Code Playgroud)
编辑
我现在正在使用"结束",但它不起作用我做了一个例子,你可以在这里尝试
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<table>
<th>
<tr>one</tr>
<tr>two</tr>
</th>
<tr>
<td id="test"><a href="#"><img src="http://ais.web.cern.ch/ais/apps/hrt/SMT%20v2/Images/btnbar_edit.png" /></a></td>
<td class="selectMe">1</td>
</tr>
</table>
</body>
</html>
$(function()
{
$('#test').click(function()
{
// does not work
var a = $(this).parent().addClass('afb').end().children('.selectMe').text(); …Run Code Online (Sandbox Code Playgroud) 我有一个对象列表,其中包含另一个对象.
List<MyClass> myClass = new List<MyClass>();
Run Code Online (Sandbox Code Playgroud)
我想这样做一些linq
myClass.Where(x => x.MyOtherObject.Name = "Name").ToList();
Run Code Online (Sandbox Code Playgroud)
事情有时候"MyOtherObject"为空.我该如何检查?
我在用
目前我正在使用nhibernate,ninject与存储库模式和服务层.
所以我有这个
public class NhibernateSessionFactory
{
public ISessionFactory GetSessionFactory()
{
ISessionFactory fluentConfiguration = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("ConnectionString")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Framework.Data.Mapping.TableAMap>().Conventions.Add(ForeignKey.EndsWith("Id")))
.ExposeConfiguration(cfg => cfg.SetProperty("adonet.batch_size", "20"))
.ExposeConfiguration(c => c.SetProperty("generate_statistics", "true"))
//.ExposeConfiguration(BuidSchema)
.BuildSessionFactory();
return fluentConfiguration;
}
private static void BuidSchema(NHibernate.Cfg.Configuration config)
{
new NHibernate.Tool.hbm2ddl.SchemaExport(config).Create(false, true);
}
public class NhibernateSessionFactoryProvider : Provider<ISessionFactory>
{
protected override ISessionFactory CreateInstance(IContext context)
{
var sessionFactory = new NhibernateSessionFactory();
return sessionFactory.GetSessionFactory();
}
}
public class NhibernateModule : NinjectModule
{
public override …Run Code Online (Sandbox Code Playgroud) c# ×5
.net ×4
asp.net-mvc ×4
colors ×1
hex ×1
javascript ×1
jquery ×1
jquery-ui ×1
json ×1
json.net ×1
linq ×1
mocking ×1
nhibernate ×1
ninject-2 ×1
rgb ×1
selenium ×1
sql ×1
sqlbulkcopy ×1
unit-of-work ×1
unit-testing ×1