I am so impressed by CsharpRepl - Mono. It's brilliant. A command line interactive C# compiler.
See, mono is way better than visual studio 😉
Coffee | Coding | Computers | Church | What does it all mean?
Software Development
I am so impressed by CsharpRepl - Mono. It's brilliant. A command line interactive C# compiler.
See, mono is way better than visual studio 😉
There are several things you need to know to be able to do this.
There. That was only slightly unreasonably difficult. Now you can
Select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir=c:\MyDirectoryName;','select * from MyTextFile.txt')
and
Insert into OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir=c:\MyDirectoryName;','select * from MyTextFile.txt') Values ('Col1', 'Col2')
The usual examples for asp.net localisation are for the aspx markup page, not for the code behind.
In fact localisation, accessing localisation resource files programmatically, in code behind is also dead simple. You use GetLocalResourceObject() like so:
ctrl.Text = (string)GetLocalResourceObject("myCtrlKey.Text"); ctrl.AnotherAttribute = (string)GetLocalResourceObject("myCtrlKey.AnotherAttribute");
Using LocalResource means that for a page called MyPage.aspx, you have created a resource file called MyPage.aspx.resx and/or MyPage.aspx.{culturename}.resx in the special directory App_LocalResource.
If you like GlobalResources instead of local, use the special directory App_GlobalResource
to hold a resource file called MyResourceFileName.resx and call:
ctrl.Text= (string)GetGlobalResourceObject("MyResourceFileName", "myGlobalKey");
as per http://msdn.microsoft.com/en-us/library/ms227982.aspx
For a bit more of an overview of asp.net localisation, the page at http://msdn.microsoft.com/en-us/library/ms227427.aspx should only take you a few minutes to scan.
I hereby introduce a very simple no-configuration pattern for making components with dependencies unit testable. Object Quote competes with existing solutions for testability of components with dependencies and is intended to be the simplest possible solution. This will make most sense if you already understand the problem of unit testing components and classes with dependencies.
Neither of these are cost-free. Dependency Injection requires a framework and is best considered as an application-wide architectural pattern that should be used when runtime configuration is required. In that sense it is overkill for most bespoke code where you don't need to choose at runtime between multiple implementations for an interface, and all you want is test-time mockability.
The humble object is effectively a proposal to rewrite code, albeit minimally. So it has a significant cost to it; and the end result is slightly more complex than the original.
is very simple. It requires no framework, and can be applied to existing code for virtually no startup cost.
Behold. You now have decoupled, testable code. Thus:
public class MyClassThatDependsonSomething { public SomeDependency D1 { get; set; } public MyClassThatDependsonSomething() { D1 = Soq.Quote( new SomeDependency() ); } } [TestFixture] public class TestExampleCode { [Test] public void Test_something_with_dependencies() { //Arrange SomeDependency dummy = new Mock<SomeDependency>().Object; var mockSoq = new Mock<Soq>(); mockSoq.Setup(soq => soq.QuoteImplementation<SomeDependency>(It.IsAny<SomeDependency>())) .Returns(dummy); Soq.ConfigureForTest(mockSoq.Object); // Act var myClass = new MyClassThatDependsonSomething(); var result = myClass.D1; //Assert Assert.AreSame<SomeDependency>(dummy, result); } }
By default the Soq just returns the object given it.
But when configured for test, the Soq is implemented by your MoqSoq, which returns whatever you've configured it to.
Voila. Testable code with no framework needed and no extensive refactoring of existing codebase. You get started with TDD even on legacy code with minimal overhead.
Get the code and a couple of example tests from https://github.com/xcarroll/Soq. Or copy and paste the source -- just 12 lines of actual code -- from below.
On Github: https://github.com/xcarroll/Soq/blob/master/Soq.cs
using System; public class Soq { private static Soq instance = new Soq(); public static T Quote<T>(T instantiatedDependency) { return instance.QuoteImplementation<T>(instantiatedDependency); } public virtual T QuoteImplementation<T>(T dependency) { return dependency; } public static void ConfigureForTest(Soq testSoq) { if (!ConfigurationIsEnabled) { throw new InvalidOperationException( "Test configuration is not enabled."); } instance = testSoq ?? new Soq(); } public static bool ConfigurationIsEnabled { get { return true; } } }