我刚刚开始使用单元测试和TDD.我之前已经涉足过,但现在我决心将它添加到我的工作流程并编写更好的软件.
我昨天问了一个问题,包括这个问题,但这似乎是一个问题.我坐下来开始实现一个服务类,我将用它来从控制器中抽象出业务逻辑,并使用EF6映射到特定的模型和数据交互.
问题是我已经阻止了自己,因为我不想在存储库中抽象EF(它仍然可以在服务之外用于特定查询等)并且想测试我的服务(将使用EF Context) .
在这里我想是问题,有没有意义这样做?如果是这样的话,人们如何在野外做到这一点,因为IQueryable引起的漏洞抽象以及Ladislav Mrnka关于单元测试主题的许多重要帖子都不是直截了当的,因为Linq提供商在处理内存时存在差异与特定数据库相关的实现.
我想测试的代码看起来很简单.(这只是虚拟代码,试图理解我在做什么,我想用TDD驱动创建)
上下文
public interface IContext
{
IDbSet<Product> Products { get; set; }
IDbSet<Category> Categories { get; set; }
int SaveChanges();
}
public class DataContext : DbContext, IContext
{
public IDbSet<Product> Products { get; set; }
public IDbSet<Category> Categories { get; set; }
public DataContext(string connectionString)
: base(connectionString)
{
}
}
Run Code Online (Sandbox Code Playgroud)
服务
public class ProductService : IProductService
{
private IContext _context;
public ProductService(IContext dbContext)
{
_context = dbContext;
}
public IEnumerable<Product> GetAll() …Run Code Online (Sandbox Code Playgroud) 好吧,我已经设置VS2010起始页面以显示最近项目部分中的20多个项目,但是当我搞乱主题和导入/导出设置时,我似乎已将其重置为默认值10,我可以'找到该设置的位置.有谁知道起始页面上的最近项目数量设置在哪里,而不是文件菜单?我已将tools\options,environment中的值更改为该设置页面的最近文件部分中两个项目的24(最大值),但这不会影响起始页面.
TIA
我正在编写一些扩展来模仿地图并减少Lisp中的函数.
public delegate R ReduceFunction<T,R>(T t, R previous);
public delegate void TransformFunction<T>(T t, params object[] args);
public static R Reduce<T,R>(this List<T> list, ReduceFunction<T,R> r, R initial)
{
var aggregate = initial;
foreach(var t in list)
aggregate = r(t,aggregate);
return aggregate;
}
public static void Transform<T>(this List<T> list, TransformFunction<T> f, params object [] args)
{
foreach(var t in list)
f(t,args);
}
Run Code Online (Sandbox Code Playgroud)
转换功能将减少如下:
foreach(var t in list)
if(conditions && moreconditions)
//do work etc
Run Code Online (Sandbox Code Playgroud)
这有意义吗?会更好吗?
我试图首先在EF代码中建立多对多关系,但默认约定是错误的.以下类描述了这种关系:
class Product
{
public int Id { get; set; }
public string Name { get; set; }
}
class Account
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
一个帐户可以有许多产品.
但是,EF约定将创建DB表,如下所示:
Products Table
--------------
Id
Name
Account_Id <- What is this?
Accounts Table
--------------
Id
Name
Run Code Online (Sandbox Code Playgroud)
这看起来不像是一个多对多的表结构?如何配置流畅的API以反映关系并创建中间表:
AccountProducts Table
---------------------
Account_Id
Product_Id
Run Code Online (Sandbox Code Playgroud) 我尝试使用MVC5和OWIN身份验证为Web站点的ApplicationUser添加自定义属性.我已经阅读了/sf/answers/736701381/,我喜欢它如何与基本控制器集成,以便轻松访问新属性.我的问题是,当我将HTTPContext.Current.User属性设置为我的新IPrincipal时,我得到一个空引用错误:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.Security.UrlAuthorizationModule.OnEnter(Object source, EventArgs eventArgs) +127
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
ApplicationUser user = userManager.FindByName(HttpContext.Current.User.Identity.Name);
PatientPortalPrincipal newUser = new PatientPortalPrincipal();
newUser.BirthDate = user.BirthDate;
newUser.InvitationCode = user.InvitationCode;
newUser.PatientNumber = user.PatientNumber;
//Claim cPatient = new Claim(typeof(PatientPortalPrincipal).ToString(), );
HttpContext.Current.User = newUser;
}
}
public class PatientPortalPrincipal : ClaimsPrincipal, IPatientPortalPrincipal
{
public …Run Code Online (Sandbox Code Playgroud) VS2012菜单中的全部大写是非常烦人的,在IDE或其他地方的某个地方是否有设置将其关闭?
我一直在考虑回到.net DI的springframework,但我刚注意到他们的网站上没有任何最近的开发或公告.任何人都可以确认他们仍然在积极开发弹簧框架的.net版本,或者项目已经死了?
我知道之前已经问过这个问题(spring.net是否被积极维护/开发/记录?),但这已经超过2年了.该网站主页上的最新公告是2012年12月.
更多证据表明它已经死亡:
我的任务是将图像采集集成到.NET应用程序中,我一直在寻找用于执行此功能的API.我遇到过几个"标准"API,有些已经存在了很长时间,有些时间不长.我查看了对ISIS,TWAIN,WIA和SANE的引用(据说主要是*nix).它们似乎都是除了SANE之外的Win32库,我想知道目前推荐用于与图像采集设备(扫描仪)交谈的建议是什么?
如果你觉得它更好,请随意推荐别的东西. 我正在寻找开源选项.
编辑:我把开源,当我实际意味着是免费的.使用WIA或TWAIN是好的,因为它们是免费的,即使它们是专有接口.
我必须在c#中开发一个应用程序,以获取基于我提供的DNS(例如*.google.com)发布的SSL证书信息,如有效期,以便如果到期日期临近,我可以主动处理它.如果我将DNS提供为*.google.com,那么我需要获取该域的SSL证书信息的详细信息.
我尝试了http://awesomeideas.net/page/Cert-Expiry-Check.aspx,但我觉得它是存储在本地系统中的证书.我也尝试使用HttpWebRequest获取SSL证书的详细信息,但它要求我输入一个有效的URI,在我的情况下是不可用的.我只有DNS名称
下面是我用HttpWebRequest获取信息的代码.但它要求我输入https://*.domain.com类型的有效URI
Uri uri = new Uri(DNSEntry);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
X509Certificate cert1 = request.ServicePoint.Certificate;
X509Certificate2 cert = new X509Certificate2(cert1);
DateTime dtCertExpiry = Convert.ToDateTime(cert.NotAfter.ToString());
Run Code Online (Sandbox Code Playgroud) 我需要保持HeaderTemplate一个的ListView可见在任何时候,但我不知道该怎么设置,还是什么的一部分ListView的模板更改为做到这一点.
我目前所拥有的是ListView当向下滚动项目时导致标题滚动到顶部.
ListView即使滚动浏览ListView项目,如何保持可见的标题"行" ?
这是我的XAML:
<ListView x:Name="permitResults"
Grid.Row="1"
AutomationProperties.AutomationId="PermitResults"
AutomationProperties.Name="Permit Search Results"
ItemsSource="{Binding Source={StaticResource ResultsSource}}"
ItemClick="permitResults_ItemClick"
SelectionMode="None"
TabIndex="1"
Padding="0"
Margin="0"
BorderThickness="0"
IsSwipeEnabled="True"
IsItemClickEnabled="True"
ScrollViewer.VerticalScrollBarVisibility="Auto" >
<ListView.HeaderTemplate>
<DataTemplate>
<Grid Margin="0,0,0,0" Width="1366" Height="Auto" HorizontalAlignment="Left">
<Grid.Resources>
<Style TargetType="TextBlock" BasedOn="{StaticResource SearchGridResultsHeaderTextBlock}">
<Setter Property="HorizontalAlignment" Value="Left"></Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Permit #" MaxLines="2" TextWrapping="WrapWholeWords"/>
<TextBlock Grid.Column="1" Text="County" …Run Code Online (Sandbox Code Playgroud) 我想做这个:
public static void SetStringsToBeNonUnicode(this EntityTypeConfiguration<T> config)
{
}
Run Code Online (Sandbox Code Playgroud)
编译器不喜欢那里的<T>,这个的正确语法是什么?
更多上下文,EntityTypeConfiguration是一个EntityFramework类,定义为
public class EntityTypeConfiguration<TEntityType> : StructuralTypeConfiguration<TEntityType> where TEntityType : class
Run Code Online (Sandbox Code Playgroud)
这是导致我头痛的原因.
我真正想要的是在配置dbcontext类时能够做这样的事情:
public class ReceiptEntityConfiguration: EntityTypeConfiguration<ReceiptEntity>
{
public ReceiptEntityConfiguration()
{
ToTable("vReceipt");
HasKey(r => r.ReceiptId);
this.SetStringsToBeNonUnicode(); //I want to make all string fields for this entity type (ReceiptEntity in this case) to be treated as not unicode.
...etc etc
}
}
Run Code Online (Sandbox Code Playgroud)
EF6.0使用轻量级约定来处理这个问题,但我不能将beta位用于prod.
嗨,我正在使用angularjs2的新alpha组件路由器https://angular.io/docs/ts/latest/guide/router.html
我有一个模式用于验证用户然后在localstorage中创建一个JWT,它保存用户所需的信息.
我的问题是,如果用户正在查看/home路径,那里只有登录用户可见的东西,但在他通过模态登录后,他必须刷新页面,以便组件刷新并显示正确的记录 -在信息中
有没有办法告诉angular2刷新当前路径上的所有组件?像一个页面重新加载,但没有真正重新加载整个页面(我不想只是为用户点击刷新按钮)
提前致谢
编辑:当我尝试重定向到我已经在的路线时,可能还有一个强制重定向功能?
EDIT2:尝试使用observables
@Injectable()
export class UserService {
private loggedInObservable;
constructor(private http: Http) {
this.loggedInObservable = Observable.of(this.checkIsLoggedIn());
}
checkIsLoggedIn() {
let isLoggedIn = false;
try {
isLoggedIn = tokenNotExpired();
} catch(e) {
}
console.log('returning:', isLoggedIn);
return isLoggedIn;
}
login(model, cbSuccess=null, cbError=null, cbAlways=null) {
serverPost(this, '/api/users/login', model, cbSuccess, cbError, cbAlways, (data)=> {
localStorage.setItem("id_token", data.id_token);
this.loggedInObservable.map((val) => console.log('HELLO?'));
});
}
isLoggedInObservable() {
return this.loggedInObservable;
}
}
Run Code Online (Sandbox Code Playgroud)
地图完全没有('HELLO?'没有显示),虽然观察者有一个值,地图功能不会调用任何东西.
使用观察者:
import {Component, OnInit, OnDestroy} from '@angular/core'; …Run Code Online (Sandbox Code Playgroud) c# ×7
.net ×3
ide ×2
angular ×1
associations ×1
c++ ×1
generics ×1
iprincipal ×1
listview ×1
menubar ×1
owin ×1
raii ×1
scanning ×1
spring ×1
spring.net ×1
ssl ×1
start-page ×1
twain ×1
unit-testing ×1
uwp-xaml ×1
wia ×1
xaml ×1