- Presentation Zen and the book's web site (www.presentationzen.com)
- "The Inmates Are Running the Asylum" by Alice Cooper
Update: 04/10 - Added "color" articles' links
commercial product has support so I know whom to contact when I will be trouble (be sure you will %99), while open source has no support
commercial product has support that can promise me a deadline...
The other day I was thinking about Double Dispatch Principle and it's benefits and came up with the following code sample:
public class Air
{
}
public class Fun
{
public void Run(Air air)
{ }
}
public class Sheet : Air
{
public void Hit(Fun theFun)
{
theFun.Run(this);
}
}
public class Program
{
public void Process()
{
var theFun = new Fun();
new Sheet().Hit(theFun);
}
}
About 10 minutes I needed to understand the problem. Luckily I had tests. It appears, that Path.Combine works funny. Here are a comple of examples:
Oh, frankly speaking, I would really like to have Path.Combine("../Tests/", "/123.xml") give me "../Tests/123.xml" or, at least, "../Tests//123.xml" and even "../Tests\123.xml" would be fine.
For now, I have to remember funny point #1 and will try to do #2 and #3 all along.
XML Team started to blog about most difficult things in System.XML. The list of posts below:
Hope this helps!
Today I found a post about The Compare Contract by BCL Team. In brief, one of the customers complained about the breaking changes made in SP1 compared to RTM version. Actually, the ComparedTo method of the StringWrapper class was changed which affected sorting behavior.
It appeared that ComparedTo method was implemented incorrectly. Therefore, it was decided to change it. MSDN describes several requirements that must be met by a particular implementation of IComparable<T> interface.
I see this as a big bonus for any developer implementing IComparable<T> interface. Even before starting to implement the method you can write very strict Unit Tests that will help you to implement a method that will satisfy common requirements for any sorting algorithm.
As you see, you can end up with 5 unit test. If you will use MbUnit, for example, you can employ Row Tests to specify more precise requirements for your interface implementation very easy.
For example I ended up with 15 tests. It took me about 15 minutes. Here they are:
namespace CompareToContract.UnitTests
{
using MbUnit.Framework;
[TestFixture]
public class StringWrapperTests
{
[RowTest]
[Row("")]
[Row("value")]
[Row(null)]
public void CompareTo_SameValue_ShouldReturnZero(string value)
{
StringWrapper wrapper = new StringWrapper() { Value = value };
Assert.AreEqual(wrapper.CompareTo(wrapper), 0, "A.CompareTo(A) should return 0.");
}
[RowTest]
[Row("", "")]
[Row("value", "value")]
[Row(null, null)]
public void CompareTo_AnotherEqualValue_ShouldReturnZero(string value1, string value2)
{
StringWrapper a = new StringWrapper() { Value = value1 };
StringWrapper b = new StringWrapper() { Value = value2 };
Assert.AreEqual(a.CompareTo(b), 0, "A'value'.ComparedTo(b'value') should return 0.");
}
[RowTest]
[Row("", "", "")]
[Row("value", "value", "value")]
[Row(null, null, null)]
public void CompareTo_AandBandCequal_ShouldReturnZero(string value1, string value2, string value3)
{
StringWrapper a = new StringWrapper() { Value = value1 };
StringWrapper b = new StringWrapper() { Value = value2 };
StringWrapper c = new StringWrapper() { Value = value3 };
Assert.AreEqual(a.CompareTo(b), 0, "A'value'.ComparedTo(B'value') should return 0.");
Assert.AreEqual(b.CompareTo(c), 0, "B'value'.ComparedTo(C'value') should return 0.");
Assert.AreEqual(a.CompareTo(c), 0, "A'value'.ComparedTo(C'value') should return 0.");
}
[RowTest]
[Row("1", "2")]
[Row("value1", "value2")]
[Row(null, "1")]
public void CompareTo_IfAComparedToBReturnValueThenBComparedToA_ShouldReturnSameValueButDifferentInSign(string value1, string value2)
{
StringWrapper a = new StringWrapper() { Value = value1 };
StringWrapper b = new StringWrapper() { Value = value2 };
Assert.AreEqual(a.CompareTo(b), -1 * b.CompareTo(a), "a.ComparedTo(b) should equal to -1 * b.ComparedTo(a).");
}
[RowTest]
[Row("1", "2", "3")]
[Row("value3", "value2", "value1")]
[Row("value1", "value2", "value3")]
public void CompareTo_IfAComparedToBReturnsValueWithTheSameSignAsBComparedToCThenACompareToC_ShouldReturnValueWithTheSameSign(string value1, string value2, string value3)
{
StringWrapper a = new StringWrapper() { Value = value1 };
StringWrapper b = new StringWrapper() { Value = value2 };
StringWrapper c = new StringWrapper() { Value = value3 };
int abResult = a.CompareTo(b);
int bcResult = b.CompareTo(c);
int acResult = a.CompareTo(c);
Assert.IsTrue(Math.Sign(abResult) == Math.Sign(bcResult), "A.ComparedTo(B) should have the same sign as B.ComparedTo(C).");
Assert.IsTrue(Math.Sign(abResult) == Math.Sign(acResult), "A.ComparedTo(C) should have the same sign as A.ComparedTo(B).");
}
}
}
The old implementation of CompareTo completed with 10 succeeded and 5 failed tests. While implementation provided by BCL Team completed with all 15 succeeded. This way I can trust this implementation of CompareTo method.
Conclusion
Test your requirements before you right the code. This will minimize your time and efforts to understand (remember all the time) requirements of implementation and will help you to write the code you need, not the code you can write.
Hope this helps!
I am not an expert in neither WCF nor WSE, however, recently I have been busy implementing WCF service that could be consumed by WSE client. And the requirement for this was to use Anonymous For Certificate Security protection of messages.
As always I started from Google... However, after spending about 4 to 6 hour I get nothing except examples that was not working.
Therefore, here, I decided to describe the implementation of, both, service and client.
Anonymous for Certificate Security In a Nutshell.
Basically, to protect your messages with certificates you need to do a number of things:
The way Anonymous for Certificate Security mechanisms work is very simple - the same way as Encryption Algorithms with Open Key works. The certificate (*.cer file) will be used by client as public key to sign and encode his requests to the service and decode response from the service. The service, in it's turn, will be using private key (*.pfx file) to encode / decode messages.
In this way, it will be impossible to give client a fake service, because only service has private key. However, anything can be a client of a service as soon as it encodes and decodes messages using public key (*.cer file).
WCF Service Implementation.
In order to connect WSE and WCF could understand each other they need to talk the same security protocol. Therefore, I set message security version of service binding to "WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10".
Also, made service and client both you MTOM messaging. Message version should be set to "Soap11WSAddressingAugust2004" by the reason explained earlier.
Next things you need to do is to configure your service behaviour, of course. This is very simple to do as well. You need to add
After this is done, you need to configure your service interface to use message contract and create request and response messages for every method on your service interface. Then implement your service. If something was not configured properly your service will not run.
WSE Client Implementation.
First of all, you need to create a proxy for you WCF service. This is very simple to accomplish using wseWsdl3.exe utility that will be installed along with WSE3.0 installation package.
After you did that, you need to create a WSE policy to access WCF service. You can do in configuration file or in code. It does not matter. What you need to do is to configure AnonymousForSecurity assertion and configure your proxy to use certificate you installed as credentials to access WCF service.
Do not forget to configure WSE to use MTOM messaging as well.
Links
There are lots of resources on the web that can give you some food for thought when dealing with peculiarities of this integration including Microsoft Forums and personal blogs. However, I would recommend to check WCF Security Guidance on CodePlex. This is the place where you will find a lot of information about WCF security and How-Tos.
Hope this helps!