2009年5月19日

Unit Testing ASP.NET? ASP.NET unit testing has never been this easy.

Typemock is launching a new product for ASP.NET developers – the ASP.NET Bundle - and for the launch will be giving out FREE licenses to bloggers and their readers.

The ASP.NET Bundle is the ultimate ASP.NET unit testing solution, and offers both Typemock Isolator, a unit test tool and Ivonna, the Isolator add-on for ASP.NET unit testing, for a bargain price.

Typemock Isolator is a leading .NET unit testing tool (C# and VB.NET) for many ‘hard to test’ technologies such as SharePoint, ASP.NET, MVC, WCF, WPF, Silverlight and more. Note that for unit testing Silverlight there is an open source Isolator add-on called SilverUnit.

The first 60 bloggers who will blog this text in their blog and tell us about it, will get a Free Isolator ASP.NET Bundle license (Typemock Isolator + Ivonna). If you post this in an ASP.NET dedicated blog, you'll get a license automatically (even if more than 60 submit) during the first week of this announcement.

Also 8 bloggers will get an additional 2 licenses (each) to give away to their readers / friends.

Go ahead, click the following link for more information on how to get your free license.

Typemock の ASP.NET Bundle が出たからそれについてのblogに上記メッセージをpostすればライセンスあげるよキャンペーンなのですかね?Typemockつかってみたいからとりあえずダメ元でメールしてみようかなー。

posted @ 12:18 | Feedback (0)

2009年3月4日

ASP.NET MVCのリリースまだかなとおもっていたらRC 2がでました。Changes Since RC 1の見出しを列挙すると以下のようなところが変わったみたいです。

  • Anti-Forgery Helpers Support Setting Cookie Path
  • DefaultModelBinder Validation Messages Are Now Localizable
  • New ValidationSummary Method Overload Supports Header Message
  • jQuery Updated to Version 1.3.1

ソースコードはCodePlexのプロジェクトリリースから、バイナリ形式のインストーラのダウンロードはダウンロードセンターから入手できます。

posted @ 11:47 | Feedback (1)

2008年10月30日

普通に何にも考えないでビルドされたものを実行するとx64のCLRで起動します。そして当然ですがx64のCLRで起動された場合当然x86のDLLなどをロードすることができません。

そこで自分が作っているものであればプラットフォームをx86に変更すればよいのですがそうではなく誰かが配っているものの場合は困ったりします。

で、とりあえず以下のようなプログラムをx86用アセンブリとしてコンパイルして介して起動することで動くことは動きました。

でもコマンドラインを元に戻すのがちゃんとできてないのでアレソレです。Environment.CommandLine とかEnvironement.GetCommandLineArgs() とかで取ってくるやつはどうにもなりません。きっとどうしてもどうにかしたい人がなんとかしてくれる!

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
namespace _32bitApplicationStarter
{
    static class Program
    {
        [STAThread]
        static void Main(String[] args)
        {
            if (args.Length == 0)
            {
                MessageBox.Show("起動したい実行ファイルをドロップ引数に渡してください。", "32bitApplicationStarter", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            Assembly asm = Assembly.LoadFrom(args[0]);
            try
            {
                if (asm.EntryPoint.GetParameters().Length > 0)
                {
                    List<String> argsNew = new List<String>(args);
                    argsNew.RemoveAt(0);
                    asm.EntryPoint.Invoke(null, new object[] {argsNew.ToArray()});
                }
                else
                {
                    asm.EntryPoint.Invoke(null, new object[] {});
                }
            }
            catch (TargetInvocationException e)
            {
                MessageBox.Show(e.InnerException.ToString(), "32bitApplicationStarter", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                throw e.InnerException;
            }
        }
    }
}
posted @ 19:41 | Feedback (3)

2008年8月31日

http://www.example.com/http://www2.example.com/ という値を Uri クラスのコンストラクタに渡すと http://www.example.com/http:/www2.example.com/ と二つ目以降のスラッシュの連続が一つにまとめられていたことがあって今は直っているのですが、 一体いつ起こって直ったんだろうと思ったので調べてみました。

それ困るの?と言われそうですが、例えばはてなブックマークのエントリのURLなどがそんな感じになってるので困るのです。というか困りました。困ってたのにいつの間にか直っていてアレ?っと思ったのです。

ちなみにUri class does not parse "http://.../http://..." properlyというフィードバックでなおしますよってことになっていて、報告がVisual Studio 2005なのでまあ順当に考えると2.0 SP1で直ると読めます。 一方、System.Uri constructor evaluates escaped slashes and removes double slashesではby design扱い。ひどい。先にこっち見てたから直らないものだとばかり。

ということで以下のようなコードで各バージョン試してみました。ついでに%2fを含められない話ももしかしたら途中で変わってるのかもと思って試してみました。

using System;
public class Program
{
 public static void Main(String[] args)
 {
  Console.WriteLine(Environment.Version);
  Console.WriteLine(new Uri("http://www.example.com/http://hauhau-users.jp/").AbsoluteUri);
  Console.WriteLine(new Uri("http://www.example.com/http://%2f%2fhauhau-users.jp/").AbsoluteUri);
 }
}

.NET Framework 1.0a。大丈夫っぽい。

C:\Documents and Settings\User\デスクトップ>test_v1.0.exe
1.0.3705.0
http://www.example.com/http://hauhau-users.jp/
http://www.example.com/http://%2f%2fhauhau-users.jp/

.NET Framework 1.1。コレも大丈夫っぽい。

C:\Documents and Settings\User\デスクトップ>test_v1.1.exe
1.1.4322.573
http://www.example.com/http://hauhau-users.jp/
http://www.example.com/http://%2f%2fhauhau-users.jp/

.NET Framework 2.0。やっぱりここでダメになった模様。

C:\Documents and Settings\User\デスクトップ>test_v2.0.exe
2.0.50727.42
http://www.example.com/http:/hauhau-users.jp/
http://www.example.com/http:/hauhau-users.jp/

.NET Framework 2.0 Service Pack 1。修正された。

C:\Documents and Settings\User\デスクトップ>test_v2.0.exe
2.0.50727.1433
http://www.example.com/http://hauhau-users.jp/
http://www.example.com/http:////hauhau-users.jp/

やっぱり.NET 2.0無印だけなのですね。.NET 1.xのSP適用版とかもやろうかと思ったけどめんどくさいのでパスで。

%2fが戻るやつのテストはうっかり戻ると連続になるようにしてしまったので.NET 2.0無印で消えてしまった…けど消えたと言うことは戻されてるのでやっぱり.NET 2.0から変わったっぽいですねー。dontEscape オプションをつけられなくなったのに…。

posted @ 20:10 | Feedback (0)
 

拡張子.ashxも.axdもASP.NETに割り当てられていて、IHttpHandlerを実装してhttpHandlersに登録すればどっちの拡張子でも同じように使えるのですね。

ふと、じゃあ.axd使ってもいいのかなと思ったわけです。でちょっと調べたらこんな感じのことが。

You should actually be able to use either extension -- both can be mapped to your own custom IHttpHandler.

If I had to pick one to use, I'd probably go with a .ashx extension. One reason for this is that there are no built-in .ashx end-points in ASP.NET -- whereas there are a few .axd ones (for example: the new webresources.axd). So going with a .ashx reduces the chance of a naming conflict.

.ashx files also now have intellisense support in VS 2005 -- so that makes building them easier as well.

まあどっちも使えるけど、ASP.NETに組み込まれているものに.ashxはないから(逆を言うと全部.axdだから)名前もかぶりにくくなるので.ashx使った方がいいよ、VS2005からはIntelliSense効くし。ということのよう。

posted @ 16:24 | Feedback (0)

2007年12月6日

小ネタです。PerlとかJavaScriptとか(まあJavaScriptはC#の new {...} なんだけど)みたいに以下のような感じでDictionaryを初期化できないカナーと思ったわけです。

my %hash = ( Foo => "bar", Baz => "Hoge" );

まあ普通に考えてC# 3.0では次のコードみたいにはできるようになったので結構よい感じなのです。

var hash = new Dictionary<String, String>() { {"Foo", "Bar"}, {"Baz", "Hoge"} };

で、なんかもっとそれらしくできないかなーと思っていたのですが、ふとExpressionとラムダで何とかできたりして?と思い試してみたのが以下のコードです。Dictionary メソッドに複数個のラムダ式を渡して、そのパラメータ名と戻り値を使おうという試みです。

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Diagnostics;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var dict = Dictionary(
                x      => "foo",
                y      => "bar",
                Hauhau => "gaogao"
            );
            
            var dict2 = new Dictionary<String, String>()
            {
                {"x", "foo"},
                {"y", "bar"},
                {"Hauhau", "gaogao"}
            };
            Debug.Assert(dict["x"] == dict2["x"]);
        }
        static Dictionary<String, String> Dictionary(params Expression<Func<Object, String>>[] exprs)
        {
            return CreateDictionaryFromExpression<String>(exprs);
        }
        
        static Dictionary<String, T> CreateDictionaryFromExpression<T>(params Expression<Func<Object, T>>[] exprs)
        {
            Dictionary<String, T> dict = new Dictionary<string,T>();
            foreach (Expression<Func<Object, T>> expr in exprs)
            {
                dict[expr.Parameters[0].Name] = expr.Compile().Invoke(null);
            }
            return dict;
        }
    }
}

見た目だけはそれっぽくなったというネタでした。

posted @ 0:27 | Feedback (2)

2007年12月5日

C#でCの構造体を直接はいたようなファイルを読み込もうと思って、こんな感じのをちょっと書いてみたり。

static class Extensions
{
    public static T ReadStruct<T>(this BinaryReader reader) where T : struct
    {
        Byte[] bytes = new Byte[Marshal.SizeOf(typeof(T))];
        reader.Read(bytes, 0, bytes.Length);
        
        GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
        try
        {
            return (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
        }
        finally
        {
            handle.Free();
        }
    }
}

reader.ReadStruct<FooStruct>();という感じで構造体をBinaryReaderから吸い上げます。

posted @ 23:14 | Feedback (1)

2007年10月10日

ASP.NETじゃないASPをVisual Studio 2005でデバッグするためのメモ。

greggm's WebLog : Debugging Classic ASP Code

#3. Sadly, there just isn’t any way to do remote script debugging. If you need remote script debugging, my only suggestion would be to use Remote Desktop and run Visual Studio on your server.

絶望した!スクリプトのリモートデバッグができないVisual Studio 2005に絶望した!!

posted @ 16:40 | Feedback (0)

2007年9月12日

もう一個PowerShell+iTunesネタ。アートワークがないやつを抽出してプレイリストにします。

$itunes = New-Object -com iTunes.Application
$playlist = $itunes.CreatePlaylist("アートワークがない曲")
$itunes.LibraryPlaylist.Tracks | ?{ $_.Artwork.Count -eq 0 } | %{ $playlist.AddTrack($_) } | Out-Null

例によって結構時間がかかりますが、プレイリストができたらあとはがんばってアートワークをつけてCover Flowを楽しむだけです。

posted @ 5:37 | Feedback (0)
 

PowerShellでiTunesのライブラリから特定ディレクトリ以下にファイルがあるトラックをさくっと(と言っても遅いんですが)取り除く方法です。

PS C:\> $itunes = New-Object -com iTunes.Application
PS C:\> $tracks = $itunes.LibraryPlaylist.Tracks | ?{ $_.Location -match "C:\\Users" }
PS C:\> $tracks.Length
54
PS C:\> $tracks[52,53] | %{ $_.Location }
C:\Users\UserName\Music\iTunes\iTunes Music\eufonius\メグメル ~frequency⇒e Ver.~\02 マルメロ ~fildychrom~(Short Ver.).m4a
C:\Users\UserName\Music\iTunes\iTunes Music\eufonius\メグメル ~frequency⇒e Ver.~\03 メグメル ~frequency⇒e Ver.~ (off voca.m4a
PS C:\> $tracks | %{ $_.Delete(); }

上から、

  1. iTunesオブジェクト作成
  2. 特定ディレクトリ以下(ここではC:\Users以下)のトラックを抽出
  3. 何個あったかみて
  4. 最後のあたりを軽くみてみて
  5. 大丈夫そうなので全部ライブラリから削除

という感じです。

posted @ 5:25 | Feedback (0)